@@ -211,7 +211,7 @@ def _remove_universal_flags(_config_vars):
211
211
if cv in _config_vars and cv not in os .environ :
212
212
flags = _config_vars [cv ]
213
213
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 )
215
215
_save_modified_value (_config_vars , cv , flags )
216
216
217
217
return _config_vars
@@ -287,15 +287,15 @@ def _check_for_unavailable_sdk(_config_vars):
287
287
# to /usr and /System/Library by either a standalone CLT
288
288
# package or the CLT component within Xcode.
289
289
cflags = _config_vars .get ('CFLAGS' , '' )
290
- m = re .search (r'-isysroot\s+ (\S+)' , cflags )
290
+ m = re .search (r'-isysroot\s* (\S+)' , cflags )
291
291
if m is not None :
292
292
sdk = m .group (1 )
293
293
if not os .path .exists (sdk ):
294
294
for cv in _UNIVERSAL_CONFIG_VARS :
295
295
# Do not alter a config var explicitly overridden by env var
296
296
if cv in _config_vars and cv not in os .environ :
297
297
flags = _config_vars [cv ]
298
- flags = re .sub (r'-isysroot\s+ \S+(?:\s|$)' , ' ' , flags )
298
+ flags = re .sub (r'-isysroot\s* \S+(?:\s|$)' , ' ' , flags )
299
299
_save_modified_value (_config_vars , cv , flags )
300
300
301
301
return _config_vars
@@ -320,7 +320,7 @@ def compiler_fixup(compiler_so, cc_args):
320
320
stripArch = stripSysroot = True
321
321
else :
322
322
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 )
324
324
325
325
if stripArch or 'ARCHFLAGS' in os .environ :
326
326
while True :
@@ -338,23 +338,34 @@ def compiler_fixup(compiler_so, cc_args):
338
338
339
339
if stripSysroot :
340
340
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' :
343
346
# Strip this argument and the next one:
344
347
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 ]
347
351
348
352
# Check if the SDK that is used during compilation actually exists,
349
353
# the universal build requires the usage of a universal SDK and not all
350
354
# users have that installed by default.
351
355
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
358
369
359
370
if sysroot and not os .path .isdir (sysroot ):
360
371
from distutils import log
0 commit comments