Skip to content

Commit

Permalink
python module: fix broken non-embed dependency
Browse files Browse the repository at this point in the history
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 mesonbuild#11097
  • Loading branch information
eli-schwartz committed Nov 24, 2022
1 parent 0404ad5 commit b773734
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions mesonbuild/modules/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,17 @@ def __init__(self, name: str, environment: 'Environment',
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):

Expand Down Expand Up @@ -521,17 +532,8 @@ def extension_module_method(self, args: T.List['TYPE_var'], kwargs: 'TYPE_kwargs

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():
Expand Down

0 comments on commit b773734

Please sign in to comment.