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.
pull/7314/head
Dylan Baker 5 years ago
parent 365b667dc5
commit 85be45ea11
  1. 46
      mesonbuild/dependencies/base.py
  2. 7
      mesonbuild/dependencies/ui.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)

@ -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():

Loading…
Cancel
Save