From 758011f3c20cc23804bb6dbe153852f0df026ffd Mon Sep 17 00:00:00 2001 From: "Bobby R. Bruce" Date: Mon, 25 Jan 2021 13:54:03 -0800 Subject: [PATCH] scons,python: Fix `--without-python` flag Even with the `--without-python` flag, checks were still done to ensure the correct version of Python was being used. This commit fixes this so these checks are not performed when `--without-python` is enabled. Change-Id: I2242f2971a49ef28cff229ad0337bce0a998413d Issue-on: https://gem5.atlassian.net/browse/GEM5-880 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/39715 Reviewed-by: Gabe Black Reviewed-by: Lukas Steiner Maintainer: Gabe Black Tested-by: kokoro --- SConstruct | 42 ++++++++++++++++++++++++------------------ src/SConscript | 17 +++++++++-------- 2 files changed, 33 insertions(+), 26 deletions(-) diff --git a/SConstruct b/SConstruct index 4cf2f1059..f744c77df 100755 --- a/SConstruct +++ b/SConstruct @@ -709,22 +709,25 @@ if main['USE_PYTHON']: if not conf.CheckLib(lib): error("Can't find library %s required by python." % lib) -main.Prepend(CPPPATH=Dir('ext/pybind11/include/')) -# Bare minimum environment that only includes python -marshal_env = main.Clone() -marshal_env.Append(CCFLAGS='$MARSHAL_CCFLAGS_EXTRA') -marshal_env.Append(LINKFLAGS='$MARSHAL_LDFLAGS_EXTRA') -py_version = conf.CheckPythonLib() -if not py_version: - error("Can't find a working Python installation") - -# Found a working Python installation. Check if it meets minimum -# requirements. -if py_version[0] < 3 or \ - (py_version[0] == 3 and py_version[1] < 6): - error('Python version too old. Version 3.6 or newer is required.') -elif py_version[0] > 3: - warning('Python version too new. Python 3 expected.') + main.Prepend(CPPPATH=Dir('ext/pybind11/include/')) + + marshal_env = main.Clone() + + # Bare minimum environment that only includes python + marshal_env.Append(CCFLAGS='$MARSHAL_CCFLAGS_EXTRA') + marshal_env.Append(LINKFLAGS='$MARSHAL_LDFLAGS_EXTRA') + + py_version = conf.CheckPythonLib() + if not py_version: + error("Can't find a working Python installation") + + # Found a working Python installation. Check if it meets minimum + # requirements. + if py_version[0] < 3 or \ + (py_version[0] == 3 and py_version[1] < 6): + error('Python version too old. Version 3.6 or newer is required.') + elif py_version[0] > 3: + warning('Python version too new. Python 3 expected.') # On Solaris you need to use libsocket for socket ops if not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): @@ -1271,10 +1274,13 @@ Build variables for {dir}: env.Append(CCFLAGS='$CCFLAGS_EXTRA') env.Append(LINKFLAGS='$LDFLAGS_EXTRA') + exports=['env'] + if main['USE_PYTHON']: + exports.append('marshal_env') + # The src/SConscript file sets up the build rules in 'env' according # to the configured variables. It returns a list of environments, # one for each variant build (debug, opt, etc.) - SConscript('src/SConscript', variant_dir=variant_path, - exports=['env', 'marshal_env']) + SConscript('src/SConscript', variant_dir=variant_path, exports=exports) atexit.register(summarize_warnings) diff --git a/src/SConscript b/src/SConscript index 81a1b4d09..74b9516a0 100644 --- a/src/SConscript +++ b/src/SConscript @@ -1208,11 +1208,6 @@ env.Command('sim/tags.cc', None, Transform("VER TAGS"))) env.AlwaysBuild(tags) -# Build a small helper that marshals the Python code using the same -# version of Python as gem5. This is in an unorthodox location to -# avoid building it for every variant. -py_marshal = marshal_env.Program('marshal', 'python/marshal.cc')[0] - # Embed python files. All .py files that have been indicated by a # PySource() call in a SConscript need to be embedded into the M5 # library. To do that, we compile the file to byte code, marshal the @@ -1266,10 +1261,16 @@ EmbeddedPython embedded_${sym}( ''') code.write(str(target[0])) -for source in PySource.all: - marshal_env.Command(source.cpp, [ py_marshal, source.tnode ], +if main['USE_PYTHON']: + # Build a small helper that marshals the Python code using the same + # version of Python as gem5. This is in an unorthodox location to + # avoid building it for every variant. + py_marshal = marshal_env.Program('marshal', 'python/marshal.cc')[0] + + for source in PySource.all: + marshal_env.Command(source.cpp, [ py_marshal, source.tnode ], MakeAction(embedPyFile, Transform("EMBED PY"))) - Source(source.cpp, tags=source.tags, add_tags='python') + Source(source.cpp, tags=source.tags, add_tags='python') ######################################################################## # -- 2.30.2