Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions mesonbuild/dependencies/pkgconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions run_project_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
Loading