From c780d240e2f0a557eab0459a63e6936ff37615d1 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Tue, 17 Jan 2023 16:58:50 -0500 Subject: 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. --- mesonbuild/dependencies/detect.py | 41 ++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 24 deletions(-) (limited to 'mesonbuild') 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 -- cgit v1.1