8000 bpo-38360: macOS: support alternate form of -isysroot flag by jmroot · Pull Request #16480 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-38360: macOS: support alternate form of -isysroot flag #16480

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
8000 Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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.
  • Loading branch information
jmroot committed Nov 8, 2019
commit c76b8a26d64e757da813805b9858ebdcbda2c124
39 changes: 25 additions & 14 deletions Lib/_osx_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def _remove_universal_flags(_config_vars):
if cv in _config_vars and cv not in os.environ:
flags = _config_vars[cv]
flags = re.sub(r'-arch\s+\w+\s', ' ', flags, flags=re.ASCII)
flags = re.sub('-isysroot [^ \t]*', ' ', flags)
flags = re.sub(r'-isysroot\s*\S+', ' ', flags)
_save_modified_value(_config_vars, cv, flags)

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

return _config_vars
Expand All @@ -320,7 +320,7 @@ def compiler_fixup(compiler_so, cc_args):
stripArch = stripSysroot = True
else:
stripArch = '-arch' in cc_args
stripSysroot = '-isysroot' in cc_args
stripSysroot = any(arg for arg in cc_args if arg.find('-isysroot') == 0)

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

if stripSysroot:
while True:
try:
index = compiler_so.index('-isysroot')
indices = [i for i,x in enumerate(compiler_so) if x.find('-isysroot') == 0]
if not indices:
break
index = indices[0]
if compiler_so[index] == '-isysroot':
# Strip this argument and the next one:
del compiler_so[index:index+2]
except ValueError:
break
else:
# It's '-isysroot/some/path' in one arg
del compiler_so[index:index+1]

# Check if the SDK that is used during compilation actually exists,
# the universal build requires the usage of a universal SDK and not all
# users have that installed by default.
sysroot = None
if '-isysroot' in cc_args:
idx = cc_args.index('-isysroot')
sysroot = cc_args[idx+1]
elif '-isysroot' in compiler_so:
idx = compiler_so.index('-isysroot')
sysroot = compiler_so[idx+1]
argvar = cc_args
indices = [i for i,x in enumerate(cc_args) if x.find('-isysroot') == 0]
if not indices:
argvar = compiler_so
indices = [i for i,x in enumerate(compiler_so) if x.find('-isysroot') == 0]

for idx in indices:
if argvar[idx] == '-isysroot':
sysroot = argvar[idx+1]
break
else:
sysroot = argvar[idx][len('-isysroot'):]
break

if sysroot and not os.path.isdir(sysroot):
from distutils import log
Expand Down
2 changes: 1 addition & 1 deletion Lib/distutils/unixccompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def find_library_file(self, dirs, lib, debug=0):
# vs
# /usr/lib/libedit.dylib
cflags = sysconfig.get_config_var('CFLAGS')
m = re.search(r'-isysroot\s+(\S+)', cflags)
m = re.search(r'-isysroot\s*(\S+)', cflags)
if m is None:
sysroot = '/'
else:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def macosx_sdk_root():
return MACOS_SDK_ROOT

cflags = sysconfig.get_config_var('CFLAGS')
m = re.search(r'-isysroot\s+(\S+)', cflags)
m = re.search(r'-isysroot\s*(\S+)', cflags)
if m is not None:
MACOS_SDK_ROOT = m.group(1)
else:
Expand Down
0