Skip to content

Commit

Permalink
ALL smoke.py invocations are done through smoke_command()
Browse files Browse the repository at this point in the history
This function returns a string command with fully qualified paths to a
valid (>= 2.5) Python interpreter and to the smoke.py file.
  • Loading branch information
Dan Crosta committed Feb 17, 2012
1 parent 7cf238c commit 31991af
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
4 changes: 3 additions & 1 deletion SConscript.smoke
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# e.g.)

import os
from buildscripts import utils

Import( "has_option env shellEnv testEnv" )

Expand Down Expand Up @@ -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") ] )
Expand Down
48 changes: 48 additions & 0 deletions buildscripts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
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="." ):
Expand Down Expand Up @@ -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))

6 changes: 3 additions & 3 deletions src/mongo/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")

0 comments on commit 31991af

Please sign in to comment.