Gabe Black has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/49422 )

Change subject: scons: Ensure the gem5py_env always has embedded python.
......................................................................

scons: Ensure the gem5py_env always has embedded python.

Even if the gem5 binary itself won't.

Change-Id: I825e2cbed35a3dcc4fb4bec6f2fd71e78164e7c0
---
M SConstruct
1 file changed, 21 insertions(+), 15 deletions(-)



diff --git a/SConstruct b/SConstruct
index 7e06e68..59135cf 100755
--- a/SConstruct
+++ b/SConstruct
@@ -476,24 +476,25 @@
 ########################################################################

 main['USE_PYTHON'] = not GetOption('without_python')
-if main['USE_PYTHON']:
+
+def config_embedded_python(env):
     # Find Python include and library directories for embedding the
     # interpreter. We rely on python-config to resolve the appropriate
# includes and linker flags. If you want to link in an alternate version
     # of python, override the PYTHON_CONFIG variable.

-    python_config = main.Detect(main['PYTHON_CONFIG'])
+    python_config = env.Detect(env['PYTHON_CONFIG'])
     if python_config is None:
-        error("Can't find a suitable python-config, tried %s" % \
-              main['PYTHON_CONFIG'])
+        error("Can't find a suitable python-config, tried "
+              f"{env['PYTHON_CONFIG']}")

-    print("Info: Using Python config: %s" % python_config)
+    print(f"Info: Using Python config: {python_config}")

     cmd = [python_config, '--ldflags', '--includes']

# Starting in Python 3.8 the --embed flag is required. Use it if supported.
-    with gem5_scons.Configure(main) as conf:
-        if conf.TryAction('@%s --embed' % python_config)[0]:
+    with gem5_scons.Configure(env) as conf:
+        if conf.TryAction(f'@{python_config} --embed')[0]:
             cmd.append('--embed')

     def flag_filter(env, cmd_output):
@@ -503,11 +504,11 @@
         useful_flags = list(filter(is_useful, flags))
         env.MergeFlags(' '.join(useful_flags))

-    main.ParseConfig(cmd, flag_filter)
+    env.ParseConfig(cmd, flag_filter)

-    main.Prepend(CPPPATH=Dir('ext/pybind11/include/'))
+    env.Prepend(CPPPATH=Dir('ext/pybind11/include/'))

-    with gem5_scons.Configure(main) as conf:
+    with gem5_scons.Configure(env) as conf:
         # verify that this stuff works
         if not conf.CheckHeader('Python.h', '<>'):
             error("Check failed for Python.h header.\n",
@@ -516,7 +517,7 @@
                   "package python-dev on Ubuntu and RedHat)\n"
"2. SCons is using a wrong C compiler. This can happen if "
                   "CC has the wrong value.\n"
-                  "CC = %s" % main['CC'])
+                  f"CC = {env['CC']}")
         py_version = conf.CheckPythonLib()
         if not py_version:
             error("Can't find a working Python installation")
@@ -525,13 +526,18 @@
     # requirements.
     ver_string = '.'.join(map(str, py_version))
     if py_version[0] < 3 or (py_version[0] == 3 and py_version[1] < 6):
-        error('Embedded python library 3.6 or newer required, found %s.' %
-              ver_string)
+        error('Embedded python library 3.6 or newer required, found '
+              f'{ver_string}.')
     elif py_version[0] > 3:
         warning('Embedded python library too new. '
-                'Python 3 expected, found %s.' % ver_string)
+                f'Python 3 expected, found {ver_string}.')

-gem5py_env = main.Clone()
+if main['USE_PYTHON']:
+    config_embedded_python(main)
+    gem5py_env = main.Clone()
+else:
+    gem5py_env = main.Clone()
+    config_embedded_python(gem5py_env)

 # Bare minimum environment that only includes python
 gem5py_env.Append(CCFLAGS=['${MARSHAL_CCFLAGS_EXTRA}',

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/49422
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I825e2cbed35a3dcc4fb4bec6f2fd71e78164e7c0
Gerrit-Change-Number: 49422
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to