diff --git a/mesonbuild/dependencies/detect.py b/mesonbuild/dependencies/detect.py index 4c7a47734..b5c925153 100644 --- a/mesonbuild/dependencies/detect.py +++ b/mesonbuild/dependencies/detect.py @@ -80,7 +80,7 @@ display_name_map = { 'wxwidgets': 'WxWidgets', } -def find_external_dependency(name: str, env: 'Environment', kwargs: T.Dict[str, object]) -> T.Union['ExternalDependency', NotFoundDependency]: +def find_external_dependency(name: str, env: 'Environment', kwargs: T.Dict[str, object], candidates: T.Optional[T.List['DependencyGenerator']] = None) -> T.Union['ExternalDependency', NotFoundDependency]: assert name required = kwargs.get('required', True) if not isinstance(required, bool): @@ -101,7 +101,8 @@ def find_external_dependency(name: str, env: 'Environment', kwargs: T.Dict[str, type_text = PerMachine('Build-time', 'Run-time')[for_machine] + ' dependency' # build a list of dependency methods to try - candidates = _build_external_dependency_list(name, env, for_machine, kwargs) + if candidates is None: + candidates = _build_external_dependency_list(name, env, for_machine, kwargs) pkg_exc: T.List[DependencyException] = [] pkgdep: T.List[ExternalDependency] = [] diff --git a/mesonbuild/modules/python.py b/mesonbuild/modules/python.py index 8588c4cbb..ac74e13dc 100644 --- a/mesonbuild/modules/python.py +++ b/mesonbuild/modules/python.py @@ -22,7 +22,7 @@ from .. import mlog from ..coredata import UserFeatureOption from ..build import known_shmod_kwargs from ..dependencies import NotFoundDependency -from ..dependencies.detect import get_dep_identifier +from ..dependencies.detect import get_dep_identifier, find_external_dependency from ..dependencies.python import BasicPythonExternalProgram, python_factory, _PythonDependencyBase from ..interpreter import ExternalProgramHolder, extract_required_kwarg, permitted_dependency_kwargs from ..interpreter import primitives as P_OBJ @@ -185,12 +185,8 @@ class PythonInstallation(ExternalProgramHolder): new_kwargs = kwargs.copy() new_kwargs['required'] = False - # it's theoretically (though not practically) possible to not bind dep, let's ensure it is. - dep: Dependency = NotFoundDependency('python', self.interpreter.environment) - for d in python_factory(self.interpreter.environment, for_machine, new_kwargs, self.held_object): - dep = d() - if dep.found(): - break + candidates = python_factory(self.interpreter.environment, for_machine, new_kwargs, self.held_object) + dep = find_external_dependency('python', self.interpreter.environment, new_kwargs, candidates) self.interpreter.coredata.deps[for_machine].put(identifier, dep) return dep