Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6750282

Browse files
committed
Issue #18080: merge from 3.3
2 parents 56dfc21 + 9734568 commit 6750282

3 files changed

Lines changed: 47 additions & 4 deletions

File tree

Lib/distutils/sysconfig.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,15 @@ def customize_compiler(compiler):
188188
get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS',
189189
'CCSHARED', 'LDSHARED', 'SHLIB_SUFFIX', 'AR', 'ARFLAGS')
190190

191-
newcc = None
192191
if 'CC' in os.environ:
193-
cc = os.environ['CC']
192+
newcc = os.environ['CC']
193+
if (sys.platform == 'darwin'
194+
and 'LDSHARED' not in os.environ
195+
and ldshared.startswith(cc)):
196+
# On OS X, if CC is overridden, use that as the default
197+
# command for LDSHARED as well
198+
ldshared = newcc + ldshared[len(cc):]
199+
cc = newcc
194200
if 'CXX' in os.environ:
195201
cxx = os.environ['CXX']
196202
if 'LDSHARED' in os.environ:

Lib/distutils/tests/test_unixccompiler.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"""Tests for distutils.unixccompiler."""
2+
import os
23
import sys
34
import unittest
4-
from test.support import run_unittest
5+
from test.support import EnvironmentVarGuard, run_unittest
56

67
from distutils import sysconfig
78
from distutils.unixccompiler import UnixCCompiler
@@ -94,7 +95,6 @@ def gcv(v):
9495
sysconfig.get_config_var = gcv
9596
self.assertEqual(self.cc.rpath_foo(), '-Wl,--enable-new-dtags,-R/foo')
9697

97-
9898
# non-GCC GNULD
9999
sys.platform = 'bar'
100100
def gcv(v):
@@ -115,6 +115,38 @@ def gcv(v):
115115
sysconfig.get_config_var = gcv
116116
self.assertEqual(self.cc.rpath_foo(), '-R/foo')
117117

118+
@unittest.skipUnless(sys.platform == 'darwin', 'test only relevant for OS X')
119+
def test_osx_cc_overrides_ldshared(self):
120+
# Issue #18080:
121+
# ensure that setting CC env variable also changes default linker
122+
def gcv(v):
123+
if v == 'LDSHARED':
124+
return 'gcc-4.2 -bundle -undefined dynamic_lookup '
125+
return 'gcc-4.2'
126+
sysconfig.get_config_var = gcv
127+
with EnvironmentVarGuard() as env:
128+
env['CC'] = 'my_cc'
129+
del env['LDSHARED']
130+
sysconfig.customize_compiler(self.cc)
131+
self.assertEqual(self.cc.linker_so[0], 'my_cc')
132+
133+
@unittest.skipUnless(sys.platform == 'darwin', 'test only relevant for OS X')
134+
def test_osx_explict_ldshared(self):
135+
# Issue #18080:
136+
# ensure that setting CC env variable does not change
137+
# explicit LDSHARED setting for linker
138+
def gcv(v):
139+
if v == 'LDSHARED':
140+
return 'gcc-4.2 -bundle -undefined dynamic_lookup '
141+
return 'gcc-4.2'
142+
sysconfig.get_config_var = gcv
143+
with EnvironmentVarGuard() as env:
144+
env['CC'] = 'my_cc'
145+
env['LDSHARED'] = 'my_ld -bundle -dynamic'
146+
sysconfig.customize_compiler(self.cc)
147+
self.assertEqual(self.cc.linker_so[0], 'my_ld')
148+
149+
118150
def test_suite():
119151
return unittest.makeSuite(UnixCCompilerTestCase)
120152

Misc/NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,11 @@ Library
308308
- Issue #17032: The "global" in the "NameError: global name 'x' is not defined"
309309
error message has been removed. Patch by Ram Rachum.
310310

311+
- Issue #18080: When building a C extension module on OS X, if the compiler
312+
is overriden with the CC environment variable, use the new compiler as
313+
the default for linking if LDSHARED is not also overriden. This restores
314+
Distutils behavior introduced in 3.2.3 and inadvertently dropped in 3.3.0.
315+
311316
Tests
312317
-----
313318

0 commit comments

Comments
 (0)