diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2020-05-08 14:00:38 -0700 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2020-06-12 11:16:24 -0700 |
commit | 85be45ea1169c6383a252c5c2235b024c50a9672 (patch) | |
tree | f9c4b6fb7ce098e562ad0860bc6f8a6561915798 | |
parent | 365b667dc545923718a7fbf22ff29c15877eb67b (diff) | |
download | meson-85be45ea1169c6383a252c5c2235b024c50a9672.zip meson-85be45ea1169c6383a252c5c2235b024c50a9672.tar.gz meson-85be45ea1169c6383a252c5c2235b024c50a9672.tar.bz2 |
dependencies: Split search_tool out of ExternalDependency
it really doesn't make sense to put this in the ExternalDependency
class. It doesn't rely on any of the state of that class, and it's
generically useful inside meson.
-rw-r--r-- | mesonbuild/dependencies/base.py | 46 | ||||
-rw-r--r-- | mesonbuild/dependencies/ui.py | 7 |
2 files changed, 29 insertions, 24 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) diff --git a/mesonbuild/dependencies/ui.py b/mesonbuild/dependencies/ui.py index 4b3d634..3bba3dc 100644 --- a/mesonbuild/dependencies/ui.py +++ b/mesonbuild/dependencies/ui.py @@ -31,9 +31,11 @@ from .base import DependencyException, DependencyMethods from .base import ExternalDependency, NonExistingExternalProgram from .base import ExtraFrameworkDependency, PkgConfigDependency from .base import ConfigToolDependency, DependencyFactory +from .base import find_external_program if T.TYPE_CHECKING: from ..environment import Environment + from .base import ExternalProgram class GLDependencySystem(ExternalDependency): @@ -324,10 +326,9 @@ class QtBaseDependency(ExternalDependency): if prefix: self.bindir = os.path.join(prefix, 'bin') - def search_qmake(self): + def search_qmake(self) -> T.Generator['ExternalProgram', None, None]: for qmake in ('qmake-' + self.name, 'qmake'): - for potential_qmake in self.search_tool(qmake, 'QMake', [qmake]): - yield potential_qmake + yield from find_external_program(self.env, self.for_machine, qmake, 'QMake', [qmake]) def _qmake_detect(self, mods, kwargs): for qmake in self.search_qmake(): |