]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #18080: When building a C extension module on OS X, if the compiler
authorNed Deily <nad@acm.org>
Tue, 28 May 2013 23:31:45 +0000 (16:31 -0700)
committerNed Deily <nad@acm.org>
Tue, 28 May 2013 23:31:45 +0000 (16:31 -0700)
is overriden with the CC environment variable, use the new compiler as
the default for linking if LDSHARED is not also overriden.  This restores
Distutils behavior introduced in 2.7.3 and inadvertently dropped in 2.7.4.

Lib/distutils/sysconfig.py
Lib/distutils/tests/test_unixccompiler.py
Misc/NEWS

index 0c726d92ffbaddaa18d6a59833bd6108c17d6043..4aa93346d5306f6b93b3d6948c984ead1e932612 100644 (file)
@@ -175,9 +175,15 @@ def customize_compiler(compiler):
                             'CCSHARED', 'LDSHARED', 'SO', 'AR',
                             'ARFLAGS')
 
-        newcc = None
         if 'CC' in os.environ:
-            cc = os.environ['CC']
+            newcc = os.environ['CC']
+            if (sys.platform == 'darwin'
+                    and 'LDSHARED' not in os.environ
+                    and ldshared.startswith(cc)):
+                # On OS X, if CC is overridden, use that as the default
+                #       command for LDSHARED as well
+                ldshared = newcc + ldshared[len(cc):]
+            cc = newcc
         if 'CXX' in os.environ:
             cxx = os.environ['CXX']
         if 'LDSHARED' in os.environ:
index 40c908a24d060b0084056996392040d73f2eeba6..64f9d26751154217e1bcf1b2bc35e3349d7a9d0a 100644 (file)
@@ -1,7 +1,8 @@
 """Tests for distutils.unixccompiler."""
+import os
 import sys
 import unittest
-from test.test_support import run_unittest
+from test.test_support import EnvironmentVarGuard, run_unittest
 
 from distutils import sysconfig
 from distutils.unixccompiler import UnixCCompiler
@@ -122,6 +123,37 @@ class UnixCCompilerTestCase(unittest.TestCase):
         sysconfig.get_config_var = gcv
         self.assertEqual(self.cc.rpath_foo(), '-R/foo')
 
+    @unittest.skipUnless(sys.platform == 'darwin', 'test only relevant for OS X')
+    def test_osx_cc_overrides_ldshared(self):
+        # Issue #18080:
+        # ensure that setting CC env variable also changes default linker
+        def gcv(v):
+            if v == 'LDSHARED':
+                return 'gcc-4.2 -bundle -undefined dynamic_lookup '
+            return 'gcc-4.2'
+        sysconfig.get_config_var = gcv
+        with EnvironmentVarGuard() as env:
+            env['CC'] = 'my_cc'
+            del env['LDSHARED']
+            sysconfig.customize_compiler(self.cc)
+        self.assertEqual(self.cc.linker_so[0], 'my_cc')
+
+    @unittest.skipUnless(sys.platform == 'darwin', 'test only relevant for OS X')
+    def test_osx_explict_ldshared(self):
+        # Issue #18080:
+        # ensure that setting CC env variable does not change
+        #   explicit LDSHARED setting for linker
+        def gcv(v):
+            if v == 'LDSHARED':
+                return 'gcc-4.2 -bundle -undefined dynamic_lookup '
+            return 'gcc-4.2'
+        sysconfig.get_config_var = gcv
+        with EnvironmentVarGuard() as env:
+            env['CC'] = 'my_cc'
+            env['LDSHARED'] = 'my_ld -bundle -dynamic'
+            sysconfig.customize_compiler(self.cc)
+        self.assertEqual(self.cc.linker_so[0], 'my_ld')
+
 
 def test_suite():
     return unittest.makeSuite(UnixCCompilerTestCase)
index 13f7cc360a34d6a52c0e11d90d8d2b8770523e0c..00448c45af4b93c487fe8c0152b245321eac5f2c 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -28,6 +28,11 @@ Library
 - Issue #17269: Workaround for socket.getaddrinfo crash on MacOS X
   with port None or "0" and flags AI_NUMERICSERV.
 
+- Issue #18080: When building a C extension module on OS X, if the compiler
+  is overriden with the CC environment variable, use the new compiler as
+  the default for linking if LDSHARED is not also overriden.  This restores
+  Distutils behavior introduced in 2.7.3 and inadvertently dropped in 2.7.4.
+
 IDLE
 ----