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

Skip to content

Commit 2747177

Browse files
committed
Issue #13590: Improve support for OS X Xcode 4:
- fix test_distutils and test_sysconfig test failures by aligning sysconfig and distutils.sysconfig tailoring of configure variables (as in 2.7)
1 parent 950b76a commit 2747177

3 files changed

Lines changed: 33 additions & 23 deletions

File tree

Lib/distutils/sysconfig.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ def get_config_vars(*args):
624624
# are in CFLAGS or LDFLAGS and remove them if they are.
625625
# This is needed when building extensions on a 10.3 system
626626
# using a universal build of python.
627-
for key in ('LDFLAGS', 'BASECFLAGS',
627+
for key in ('LDFLAGS', 'BASECFLAGS', 'LDSHARED',
628628
# a number of derived variables. These need to be
629629
# patched up as well.
630630
'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
@@ -669,16 +669,39 @@ def get_config_vars(*args):
669669
# that OS release.
670670
if 'ARCHFLAGS' in os.environ:
671671
arch = os.environ['ARCHFLAGS']
672-
for key in ('LDFLAGS', 'BASECFLAGS',
672+
for key in ('LDFLAGS', 'BASECFLAGS', 'LDSHARED',
673673
# a number of derived variables. These need to be
674674
# patched up as well.
675-
'CFLAGS', 'PY_CFLAGS', 'BLDSHARED', 'LDSHARED'):
675+
'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
676676

677677
flags = _config_vars[key]
678678
flags = re.sub('-arch\s+\w+\s', ' ', flags)
679679
flags = flags + ' ' + arch
680680
_config_vars[key] = flags
681681

682+
# If we're on OSX 10.5 or later and the user tries to
683+
# compiles an extension using an SDK that is not present
684+
# on the current machine it is better to not use an SDK
685+
# than to fail.
686+
#
687+
# The major usecase for this is users using a Python.org
688+
# binary installer on OSX 10.6: that installer uses
689+
# the 10.4u SDK, but that SDK is not installed by default
690+
# when you install Xcode.
691+
#
692+
m = re.search('-isysroot\s+(\S+)', _config_vars['CFLAGS'])
693+
if m is not None:
694+
sdk = m.group(1)
695+
if not os.path.exists(sdk):
696+
for key in ('LDFLAGS', 'BASECFLAGS', 'LDSHARED',
697+
# a number of derived variables. These need to be
698+
# patched up as well.
699+
'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
700+
701+
flags = _config_vars[key]
702+
flags = re.sub('-isysroot\s+\S+(\s|$)', ' ', flags)
703+
_config_vars[key] = flags
704+
682705
if args:
683706
vals = []
684707
for name in args:

Lib/distutils/unixccompiler.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ def _darwin_compiler_fixup(compiler_so, cc_args):
8383
except ValueError:
8484
pass
8585

86-
# Check if the SDK that is used during compilation actually exists.
87-
# If not, revert to using the installed headers and hope for the best.
86+
# Check if the SDK that is used during compilation actually exists,
87+
# the universal build requires the usage of a universal SDK and not all
88+
# users have that installed by default.
8889
sysroot = None
8990
if '-isysroot' in cc_args:
9091
idx = cc_args.index('-isysroot')
@@ -96,21 +97,7 @@ def _darwin_compiler_fixup(compiler_so, cc_args):
9697
if sysroot and not os.path.isdir(sysroot):
9798
log.warn("Compiling with an SDK that doesn't seem to exist: %s",
9899
sysroot)
99-
log.warn("Attempting to compile without the SDK")
100-
while True:
101-
try:
102-
index = cc_args.index('-isysroot')
103-
# Strip this argument and the next one:
104-
del cc_args[index:index+2]
105-
except ValueError:
106-
break
107-
while True:
108-
try:
109-
index = compiler_so.index('-isysroot')
110-
# Strip this argument and the next one:
111-
del compiler_so[index:index+2]
112-
except ValueError:
113-
break
100+
log.warn("Please check your Xcode installation")
114101

115102
return compiler_so
116103

Lib/sysconfig.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ def get_config_vars(*args):
565565
# are in CFLAGS or LDFLAGS and remove them if they are.
566566
# This is needed when building extensions on a 10.3 system
567567
# using a universal build of python.
568-
for key in ('LDFLAGS', 'BASECFLAGS',
568+
for key in ('LDFLAGS', 'BASECFLAGS', 'LDSHARED',
569569
# a number of derived variables. These need to be
570570
# patched up as well.
571571
'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
@@ -581,7 +581,7 @@ def get_config_vars(*args):
581581
# that OS release.
582582
if 'ARCHFLAGS' in os.environ:
583583
arch = os.environ['ARCHFLAGS']
584-
for key in ('LDFLAGS', 'BASECFLAGS',
584+
for key in ('LDFLAGS', 'BASECFLAGS', 'LDSHARED',
585585
# a number of derived variables. These need to be
586586
# patched up as well.
587587
'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
@@ -606,7 +606,7 @@ def get_config_vars(*args):
606606
if m is not None:
607607
sdk = m.group(1)
608608
if not os.path.exists(sdk):
609-
for key in ('LDFLAGS', 'BASECFLAGS',
609+
for key in ('LDFLAGS', 'BASECFLAGS', 'LDSHARED',
610610
# a number of derived variables. These need to be
611611
# patched up as well.
612612
'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):

0 commit comments

Comments
 (0)