Gabe Black has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/40971 )
Change subject: scons: Simplify finding the python lib with ParseConfig.
......................................................................
scons: Simplify finding the python lib with ParseConfig.
A comment in that section of SConstruct talked about how ParseConfig
couldn't understand -Xlinker and -export-dynamic, and how that meant
they needed to parse the output of python-config manually. Some
searching around turned up this:
https://bugs.python.org/issue36508
which seems to suggest that exactly those two options weren't actually
supposed to be returned by python-config in the first place, and are
really for python's own internal build.
Change-Id: I1a50eb030019a447b919381c32168fb3bb27b89b
---
M SConstruct
1 file changed, 13 insertions(+), 47 deletions(-)
diff --git a/SConstruct b/SConstruct
index 6f7c353..7397d03 100755
--- a/SConstruct
+++ b/SConstruct
@@ -84,7 +84,6 @@
from os.path import abspath, dirname, expanduser
from os.path import isdir, isfile
from os.path import join, split
-from re import match
# SCons includes
import SCons
@@ -423,11 +422,8 @@
if main['USE_PYTHON']:
# Find Python include and library directories for embedding the
# interpreter. We rely on python-config to resolve the appropriate
- # includes and linker flags. ParseConfig does not seem to understand
- # the more exotic linker flags such as -Xlinker and -export-dynamic so
- # we add them explicitly below. If you want to link in an alternate
- # version of python, see above for instructions on how to invoke
- # scons with the appropriate PATH set.
+ # 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'])
if python_config is None:
@@ -436,41 +432,13 @@
print("Info: Using Python config: %s" % (python_config, ))
- py_includes = readCommand([python_config, '--includes'],
- exception='').split()
- py_includes = list(filter(
- lambda s: match(r'.*\/include\/.*',s), py_includes))
- # Strip the -I from the include folders before adding them to the
- # CPPPATH
- py_includes = list(map(
- lambda s: s[2:] if s.startswith('-I') else s, py_includes))
- main.Append(CPPPATH=py_includes)
+ cmd = [python_config, '--ldflags', '--includes']
- # Read the linker flags and split them into libraries and other link
- # flags. The libraries are added later through the call the CheckLib.
- # Note: starting in Python 3.8 the --embed flag is required to get the
- # -lpython3.8 linker flag
- retcode, cmd_stdout = readCommandWithReturn(
- [python_config, '--ldflags', '--embed'], exception='')
- if retcode != 0:
- # If --embed isn't detected then we're running python <3.8
- retcode, cmd_stdout = readCommandWithReturn(
- [python_config, '--ldflags'], exception='')
+ # Starting in Python 3.8 the --embed flag is required. Use it if
supported.
+ if conf.TryAction('@%s --embed' % python_config)[0]:
+ cmd.append('--embed')
- # Checking retcode again
- if retcode != 0:
- error("Failing on python-config --ldflags command")
-
- py_ld_flags = cmd_stdout.split()
-
- py_libs = []
- for lib in py_ld_flags:
- if not lib.startswith('-l'):
- main.Append(LINKFLAGS=[lib])
- else:
- lib = lib[2:]
- if lib not in py_libs:
- py_libs.append(lib)
+ main.ParseConfig(cmd)
# verify that this stuff works
if not conf.CheckHeader('Python.h', '<>'):
@@ -483,10 +451,6 @@
"CC has the wrong value.\n"
"CC = %s" % main['CC'])
- for lib in py_libs:
- if not conf.CheckLib(lib):
- error("Can't find library %s required by python." % lib)
-
main.Prepend(CPPPATH=Dir('ext/pybind11/include/'))
marshal_env = main.Clone()
@@ -501,11 +465,13 @@
# 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.')
+ 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)
elif py_version[0] > 3:
- warning('Python version too new. Python 3 expected.')
+ warning('Embedded python library too new. '
+ 'Python 3 expected, found %s.' % ver_string)
# On Solaris you need to use libsocket for socket ops
if not conf.CheckLibWithHeader(
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/40971
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: I1a50eb030019a447b919381c32168fb3bb27b89b
Gerrit-Change-Number: 40971
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