Allow Python interpreter to be specified during build

This allows the library to be built and tested with a non-default
version of CPython, e.g.

scons bindings=python python=python3.6
scons bindings=python python=python3.6 testpython
This commit is contained in:
Alex Willmer 2019-05-10 21:38:49 +01:00
parent 287f71d561
commit c82390941d
2 changed files with 5 additions and 3 deletions

View file

@ -15,6 +15,7 @@ vars = Variables(None, ARGUMENTS)
vars.Add(PathVariable('DESTDIR', 'Root directory to install in (useful for packaging scripts)', None, PathVariable.PathIsDirCreate)) vars.Add(PathVariable('DESTDIR', 'Root directory to install in (useful for packaging scripts)', None, PathVariable.PathIsDirCreate))
vars.Add(PathVariable('prefix', 'Where to install in the FHS', default_install_dir, PathVariable.PathAccept)) vars.Add(PathVariable('prefix', 'Where to install in the FHS', default_install_dir, PathVariable.PathAccept))
vars.Add(ListVariable('bindings', 'Language bindings to build', 'none', ['cpp', 'dotnet', 'perl', 'php', 'python', 'ruby'])) vars.Add(ListVariable('bindings', 'Language bindings to build', 'none', ['cpp', 'dotnet', 'perl', 'php', 'python', 'ruby']))
vars.Add('python', 'Python interpreter', 'python')
tools = ['default', 'scanreplace'] tools = ['default', 'scanreplace']
if 'dotnet' in ARGUMENTS.get('bindings', []): if 'dotnet' in ARGUMENTS.get('bindings', []):

View file

@ -10,17 +10,18 @@ pythonenv = env.Clone(IMPLICIT_COMMAND_DEPENDENCIES = 0)
swig = pythonenv.Command("hammer.i", "../swig/hammer.i", Copy("$TARGET", "$SOURCE")) swig = pythonenv.Command("hammer.i", "../swig/hammer.i", Copy("$TARGET", "$SOURCE"))
setup = ['setup.py'] setup = ['setup.py']
pydir = os.path.join(env['BUILD_BASE'], 'src/bindings/python') pydir = os.path.join(env['BUILD_BASE'], 'src/bindings/python')
libhammer_python = pythonenv.Command(['hammer.py', 'hammer_wrap.c'], [swig, setup], 'python ' + os.path.join(pydir, 'setup.py') + ' build_ext --inplace') pysetup = os.path.join(pydir, 'setup.py')
libhammer_python = pythonenv.Command(['hammer.py', 'hammer_wrap.c'], [swig, setup], '%s %s build_ext --inplace' % (env['python'], pysetup))
Default(libhammer_python) Default(libhammer_python)
pytestenv = pythonenv.Clone() pytestenv = pythonenv.Clone()
pytestenv['ENV']['LD_LIBRARY_PATH'] = os.path.dirname(str(libhammer_shared[0])) pytestenv['ENV']['LD_LIBRARY_PATH'] = os.path.dirname(str(libhammer_shared[0]))
pytests = ['hammer_tests.py'] pytests = ['hammer_tests.py']
pytestexec = pytestenv.Command(['hammer.pyc', 'hammer_tests.pyc'], pytests + libhammer_python, "LD_LIBRARY_PATH=" + os.path.dirname(str(libhammer_shared[0])) + " nosetests -vv $SOURCE") pytestexec = pytestenv.Command(['hammer.pyc', 'hammer_tests.pyc'], pytests + libhammer_python, "LD_LIBRARY_PATH=%s %s -mnose -vv $SOURCE" % (os.path.dirname(str(libhammer_shared[0])), env['python']))
pytest = Alias("testpython", [pytestexec], pytestexec) pytest = Alias("testpython", [pytestexec], pytestexec)
AlwaysBuild(pytestexec) AlwaysBuild(pytestexec)
testruns.append(pytest) testruns.append(pytest)
pyinstallexec = pythonenv.Command(None, libhammer_python, 'python ' + os.path.join(pydir, 'setup.py ') + ' install') pyinstallexec = pythonenv.Command(None, libhammer_python, '%s %s install' % (env['python'], pysetup))
pyinstall = Alias("installpython", [pyinstallexec], pyinstallexec) pyinstall = Alias("installpython", [pyinstallexec], pyinstallexec)
targets.append(pyinstall) targets.append(pyinstall)