From 33e5e772253d2a8ad3836760a96ac7baf4d73d17 Mon Sep 17 00:00:00 2001 From: Dom Heinzeller Date: Fri, 4 Nov 2022 12:52:27 -0600 Subject: 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". --- var/spack/repos/builtin/packages/python/package.py | 25 ++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'var') diff --git a/var/spack/repos/builtin/packages/python/package.py b/var/spack/repos/builtin/packages/python/package.py index 8a69efbbda..3fea87a2ec 100644 --- a/var/spack/repos/builtin/packages/python/package.py +++ b/var/spack/repos/builtin/packages/python/package.py @@ -1250,12 +1250,29 @@ config.update(get_paths()) # 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), ] -- cgit v1.2.3-60-g2f50