From 7fde3f913f83a13a23012c3d153767c031a3c754 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Thu, 4 Sep 2025 15:26:33 +0200 Subject: [PATCH] pkgconfig: Fix class cached to be keyed on extra_paths MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add `extra_paths` to cache keys for `PkgConfigInterface` and `PkgConfigCLI` instances, to avoid incorrectly reusing an instance with a different `extra_paths` value, see: https://github.com/mesonbuild/meson/pull/14657#discussion_r2320623799 Signed-off-by: Michał Górny --- mesonbuild/dependencies/pkgconfig.py | 15 +++++++++------ run_project_tests.py | 4 ++-- run_tests.py | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/mesonbuild/dependencies/pkgconfig.py b/mesonbuild/dependencies/pkgconfig.py index a0727f60f11c..012b716f6905 100644 --- a/mesonbuild/dependencies/pkgconfig.py +++ b/mesonbuild/dependencies/pkgconfig.py @@ -29,8 +29,9 @@ class PkgConfigInterface: '''Base class wrapping a pkg-config implementation''' - class_impl: PerMachine[T.Union[Literal[False], T.Optional[PkgConfigInterface]]] = PerMachine(False, False) - class_cli_impl: PerMachine[T.Union[Literal[False], T.Optional[PkgConfigCLI]]] = PerMachine(False, False) + # keyed on machine and extra_paths + class_impl: PerMachine[T.Dict[T.Optional[T.Tuple[str, ...]], T.Union[Literal[False], T.Optional[PkgConfigInterface]]]] = PerMachine({}, {}) + class_cli_impl: PerMachine[T.Dict[T.Optional[T.Tuple[str, ...]], T.Union[Literal[False], T.Optional[PkgConfigCLI]]]] = PerMachine({}, {}) pkg_bin_per_machine: PerMachine[T.Optional[ExternalProgram]] = PerMachine(None, None) @staticmethod @@ -45,14 +46,15 @@ def instance(env: Environment, for_machine: MachineChoice, silent: bool, extra_paths: T.Optional[T.List[str]] = None) -> T.Optional[PkgConfigInterface]: '''Return a pkg-config implementation singleton''' for_machine = for_machine if env.is_cross_build() else MachineChoice.HOST - impl = PkgConfigInterface.class_impl[for_machine] + extra_paths_key = tuple(extra_paths) if extra_paths is not None else None + impl = PkgConfigInterface.class_impl[for_machine].get(extra_paths_key, False) if impl is False: impl = PkgConfigCLI(env, for_machine, silent, PkgConfigInterface.pkg_bin_per_machine[for_machine], extra_paths) if not impl.found(): impl = None if not impl and not silent: mlog.log('Found pkg-config:', mlog.red('NO')) - PkgConfigInterface.class_impl[for_machine] = impl + PkgConfigInterface.class_impl[for_machine][extra_paths_key] = impl return impl @staticmethod @@ -67,12 +69,13 @@ def _cli(env: Environment, for_machine: MachineChoice, impl: T.Union[Literal[False], T.Optional[PkgConfigInterface]] # Help confused mypy impl = PkgConfigInterface.instance(env, for_machine, silent) if impl and not isinstance(impl, PkgConfigCLI): - impl = PkgConfigInterface.class_cli_impl[for_machine] + extra_paths_key = tuple(extra_paths) if extra_paths is not None else None + impl = PkgConfigInterface.class_cli_impl[for_machine].get(extra_paths_key, False) if impl is False: impl = PkgConfigCLI(env, for_machine, silent, PkgConfigInterface.pkg_bin_per_machine[for_machine], extra_paths) if not impl.found(): impl = None - PkgConfigInterface.class_cli_impl[for_machine] = impl + PkgConfigInterface.class_cli_impl[for_machine][extra_paths_key] = impl return T.cast('T.Optional[PkgConfigCLI]', impl) # Trust me, mypy @staticmethod diff --git a/run_project_tests.py b/run_project_tests.py index ce6e5c2da4f8..b2442703ef82 100755 --- a/run_project_tests.py +++ b/run_project_tests.py @@ -555,8 +555,8 @@ def clear_internal_caches() -> None: from mesonbuild.mesonlib import PerMachine mesonbuild.interpreterbase.FeatureNew.feature_registry = {} CMakeDependency.class_cmakeinfo = PerMachine(None, None) - PkgConfigInterface.class_impl = PerMachine(False, False) - PkgConfigInterface.class_cli_impl = PerMachine(False, False) + PkgConfigInterface.class_impl = PerMachine({}, {}) + PkgConfigInterface.class_cli_impl = PerMachine({}, {}) PkgConfigInterface.pkg_bin_per_machine = PerMachine(None, None) diff --git a/run_tests.py b/run_tests.py index 6ca84f07f66f..ed224f8173c5 100755 --- a/run_tests.py +++ b/run_tests.py @@ -289,7 +289,7 @@ def run_mtest_inprocess(commandlist: T.List[str]) -> T.Tuple[int, str]: def clear_meson_configure_class_caches() -> None: CCompiler.find_library_cache.clear() CCompiler.find_framework_cache.clear() - PkgConfigInterface.class_impl.assign(False, False) + PkgConfigInterface.class_impl.assign({}, {}) mesonlib.project_meson_versions.clear() def run_configure_inprocess(commandlist: T.List[str], env: T.Optional[T.Dict[str, str]] = None, catch_exception: bool = False) -> T.Tuple[int, str, str]: