diff options
-rw-r--r-- | SConscript.smoke | 4 | ||||
-rw-r--r-- | buildscripts/utils.py | 48 | ||||
-rw-r--r-- | src/mongo/SConscript | 6 |
3 files changed, 54 insertions, 4 deletions
diff --git a/SConscript.smoke b/SConscript.smoke index d05d3992da4..10e2462fa68 100644 --- a/SConscript.smoke +++ b/SConscript.smoke @@ -4,6 +4,7 @@ # e.g.) import os +from buildscripts import utils Import( "has_option env shellEnv testEnv" ) @@ -42,7 +43,8 @@ def addSmoketest( name, deps ): else: target = name[5].lower() + name[6:] - addTest(name, deps, [ "python buildscripts/smoke.py " + " ".join(smokeFlags) + ' ' + target ]) + smokeArgs = smokeFlags + [target] + addTest(name, deps, utils.smoke_command(*smokeArgs)) addSmoketest( "smoke", [ add_exe( "test" ), add_exe( "mongod" ), add_exe( "mongo" ) ] ) addSmoketest( "smokePerf", [ add_exe("perftest") ] ) diff --git a/buildscripts/utils.py b/buildscripts/utils.py index 8021d8779da..d293d89c4e3 100644 --- a/buildscripts/utils.py +++ b/buildscripts/utils.py @@ -3,6 +3,10 @@ import re import socket import time import os +import os.path +import itertools +import subprocess +import sys # various utilities that are handy def getAllSourceFiles( arr=None , prefix="." ): @@ -134,3 +138,47 @@ def didMongodStart( port=27017 , timeout=20 ): timeout = timeout - 1 return False +def which(executable): + if sys.platform == 'win32': + paths = os.environ.get('Path', '').split(';') + else: + paths = os.environ.get('PATH', '').split(':') + + for path in paths: + path = os.path.expandvars(path) + path = os.path.expanduser(path) + path = os.path.abspath(path) + executable_path = os.path.join(path, executable) + if os.path.exists(executable_path): + return executable_path + + return executable + +def find_python(min_version=(2, 5)): + # if this script is being run by py2.5 or greater, + # then we assume that "python" points to a 2.5 or + # greater python VM. otherwise, explicitly use 2.5 + # which we assume to be installed. + version = re.compile(r'[Pp]ython ([\d\.]+)', re.MULTILINE) + binaries = ('python27', 'python2.7', 'python26', 'python2.6', 'python25', 'python2.5', 'python') + for binary in binaries: + try: + out, err = subprocess.Popen([binary, '-V'], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() + for stream in (out, err): + match = version.search(stream) + if match: + versiontuple = tuple(map(int, match.group(1).split('.'))) + if versiontuple >= (2, 5): + return which(binary) + except: + pass + + raise Exception('could not find suitable Python (version >= %s)' % '.'.join(min_version)) + +def smoke_command(*args): + here = os.path.dirname(__file__) + smoke_py = os.path.join(here, 'smoke.py') + return ' '.join(itertools.chain( + (find_python(), smoke_py), + args)) + diff --git a/src/mongo/SConscript b/src/mongo/SConscript index 84ad73e6834..06a2546f8f7 100644 --- a/src/mongo/SConscript +++ b/src/mongo/SConscript @@ -3,7 +3,7 @@ # This SConscript describes build rules for the "mongo" project. import os -import buildscripts.utils as utils +from buildscripts import utils Import("env") Import("shellEnv") @@ -551,7 +551,7 @@ def build_and_test_client(env, target, source): call(scons_command + ["libmongoclient.a", "clientTests"], cwd=installDir) - return bool(call(["python", "buildscripts/smoke.py", - "--test-path", installDir, "client"])) + return bool(call(utils.smoke_command([ + "--test-path", installDir, "client"]))) env.Alias("clientBuild", [mongod, '$INSTALL_DIR'], [build_and_test_client]) env.AlwaysBuild("clientBuild") |