diff options
Diffstat (limited to 'mesonbuild/dependencies/base.py')
-rw-r--r-- | mesonbuild/dependencies/base.py | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py index 956ca39..a7b23f6 100644 --- a/mesonbuild/dependencies/base.py +++ b/mesonbuild/dependencies/base.py @@ -77,6 +77,27 @@ class DependencyMethods(Enum): DUB = 'dub' +def find_external_program(env: Environment, for_machine: MachineChoice, name: str, + display_name: str, default_names: T.List[str]) -> T.Generator['ExternalProgram', None, None]: + """Find an external program, chcking the cross file plus any default options.""" + # Lookup in cross or machine file. + potential_path = env.lookup_binary_entry(for_machine, name) + if potential_path is not None: + mlog.debug('{} binary for {} specified from cross file, native file, ' + 'or env var as {}'.format(display_name, for_machine, potential_path)) + yield ExternalProgram.from_entry(name, potential_path) + # We never fallback if the user-specified option is no good, so + # stop returning options. + return + mlog.debug('{} binary missing from cross or native file, or env var undefined.'.format(display_name)) + # Fallback on hard-coded defaults. + # TODO prefix this for the cross case instead of ignoring thing. + if env.machines.matches_build_machine(for_machine): + for potential_path in default_names: + mlog.debug('Trying a default {} fallback at'.format(display_name), potential_path) + yield ExternalProgram(potential_path, silent=True) + + class Dependency: @classmethod @@ -353,25 +374,6 @@ class ExternalDependency(Dependency, HasNativeKwarg): raise DependencyException(m.format(self.name, not_found, self.version)) return - # Create an iterator of options - def search_tool(self, name, display_name, default_names): - # Lookup in cross or machine file. - potential_path = self.env.lookup_binary_entry(self.for_machine, name) - if potential_path is not None: - mlog.debug('{} binary for {} specified from cross file, native file, ' - 'or env var as {}'.format(display_name, self.for_machine, potential_path)) - yield ExternalProgram.from_entry(name, potential_path) - # We never fallback if the user-specified option is no good, so - # stop returning options. - return - mlog.debug('{} binary missing from cross or native file, or env var undefined.'.format(display_name)) - # Fallback on hard-coded defaults. - # TODO prefix this for the cross case instead of ignoring thing. - if self.env.machines.matches_build_machine(self.for_machine): - for potential_path in default_names: - mlog.debug('Trying a default {} fallback at'.format(display_name), potential_path) - yield ExternalProgram(potential_path, silent=True) - class NotFoundDependency(Dependency): def __init__(self, environment): @@ -437,7 +439,9 @@ class ConfigToolDependency(ExternalDependency): if not isinstance(versions, list) and versions is not None: versions = listify(versions) best_match = (None, None) - for potential_bin in self.search_tool(self.tool_name, self.tool_name, self.tools): + for potential_bin in find_external_program( + self.env, self.for_machine, self.tool_name, + self.tool_name, self.tools): if not potential_bin.found(): continue tool = potential_bin.get_command() @@ -561,7 +565,7 @@ class PkgConfigDependency(ExternalDependency): else: assert PkgConfigDependency.class_pkgbin[self.for_machine] is None mlog.debug('Pkg-config binary for %s is not cached.' % self.for_machine) - for potential_pkgbin in self.search_tool('pkgconfig', 'Pkg-config', environment.default_pkgconfig): + for potential_pkgbin in find_external_program(self.env, self.for_machine, 'pkgconfig', 'Pkg-config', environment.default_pkgconfig): mlog.debug('Trying pkg-config binary {} for machine {} at {}' .format(potential_pkgbin.name, self.for_machine, potential_pkgbin.command)) version_if_ok = self.check_pkgconfig(potential_pkgbin) |