From bf832743441a1171518d7a436164c989be679410 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Wed, 23 Nov 2022 15:46:51 -0500 Subject: [PATCH] python module: fix broken non-embed dependency The `py.dependency(embed: false)` method is supposed to consistently provide a distutils-like `python.pc` / `python-embed.pc` interface regardless of Python version. It handles both pkg-config and sysconfig scraping. For the latter, we respect the value of self.link_libpython as determined by distutils, and construct a fully custom dependency. For the former, we blindly assume pkg-config is correct. It isn't correct, not until Python 3.8 when embed was added. Before then, we need to process the pkg-config dependency based on link_libpython. We did this, but only inside the extension_module method, which is obviously wrong. Delete the special casing from extension_module, and handle it inside the dependency. Fixes #11097 --- mesonbuild/modules/python.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/mesonbuild/modules/python.py b/mesonbuild/modules/python.py index 98808c4f5..71a25d594 100644 --- a/mesonbuild/modules/python.py +++ b/mesonbuild/modules/python.py @@ -121,6 +121,17 @@ class PythonPkgConfigDependency(PkgConfigDependency, _PythonDependencyBase): if libpc and not self.is_found: mlog.debug(f'"python-{self.version}" could not be found in LIBPC, this is likely due to a relocated python installation') + # The "-embed" version of python.pc was introduced in 3.8, and distutils + # extension linking was changed to be considered a non embed usage. Before + # then, this dependency always uses the embed=True file because that is the + # only one that exists, + # + # On macOS and some Linux distros (Debian) distutils doesn't link extensions + # against libpython, even on 3.7 and below. We call into distutils and + # mirror its behavior. See https://github.com/mesonbuild/meson/issues/4117 + if not self.embed and not self.link_libpython and mesonlib.version_compare(self.version, '< 3.8'): + self.link_args = [] + class PythonFrameworkDependency(ExtraFrameworkDependency, _PythonDependencyBase): @@ -529,17 +540,8 @@ class PythonInstallation(ExternalProgramHolder): kwargs['install_dir'] = self._get_install_dir_impl(False, subdir) - new_deps = [] - has_pydep = False - for dep in mesonlib.extract_as_list(kwargs, 'dependencies'): - if isinstance(dep, _PythonDependencyBase): - has_pydep = True - # On macOS and some Linux distros (Debian) distutils doesn't link - # extensions against libpython. We call into distutils and mirror its - # behavior. See https://github.com/mesonbuild/meson/issues/4117 - if not self.link_libpython: - dep = dep.get_partial_dependency(compile_args=True) - new_deps.append(dep) + new_deps = mesonlib.extract_as_list(kwargs, 'dependencies') + has_pydep = any(isinstance(dep, _PythonDependencyBase) for dep in new_deps) if not has_pydep: pydep = self._dependency_method_impl({}) if not pydep.found():