Ticket #39217: patch-issue18080_ldshared_2.7.diff

File patch-issue18080_ldshared_2.7.diff, 3.1 KB (added by jdgleeson, 11 years ago)
  • Lib/distutils/sysconfig.py

    # HG changeset patch
    # Parent 687295c6c8f2b98b4ad0b9d5cfdcc390764b8138
    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.
    
    diff --git a/Lib/distutils/sysconfig.py b/Lib/distutils/sysconfig.py
     
    175175                            'CCSHARED', 'LDSHARED', 'SO', 'AR',
    176176                            'ARFLAGS')
    177177
    178         newcc = None
    179178        if 'CC' in os.environ:
    180             cc = os.environ['CC']
     179            newcc = os.environ['CC']
     180            if (sys.platform == 'darwin'
     181                    and 'LDSHARED' not in os.environ
     182                    and ldshared.startswith(cc)):
     183                # On OS X, if CC is overridden, use that as the default
     184                #       command for LDSHARED as well
     185                ldshared = newcc + ldshared[len(cc):]
     186            cc = newcc
    181187        if 'CXX' in os.environ:
    182188            cxx = os.environ['CXX']
    183189        if 'LDSHARED' in os.environ:
  • Lib/distutils/tests/test_unixccompiler.py

    diff --git a/Lib/distutils/tests/test_unixccompiler.py b/Lib/distutils/tests/test_unixccompiler.py
     
    11"""Tests for distutils.unixccompiler."""
     2import os
    23import sys
    34import unittest
    4 from test.test_support import run_unittest
     5from test.test_support import EnvironmentVarGuard, run_unittest
    56
    67from distutils import sysconfig
    78from distutils.unixccompiler import UnixCCompiler
     
    122123        sysconfig.get_config_var = gcv
    123124        self.assertEqual(self.cc.rpath_foo(), '-R/foo')
    124125
     126    @unittest.skipUnless(sys.platform == 'darwin', 'test only relevant for OS X')
     127    def test_osx_cc_overrides_ldshared(self):
     128        # ensure that setting CC env variable also changes default linker
     129        def gcv(v):
     130            if v == 'LDSHARED':
     131                return 'gcc-4.2 -bundle -undefined dynamic_lookup '
     132            return 'gcc-4.2'
     133        sysconfig.get_config_var = gcv
     134        with EnvironmentVarGuard() as env:
     135            env['CC'] = 'my_cc'
     136            del env['LDSHARED']
     137            sysconfig.customize_compiler(self.cc)
     138        self.assertEqual(self.cc.linker_so[0], 'my_cc')
     139
     140    @unittest.skipUnless(sys.platform == 'darwin', 'test only relevant for OS X')
     141    def test_osx_explict_ldshared(self):
     142        # ensure that setting CC env variable does not change
     143        #   explicit LDSHARED setting for linker
     144        def gcv(v):
     145            if v == 'LDSHARED':
     146                return 'gcc-4.2 -bundle -undefined dynamic_lookup '
     147            return 'gcc-4.2'
     148        sysconfig.get_config_var = gcv
     149        with EnvironmentVarGuard() as env:
     150            env['CC'] = 'my_cc'
     151            env['LDSHARED'] = 'my_ld -bundle -dynamic'
     152            sysconfig.customize_compiler(self.cc)
     153        self.assertEqual(self.cc.linker_so[0], 'my_ld')
     154
    125155
    126156def test_suite():
    127157    return unittest.makeSuite(UnixCCompilerTestCase)