diff options
author | Eli Schwartz <eschwartz@archlinux.org> | 2023-01-17 16:58:50 -0500 |
---|---|---|
committer | Eli Schwartz <eschwartz@archlinux.org> | 2023-06-26 13:10:32 -0400 |
commit | c780d240e2f0a557eab0459a63e6936ff37615d1 (patch) | |
tree | 2b3cdddb9c7313741cbb60ca3bbc3d700638ad54 | |
parent | 216f7476de668a3af0f7884e014d117cd16a3eb0 (diff) | |
download | meson-c780d240e2f0a557eab0459a63e6936ff37615d1.zip meson-c780d240e2f0a557eab0459a63e6936ff37615d1.tar.gz meson-c780d240e2f0a557eab0459a63e6936ff37615d1.tar.bz2 |
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.
-rw-r--r-- | mesonbuild/dependencies/detect.py | 41 |
1 files changed, 17 insertions, 24 deletions
diff --git a/mesonbuild/dependencies/detect.py b/mesonbuild/dependencies/detect.py index b5c9251..dea70a2 100644 --- a/mesonbuild/dependencies/detect.py +++ b/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 |