8000 bpo-38360: macOS: support alternate form of -isysroot flag (GH-16480) · python/cpython@b310700 · GitHub
[go: up one dir, main page]

Skip to content

Commit b310700

Browse files
jmrootned-deily
andauthored
bpo-38360: macOS: support alternate form of -isysroot flag (GH-16480)
It is possible to use either '-isysroot /some/path' (with a space) or '-isysroot/some/path' (no space in between). Support both forms in places where special handling of -isysroot is done, rather than just the first form. Co-authored-by: Ned Deily <nad@python.org>
1 parent 3a69f3c commit b310700

File tree

5 files changed

+79
-16
lines changed

5 files changed

+79
-16
lines changed

Lib/_osx_support.py

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def _remove_universal_flags(_config_vars):
211211
if cv in _config_vars and cv not in os.environ:
212212
flags = _config_vars[cv]
213213
flags = re.sub(r'-arch\s+\w+\s', ' ', flags, flags=re.ASCII)
214-
flags = re.sub('-isysroot [^ \t]*', ' ', flags)
214+
flags = re.sub(r'-isysroot\s*\S+', ' ', flags)
215215
_save_modified_value(_config_vars, cv, flags)
216216

217217
return _config_vars
@@ -287,15 +287,15 @@ def _check_for_unavailable_sdk(_config_vars):
287287
# to /usr and /System/Library by either a standalone CLT
288288
# package or the CLT component within Xcode.
289289
cflags = _config_vars.get('CFLAGS', '')
290-
m = re.search(r'-isysroot\s+(\S+)', cflags)
290+
m = re.search(r'-isysroot\s*(\S+)', cflags)
291291
if m is not None:
292292
sdk = m.group(1)
293293
if not os.path.exists(sdk):
294294
for cv in _UNIVERSAL_CONFIG_VARS:
295295
# Do not alter a config var explicitly overridden by env var
296296
if cv in _config_vars and cv not in os.environ:
297297
flags = _config_vars[cv]
298-
flags = re.sub(r'-isysroot\s+\S+(?:\s|$)', ' ', flags)
298+
flags = re.sub(r'-isysroot\s*\S+(?:\s|$)', ' ', flags)
299299
_save_modified_value(_config_vars, cv, flags)
300300

301301
return _config_vars
@@ -320,7 +320,7 @@ def compiler_fixup(compiler_so, cc_args):
320320
stripArch = stripSysroot = True
321321
else:
322322
stripArch = '-arch' in cc_args
323-
stripSysroot = '-isysroot' in cc_args
323+
stripSysroot = any(arg for arg in cc_args if arg.startswith('-isysroot'))
324324

325325
if stripArch or 'ARCHFLAGS' in os.environ:
326326
while True:
@@ -338,23 +338,34 @@ def compiler_fixup(compiler_so, cc_args):
338338

339339
if stripSysroot:
340340
while True:
341-
try:
342-
index = compiler_so.index('-isysroot')
341+
indices = [i for i,x in enumerate(compiler_so) if x.startswith('-isysroot')]
342+
if not indices:
343+
break
344+
index = indices[0]
345+
if compiler_so[index] == '-isysroot':
343346
# Strip this argument and the next one:
344347
del compiler_so[index:index+2]
345-
except ValueError:
346-
break
348+
else:
349+
# It's '-isysroot/some/path' in one arg
350+
del compiler_so[index:index+1]
347351

348352
# Check if the SDK that is used during compilation actually exists,
349353
# the universal build requires the usage of a universal SDK and not all
350354
# users have that installed by default.
351355
sysroot = None
352-
if '-isysroot' in cc_args:
353-
idx = cc_args.index('-isysroot')
354-
sysroot = cc_args[idx+1]
355-
elif '-isysroot' in compiler_so:
356-
idx = compiler_so.index('-isysroot')
357-
sysroot = compiler_so[idx+1]
356+
argvar = cc_args
357+
indices = [i for i,x in enumerate(cc_args) if x.startswith('-isysroot')]
358+
if not indices:
359+
argvar = compiler_so
360+
indices = [i for i,x in enumerate(compiler_so) if x.startswith('-isysroot')]
361+
362+
for idx in indices:
363+
if argvar[idx] == '-isysroot':
364+
sysroot = argvar[idx+1]
365+
break
366+
else:
367+
sysroot = argvar[idx][len('-isysroot'):]
368+
break
358369

359370
if sysroot and not os.path.isdir(sysroot):
360371
from distutils import log

Lib/distutils/unixccompiler.py

6D47
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ def find_library_file(self, dirs, lib, debug=0):
288288
# vs
289289
# /usr/lib/libedit.dylib
290290
cflags = sysconfig.get_config_var('CFLAGS')
291-
m = re.search(r'-isysroot\s+(\S+)', cflags)
291+
m = re.search(r'-isysroot\s*(\S+)', cflags)
292292
if m is None:
293293
sysroot = '/'
294294
else:

Lib/test/test__osx_support.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,29 @@ def test__remove_universal_flags(self):
174174
_osx_support._remove_universal_flags(
175175
config_vars))
176176

177+
def test__remove_universal_flags_alternate(self):
178+
# bpo-38360: also test the alternate single-argument form of -isysroot
179+
config_vars = {
180+
'CFLAGS': '-fno-strict-aliasing -g -O3 -arch ppc -arch i386 ',
181+
'LDFLAGS': '-arch ppc -arch i386 -g',
182+
'CPPFLAGS': '-I. -isysroot/Developer/SDKs/MacOSX10.4u.sdk',
183+
'BLDSHARED': 'gcc-4.0 -bundle -arch ppc -arch i386 -g',
184+
'LDSHARED': 'gcc-4.0 -bundle -arch ppc -arch i386 '
185+
'-isysroot/Developer/SDKs/MacOSX10.4u.sdk -g',
186+
}
187+
expected_vars = {
188+
'CFLAGS': '-fno-strict-aliasing -g -O3 ',
189+
'LDFLAGS': ' -g',
190+
'CPPFLAGS': '-I. ',
191+
'BLDSHARED': 'gcc-4.0 -bundle -g',
192+
'LDSHARED': 'gcc-4.0 -bundle -g',
193+
}
194+
self.add_expected_saved_initial_values(config_vars, expected_vars)
195+
196+
self.assertEqual(expected_vars,
197+
_osx_support._remove_universal_flags(
198+
config_vars))
199+
177200
def test__remove_unsupported_archs(self):
178201
config_vars = {
179202
'CC': 'clang',
@@ -261,6 +284,34 @@ def test__check_for_unavailable_sdk(self):
261284
_osx_support._check_for_unavailable_sdk(
262285
config_vars))
263286

287+
def test__check_for_unavailable_sdk_alternate(self):
288+
# bpo-38360: also test the alternate single-argument form of -isysroot
289+
config_vars = {
290+
'CC': 'clang',
291+
'CFLAGS': '-fno-strict-aliasing -g -O3 -arch ppc -arch i386 '
292+
'-isysroot/Developer/SDKs/MacOSX10.1.sdk',
293+
'LDFLAGS': '-arch ppc -arch i386 -g',
294+
'CPPFLAGS': '-I. -isysroot/Developer/SDKs/MacOSX10.1.sdk',
295+
'BLDSHARED': 'gcc-4.0 -bundle -arch ppc -arch i386 -g',
296+
'LDSHARED': 'gcc-4.0 -bundle -arch ppc -arch i386 '
297+
'-isysroot/Developer/SDKs/MacOSX10.1.sdk -g',
298+
}
299+
expected_vars = {
300+
'CC': 'clang',
301+
'CFLAGS': '-fno-strict-aliasing -g -O3 -arch ppc -arch i386 '
302+
' ',
303+
'LDFLAGS': '-arch ppc -arch i386 -g',
304+
'CPPFLAGS': '-I. ',
305+
'BLDSHARED': 'gcc-4.0 -bundle -arch ppc -arch i386 -g',
306+
'LDSHARED': 'gcc-4.0 -bundle -arch ppc -arch i386 '
307+
' -g',
308+
}
309+
self.add_expected_saved_initial_values(config_vars, expected_vars)
310+
311+
self.assertEqual(expected_vars,
312+
_osx_support._check_for_unavailable_sdk(
313+
config_vars))
314+
264315
def test_get_platform_osx(self):
265316
# Note, get_platform_osx is currently tested more extensively
266317
# indirectly by test_sysconfig and test_distutils
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Support single-argument form of macOS -isysroot flag.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def macosx_sdk_root():
170170
return MACOS_SDK_ROOT
171171

172172
cflags = sysconfig.get_config_var('CFLAGS')
173-
m = re.search(r'-isysroot\s+(\S+)', cflags)
173+
m = re.search(r'-isysroot\s*(\S+)', cflags)
174174
if m is not None:
175175
MACOS_SDK_ROOT = m.group(1)
176176
else:

0 commit comments

Comments
 (0)
0