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
pull/11104/head
Eli Schwartz 2 years ago
parent c05b2ba231
commit bf83274344
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
  1. 24
      mesonbuild/modules/python.py

@ -121,6 +121,17 @@ class PythonPkgConfigDependency(PkgConfigDependency, _PythonDependencyBase):
if libpc and not self.is_found: 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') 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): class PythonFrameworkDependency(ExtraFrameworkDependency, _PythonDependencyBase):
@ -529,17 +540,8 @@ class PythonInstallation(ExternalProgramHolder):
kwargs['install_dir'] = self._get_install_dir_impl(False, subdir) kwargs['install_dir'] = self._get_install_dir_impl(False, subdir)
new_deps = [] new_deps = mesonlib.extract_as_list(kwargs, 'dependencies')
has_pydep = False has_pydep = any(isinstance(dep, _PythonDependencyBase) for dep in new_deps)
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)
if not has_pydep: if not has_pydep:
pydep = self._dependency_method_impl({}) pydep = self._dependency_method_impl({})
if not pydep.found(): if not pydep.found():

Loading…
Cancel
Save