summaryrefslogtreecommitdiffstats
path: root/Lib/_osx_support.py
diff options
context:
space:
mode:
authorRonald Oussoren <ronaldoussoren@mac.com>2020-11-22 05:14:25 (GMT)
committerGitHub <noreply@github.com>2020-11-22 05:14:25 (GMT)
commit404a719b5127602c1a948f8e189ab61cd3f147d8 (patch)
tree3c5c46adc53527468927ef6e5cdb43e84a6d6432 /Lib/_osx_support.py
parent453bc1da2023d6cbe362637a2e0b06d0521f013c (diff)
downloadcpython-404a719b5127602c1a948f8e189ab61cd3f147d8.zip
cpython-404a719b5127602c1a948f8e189ab61cd3f147d8.tar.gz
cpython-404a719b5127602c1a948f8e189ab61cd3f147d8.tar.bz2
bpo-41116: Ensure system supplied libraries are found on macOS 11 (GH-23301)
On macOS system provided libraries are in a shared library cache and not at their usual location. This PR teaches distutils to search in the SDK, even if there was no "-sysroot" argument in the compiler flags.
Diffstat (limited to 'Lib/_osx_support.py')
-rw-r--r--Lib/_osx_support.py34
1 files changed, 32 insertions, 2 deletions
diff --git a/Lib/_osx_support.py b/Lib/_osx_support.py
index 0cbfeed..37975fe 100644
--- a/Lib/_osx_support.py
+++ b/Lib/_osx_support.py
@@ -52,7 +52,7 @@ def _find_executable(executable, path=None):
return executable
-def _read_output(commandstring):
+def _read_output(commandstring, capture_stderr=False):
"""Output from successful command execution or None"""
# Similar to os.popen(commandstring, "r").read(),
# but without actually using os.popen because that
@@ -67,7 +67,10 @@ def _read_output(commandstring):
os.getpid(),), "w+b")
with contextlib.closing(fp) as fp:
- cmd = "%s 2>/dev/null >'%s'" % (commandstring, fp.name)
+ if capture_stderr:
+ cmd = "%s >'%s' 2>&1" % (commandstring, fp.name)
+ else:
+ cmd = "%s 2>/dev/null >'%s'" % (commandstring, fp.name)
return fp.read().decode('utf-8').strip() if not os.system(cmd) else None
@@ -145,6 +148,33 @@ def _save_modified_value(_config_vars, cv, newvalue):
_config_vars[_INITPRE + cv] = oldvalue
_config_vars[cv] = newvalue
+
+_cache_default_sysroot = None
+def _default_sysroot(cc):
+ """ Returns the root of the default SDK for this system, or '/' """
+ global _cache_default_sysroot
+
+ if _cache_default_sysroot is not None:
+ return _cache_default_sysroot
+
+ contents = _read_output('%s -c -E -v - </dev/null' % (cc,), True)
+ in_incdirs = False
+ for line in contents.splitlines():
+ if line.startswith("#include <...>"):
+ in_incdirs = True
+ elif line.startswith("End of search list"):
+ in_incdirs = False
+ elif in_incdirs:
+ line = line.strip()
+ if line == '/usr/include':
+ _cache_default_sysroot = '/'
+ elif line.endswith(".sdk/usr/include"):
+ _cache_default_sysroot = line[:-12]
+ if _cache_default_sysroot is None:
+ _cache_default_sysroot = '/'
+
+ return _cache_default_sysroot
+
def _supports_universal_builds():
"""Returns True if universal builds are supported on this system"""
# As an approximation, we assume that if we are running on 10.4 or above,