dependencies: Don't Repeat Yourself when it comes to lookup methods

We need to extend the candidates the same way per method, but we handle
each method twice: once in explicit method checks, and once for auto. We
can just handle auto as a special list of methods, though.
pull/11907/head
Eli Schwartz 2 years ago
parent 216f7476de
commit c780d240e2
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
  1. 41
      mesonbuild/dependencies/detect.py

@ -192,37 +192,30 @@ def _build_external_dependency_list(name: str, env: 'Environment', for_machine:
candidates: T.List['DependencyGenerator'] = []
# If it's explicitly requested, use the dub detection method (only)
if 'dub' == kwargs.get('method', ''):
candidates.append(functools.partial(DubDependency, name, env, kwargs))
return candidates
# If it's explicitly requested, use the pkgconfig detection method (only)
if 'pkg-config' == kwargs.get('method', ''):
candidates.append(functools.partial(PkgConfigDependency, name, env, kwargs))
return candidates
# If it's explicitly requested, use the CMake detection method (only)
if 'cmake' == kwargs.get('method', ''):
candidates.append(functools.partial(CMakeDependency, name, env, kwargs))
return candidates
if kwargs.get('method', 'auto') == 'auto':
# Just use the standard detection methods.
methods = ['pkg-config', 'extraframework', 'cmake']
else:
# If it's explicitly requested, use that detection method (only).
methods = [kwargs['method']]
# If it's explicitly requested, use the Extraframework detection method (only)
if 'extraframework' == kwargs.get('method', ''):
# On OSX, also try framework dependency detector
if env.machines[for_machine].is_darwin():
candidates.append(functools.partial(ExtraFrameworkDependency, name, env, kwargs))
return candidates
# Exclusive to when it is explicitly requested
if 'dub' in methods:
candidates.append(functools.partial(DubDependency, name, env, kwargs))
# Otherwise, just use the pkgconfig and cmake dependency detector
if 'auto' == kwargs.get('method', 'auto'):
# Preferred first candidate for auto.
if 'pkg-config' in methods:
candidates.append(functools.partial(PkgConfigDependency, name, env, kwargs))
# On OSX, also try framework dependency detector
# On OSX only, try framework dependency detector.
if 'extraframework' in methods:
if env.machines[for_machine].is_darwin():
candidates.append(functools.partial(ExtraFrameworkDependency, name, env, kwargs))
# Only use CMake as a last resort, since it might not work 100% (see #6113)
# Only use CMake:
# - if it's explicitly requested
# - as a last resort, since it might not work 100% (see #6113)
if 'cmake' in methods:
candidates.append(functools.partial(CMakeDependency, name, env, kwargs))
return candidates

Loading…
Cancel
Save