Andreas Sandberg has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/36383 )

Change subject: scons: Test if binaries can embed the Python interpreter
......................................................................

scons: Test if binaries can embed the Python interpreter

Add some more stringent Python tests that ensure that we can link with
and run applications that embed Python. This is implemented by running
building a small c++ program that embeds Python using PyBind11. The
program is run by the build system and prints the version of the
Python interpreter. The version information is then used by the build
system to ensure that the installed version is supported.

Change-Id: I727e0832f171362f5506247c022bea365068a0f6
Signed-off-by: Andreas Sandberg <andreas.sandb...@arm.com>
---
M SConstruct
1 file changed, 37 insertions(+), 3 deletions(-)



diff --git a/SConstruct b/SConstruct
index 8e7ec34..16558d2 100755
--- a/SConstruct
+++ b/SConstruct
@@ -575,6 +575,27 @@
     context.Result(ret)
     return ret

+def CheckPythonLib(context):
+    context.Message('Checking for Python...')
+    ret = context.TryRun(r"""
+#include <pybind11/embed.h>
+
+int
+main(int argc, char **argv) {
+    pybind11::scoped_interpreter guard{};
+    pybind11::exec(
+        "import sys\n"
+        "vi = sys.version_info\n"
+ "sys.stdout.write('%i.%i.%i' % (vi.major, vi.minor, vi.micro));\n");
+    return 0;
+}
+    """, extension=".cc")
+    context.Result(ret[1] if ret[0] == 1 else 0)
+    if ret[0] == 0:
+        return None
+    else:
+        return tuple((int(x) for x in ret[1].split(".")))
+
 # Platform-specific configuration.  Note again that we assume that all
 # builds under a given build root run on the same host platform.
 conf = Configure(main,
@@ -582,6 +603,7 @@
                  log_file = joinpath(build_root, 'scons_config.log'),
                  custom_tests = {
         'CheckMember' : CheckMember,
+        'CheckPythonLib' : CheckPythonLib,
         })

 # Check if we should compile a 64 bit binary on Mac OS X/Darwin
@@ -637,9 +659,6 @@
               main['PYTHON_CONFIG'])

     print("Info: Using Python config: %s" % (python_config, ))
-    if python_config != 'python3-config':
-        warning('python3-config could not be found.\n'
-                'Future releases of gem5 will drop support for python2.')

     py_includes = readCommand([python_config, '--includes'],
                               exception='').split()
@@ -697,6 +716,21 @@
 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")
+else:
+    # Found a working Python installation. Check if it meets minimum
+    # requirements.
+    if py_version[0] < 2 or \
+       (py_version[0] == 2 and py_version[1] < 7) or \
+       (py_version[0] == 3 and py_version[1] < 6):
+        error('Python version too old. '
+              'At least version Python 2.7 or 3.6 is required.')
+    elif py_version[0] == 2:
+        warning('Future releases of gem5 will drop support for Python 2.7')
+    elif py_version[0] > 3:
+        warning('Python version too new. Python 3.x expected.')

 # On Solaris you need to use libsocket for socket ops
if not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'):

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/36383
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: I727e0832f171362f5506247c022bea365068a0f6
Gerrit-Change-Number: 36383
Gerrit-PatchSet: 1
Gerrit-Owner: Andreas Sandberg <andreas.sandb...@arm.com>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to