python module: only find a pkg-config dependency from the found python

If the found python returns None from sysconfig.get_config_var('LIBPC')
then we cannot (and don't) set PKG_CONFIG_LIBDIR from it. In fact, we
can virtually guarantee we won't find a PkgConfigDependency either,
because any python that doesn't have a LIBPC is presumably not installed
to the system pkg-config directory (maybe it's an isolated relocatable
install, maybe it just doesn't have pkg-config support for who knows
what reason).

Trying to find one anyway using pkg-config's builtin search paths can
unexpectedly succeed, though, by finding a completely unrelated python
installation installed to a system location, which isn't the one we are
actually building for.

Instead, return early so that we use the system dependency class
fallback.

While we are at it, add back the debug messages from #3989 which got
removed.
pull/9613/head
Eli Schwartz 3 years ago
parent acef5a9762
commit 2a99252604
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
  1. 29
      mesonbuild/modules/python.py

@ -79,10 +79,19 @@ class _PythonDependencyBase(_Base):
class PythonPkgConfigDependency(PkgConfigDependency, _PythonDependencyBase):
def __init__(self, name: str, environment: 'Environment',
kwargs: T.Dict[str, T.Any], installation: 'PythonInstallation'):
kwargs: T.Dict[str, T.Any], installation: 'PythonInstallation',
libpc: bool = False):
if libpc:
mlog.debug(f'Searching for {name!r} via pkgconfig lookup in LIBPC')
else:
mlog.debug(f'Searching for {name!r} via fallback pkgconfig lookup in default paths')
PkgConfigDependency.__init__(self, name, environment, kwargs)
_PythonDependencyBase.__init__(self, installation, kwargs.get('embed', False))
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')
class PythonFrameworkDependency(ExtraFrameworkDependency, _PythonDependencyBase):
@ -240,12 +249,15 @@ def python_factory(env: 'Environment', for_machine: 'MachineChoice',
# If python-X.Y.pc exists in LIBPC, we will try to use it
def wrap_in_pythons_pc_dir(name: str, env: 'Environment', kwargs: T.Dict[str, T.Any],
installation: 'PythonInstallation') -> 'ExternalDependency':
if not pkg_libdir:
# there is no LIBPC, so we can't search in it
return NotFoundDependency('python', env)
old_pkg_libdir = os.environ.pop('PKG_CONFIG_LIBDIR', None)
old_pkg_path = os.environ.pop('PKG_CONFIG_PATH', None)
if pkg_libdir:
os.environ['PKG_CONFIG_LIBDIR'] = pkg_libdir
os.environ['PKG_CONFIG_LIBDIR'] = pkg_libdir
try:
return PythonPkgConfigDependency(name, env, kwargs, installation)
return PythonPkgConfigDependency(name, env, kwargs, installation, True)
finally:
def set_env(name, value):
if value is not None:
@ -255,10 +267,11 @@ def python_factory(env: 'Environment', for_machine: 'MachineChoice',
set_env('PKG_CONFIG_LIBDIR', old_pkg_libdir)
set_env('PKG_CONFIG_PATH', old_pkg_path)
candidates.extend([
functools.partial(wrap_in_pythons_pc_dir, pkg_name, env, kwargs, installation),
functools.partial(PythonPkgConfigDependency, pkg_name, env, kwargs, installation)
])
candidates.append(functools.partial(wrap_in_pythons_pc_dir, pkg_name, env, kwargs, installation))
# We only need to check both, if a python install has a LIBPC. It might point to the wrong location,
# e.g. relocated / cross compilation, but the presence of LIBPC indicates we should definitely look for something.
if pkg_libdir is not None:
candidates.append(functools.partial(PythonPkgConfigDependency, pkg_name, env, kwargs, installation))
if DependencyMethods.SYSTEM in methods:
candidates.append(functools.partial(PythonSystemDependency, 'python', env, kwargs, installation))

Loading…
Cancel
Save