Author: Armin Rigo <[email protected]>
Branch: py3.5
Changeset: r94544:7f62e74d2342
Date: 2018-05-13 08:46 +0000
http://bitbucket.org/pypy/pypy/changeset/7f62e74d2342/

Log:    Merged in toumorokoshi/pypy/py3.5 (pull request #608)

        Adding detection of gcc to sysconfig_pypy (fixes #2809)

diff --git a/lib-python/3/distutils/sysconfig_pypy.py 
b/lib-python/3/distutils/sysconfig_pypy.py
--- a/lib-python/3/distutils/sysconfig_pypy.py
+++ b/lib-python/3/distutils/sysconfig_pypy.py
@@ -63,39 +63,9 @@
 
 def _init_posix():
     """Initialize the module as appropriate for POSIX systems."""
-    so_ext = [s[0] for s in imp.get_suffixes() if s[2] == imp.C_EXTENSION][0]
-
-    g = {}
-    g['CC'] = "cc -pthread"
-    g['CXX'] = "c++ -pthread"
-    g['OPT'] = "-DNDEBUG -O2"
-    g['CFLAGS'] = "-DNDEBUG -O2"
-    g['CCSHARED'] = "-fPIC"
-    g['LDSHARED'] = "cc -pthread -shared"
-    g['EXT_SUFFIX'] = so_ext
-    g['SHLIB_SUFFIX'] = ".so"
-    g['SO'] = so_ext  # deprecated in Python 3, for backward compatibility
-    g['AR'] = "ar"
-    g['ARFLAGS'] = "rc"
-    g['EXE'] = ""
-    g['LIBDIR'] = os.path.join(sys.prefix, 'lib')
-    g['VERSION'] = get_python_version()
-
-    if sys.platform[:6] == "darwin":
-        import platform
-        if platform.machine() == 'i386':
-            if platform.architecture()[0] == '32bit':
-                arch = 'i386'
-            else:
-                arch = 'x86_64'
-        else:
-            # just a guess
-            arch = platform.machine()
-        g['LDSHARED'] += ' -undefined dynamic_lookup'
-        g['CC'] += ' -arch %s' % (arch,)
-
+    from _sysconfigdata import build_time_vars
     global _config_vars
-    _config_vars = g
+    _config_vars.update(build_time_vars)
 
 
 def _init_nt():
@@ -221,4 +191,3 @@
 
 from .sysconfig_cpython import (
     parse_makefile, _variable_rx, expand_makefile_vars)
-
diff --git a/lib-python/3/test/test_sysconfig.py 
b/lib-python/3/test/test_sysconfig.py
--- a/lib-python/3/test/test_sysconfig.py
+++ b/lib-python/3/test/test_sysconfig.py
@@ -4,6 +4,7 @@
 import subprocess
 import shutil
 from copy import copy
+from distutils.spawn import find_executable
 
 from test.support import (run_unittest, TESTFN, unlink, check_warnings,
                           captured_stdout, impl_detail, import_module,
@@ -297,6 +298,30 @@
 
         self.assertIn(ldflags, ldshared)
 
+    @unittest.skipIf(sys.platform == "win32", "Does not apply to Windows")
+    def test_cc_values(self):
+        """ CC and CXX should be set for pypy """
+        for var in ["CC", "CXX"]:
+            assert sysconfig.get_config_var(var) is not None
+
+    @unittest.skipIf(not find_executable("gcc"),
+        "Does not apply to machines without gcc installed"
+    )
+    def test_gcc_values(self):
+        """ if gcc is installed on the box, gcc values should be set. """
+        assert "gcc" in sysconfig.get_config_var("CC")
+        assert sysconfig.get_config_var("GNULD") == "yes"
+        assert "gcc" in sysconfig.get_config_var("LDSHARED")
+
+
+    @unittest.skipIf(not find_executable("g++"),
+        "Does not apply to machines without g++ installed"
+    )
+    def test_gplusplus_values(self):
+        """ if g++ is installed on the box, g++ values should be set. """
+        assert "g++" in sysconfig.get_config_var("CXX")
+
+
     @unittest.skipUnless(sys.platform == "darwin", "test only relevant on 
MacOSX")
     def test_platform_in_subprocess(self):
         my_platform = sysconfig.get_platform()
diff --git a/lib_pypy/_sysconfigdata.py b/lib_pypy/_sysconfigdata.py
--- a/lib_pypy/_sysconfigdata.py
+++ b/lib_pypy/_sysconfigdata.py
@@ -1,10 +1,49 @@
 import _imp
+import os
+import sys
+from distutils.spawn import find_executable
 
 so_ext = _imp.extension_suffixes()[0]
 
+
 build_time_vars = {
     "EXT_SUFFIX": so_ext,
     "SHLIB_SUFFIX": so_ext,
     "SOABI": '-'.join(so_ext.split('.')[1].split('-')[:2]),
-    "SO": so_ext  # deprecated in Python 3, for backward compatibility
+    "SO": so_ext,  # deprecated in Python 3, for backward compatibility
+    'CC': "cc -pthread",
+    'CXX': "c++ -pthread",
+    'OPT': "-DNDEBUG -O2",
+    'CFLAGS': "-DNDEBUG -O2",
+    'CCSHARED': "-fPIC",
+    'LDSHARED': "cc -pthread -shared",
+    'EXT_SUFFIX': so_ext,
+    'SHLIB_SUFFIX': ".so",
+    'AR': "ar",
+    'ARFLAGS': "rc",
+    'EXE': "",
+    'LIBDIR': os.path.join(sys.prefix, 'lib'),
+    'VERSION': sys.version[:3]
 }
+
+if sys.platform[:6] == "darwin":
+    import platform
+    if platform.machine() == 'i386':
+        if platform.architecture()[0] == '32bit':
+            arch = 'i386'
+        else:
+            arch = 'x86_64'
+    else:
+        # just a guess
+        arch = platform.machine()
+    build_time_vars['LDSHARED'] += ' -undefined dynamic_lookup'
+    build_time_vars['CC'] += ' -arch %s' % (arch,)
+
+if find_executable("gcc"):
+    build_time_vars.update({
+        "CC": "gcc -pthread",
+        "GNULD": "yes",
+        "LDSHARED": "gcc -pthread -shared",
+    })
+    if find_executable("g++"):
+        build_time_vars["CXX"] = "g++ -pthread"
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to