Skip to content

Commit 5f3d12a

Browse files
mgornydcbaker
authored andcommitted
pkgconfig: Fix class cached to be keyed on extra_paths
Add `extra_paths` to cache keys for `PkgConfigInterface` and `PkgConfigCLI` instances, to avoid incorrectly reusing an instance with a different `extra_paths` value, see: #14657 (comment) Signed-off-by: Michał Górny <[email protected]>
1 parent 8bba5d0 commit 5f3d12a

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

mesonbuild/dependencies/pkgconfig.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@
2929
class PkgConfigInterface:
3030
'''Base class wrapping a pkg-config implementation'''
3131

32-
class_impl: PerMachine[T.Union[Literal[False], T.Optional[PkgConfigInterface]]] = PerMachine(False, False)
33-
class_cli_impl: PerMachine[T.Union[Literal[False], T.Optional[PkgConfigCLI]]] = PerMachine(False, False)
32+
# keyed on machine and extra_paths
33+
class_impl: PerMachine[T.Dict[T.Optional[T.Tuple[str, ...]], T.Union[Literal[False], T.Optional[PkgConfigInterface]]]] = PerMachine({}, {})
34+
class_cli_impl: PerMachine[T.Dict[T.Optional[T.Tuple[str, ...]], T.Union[Literal[False], T.Optional[PkgConfigCLI]]]] = PerMachine({}, {})
3435
pkg_bin_per_machine: PerMachine[T.Optional[ExternalProgram]] = PerMachine(None, None)
3536

3637
@staticmethod
@@ -45,14 +46,15 @@ def instance(env: Environment, for_machine: MachineChoice, silent: bool,
4546
extra_paths: T.Optional[T.List[str]] = None) -> T.Optional[PkgConfigInterface]:
4647
'''Return a pkg-config implementation singleton'''
4748
for_machine = for_machine if env.is_cross_build() else MachineChoice.HOST
48-
impl = PkgConfigInterface.class_impl[for_machine]
49+
extra_paths_key = tuple(extra_paths) if extra_paths is not None else None
50+
impl = PkgConfigInterface.class_impl[for_machine].get(extra_paths_key, False)
4951
if impl is False:
5052
impl = PkgConfigCLI(env, for_machine, silent, PkgConfigInterface.pkg_bin_per_machine[for_machine], extra_paths)
5153
if not impl.found():
5254
impl = None
5355
if not impl and not silent:
5456
mlog.log('Found pkg-config:', mlog.red('NO'))
55-
PkgConfigInterface.class_impl[for_machine] = impl
57+
PkgConfigInterface.class_impl[for_machine][extra_paths_key] = impl
5658
return impl
5759

5860
@staticmethod
@@ -67,12 +69,13 @@ def _cli(env: Environment, for_machine: MachineChoice,
6769
impl: T.Union[Literal[False], T.Optional[PkgConfigInterface]] # Help confused mypy
6870
impl = PkgConfigInterface.instance(env, for_machine, silent)
6971
if impl and not isinstance(impl, PkgConfigCLI):
70-
impl = PkgConfigInterface.class_cli_impl[for_machine]
72+
extra_paths_key = tuple(extra_paths) if extra_paths is not None else None
73+
impl = PkgConfigInterface.class_cli_impl[for_machine].get(extra_paths_key, False)
7174
if impl is False:
7275
impl = PkgConfigCLI(env, for_machine, silent, PkgConfigInterface.pkg_bin_per_machine[for_machine], extra_paths)
7376
if not impl.found():
7477
impl = None
75-
PkgConfigInterface.class_cli_impl[for_machine] = impl
78+
PkgConfigInterface.class_cli_impl[for_machine][extra_paths_key] = impl
7679
return T.cast('T.Optional[PkgConfigCLI]', impl) # Trust me, mypy
7780

7881
@staticmethod

run_project_tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,8 +555,8 @@ def clear_internal_caches() -> None:
555555
from mesonbuild.mesonlib import PerMachine
556556
mesonbuild.interpreterbase.FeatureNew.feature_registry = {}
557557
CMakeDependency.class_cmakeinfo = PerMachine(None, None)
558-
PkgConfigInterface.class_impl = PerMachine(False, False)
559-
PkgConfigInterface.class_cli_impl = PerMachine(False, False)
558+
PkgConfigInterface.class_impl = PerMachine({}, {})
559+
PkgConfigInterface.class_cli_impl = PerMachine({}, {})
560560
PkgConfigInterface.pkg_bin_per_machine = PerMachine(None, None)
561561

562562

run_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ def run_mtest_inprocess(commandlist: T.List[str]) -> T.Tuple[int, str]:
289289
def clear_meson_configure_class_caches() -> None:
290290
CCompiler.find_library_cache.clear()
291291
CCompiler.find_framework_cache.clear()
292-
PkgConfigInterface.class_impl.assign(False, False)
292+
PkgConfigInterface.class_impl.assign({}, {})
293293
mesonlib.project_meson_versions.clear()
294294

295295
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]:

0 commit comments

Comments
 (0)