@@ -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
0 commit comments