Skip to content

Commit c76b8a2

Browse files
committed
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.
1 parent fb4ae15 commit c76b8a2

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-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.find('-isysroot') == 0)
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.find('-isysroot') == 0]
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.find('-isysroot') == 0]
358+
if not indices:
359+
argvar = compiler_so
360+
indices = [i for i,x in enumerate(compiler_so) if x.find('-isysroot') == 0]
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

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:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def macosx_sdk_root():
146146
return MACOS_SDK_ROOT
147147

148148
cflags = sysconfig.get_config_var('CFLAGS')
149-
m = re.search(r'-isysroot\s+(\S+)', cflags)
149+
m = re.search(r'-isysroot\s*(\S+)', cflags)
150150
if m is not None:
151151
MACOS_SDK_ROOT = m.group(1)
152152
else:

0 commit comments

Comments
 (0)