Python package: fix .libs on macOS with external Python (#33410)

For some instances of externally-provided Python (e.g. Homebrew),
the LDLIBRARY/LIBRARY config variables don't actually refer to
libraries and should therefore be excluded from ".libs".
This commit is contained in:
Dom Heinzeller 2022-11-04 12:52:27 -06:00 committed by GitHub
parent 13565df027
commit 33e5e77225
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1250,12 +1250,29 @@ def libs(self):
# The values of LDLIBRARY and LIBRARY aren't reliable. Intel Python uses a
# static binary but installs shared libraries, so sysconfig reports
# libpythonX.Y.a but only libpythonX.Y.so exists. So we add our own paths, too.
shared_libs = [
self.config_vars["LDLIBRARY"],
# With framework python on macOS, self.config_vars["LDLIBRARY"] can point
# to a library that is not linkable because it does not have the required
# suffix of a shared library (it is called "Python" without extention).
# The linker then falls back to libPython.tbd in the default macOS
# software tree, which security settings prohibit to link against
# (your binary is not an allowed client of /path/to/libPython.tbd).
# To avoid this, we replace the entry in config_vars with a default value.
file_extension_shared = os.path.splitext(self.config_vars["LDLIBRARY"])[-1]
if file_extension_shared == "":
shared_libs = []
else:
shared_libs = [self.config_vars["LDLIBRARY"]]
shared_libs += [
"{}python{}.{}".format(lib_prefix, py_version, dso_suffix),
]
static_libs = [
self.config_vars["LIBRARY"],
# Like LDLIBRARY for Python on Mac OS, LIBRARY may refer to an un-linkable object
file_extension_static = os.path.splitext(self.config_vars["LIBRARY"])[-1]
if file_extension_static == "":
static_libs = []
else:
static_libs = [self.config_vars["LIBRARY"]]
static_libs += [
"{}python{}.{}".format(lib_prefix, py_version, stat_suffix),
]