aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Schwartz <eschwartz@archlinux.org>2021-11-22 17:45:38 -0500
committerEli Schwartz <eschwartz@archlinux.org>2022-01-20 23:50:04 -0500
commit2a992526045b702a8ab72968c98fef9f9e189d2b (patch)
treee9b6942f9b4c7ecc7c42a40dc34a73f0621688a6
parentacef5a97624c04b91b4bdbd2c3cf070c8d048b72 (diff)
downloadmeson-2a992526045b702a8ab72968c98fef9f9e189d2b.zip
meson-2a992526045b702a8ab72968c98fef9f9e189d2b.tar.gz
meson-2a992526045b702a8ab72968c98fef9f9e189d2b.tar.bz2
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.
-rw-r--r--mesonbuild/modules/python.py29
1 files changed, 21 insertions, 8 deletions
diff --git a/mesonbuild/modules/python.py b/mesonbuild/modules/python.py
index 90335a1..2b62ea3 100644
--- a/mesonbuild/modules/python.py
+++ b/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))