dependencies/base: Split process_method_kw out of Dependency

I want to use this in a new class as well, that doesn't descend from
Dependency.
pull/6540/head
Dylan Baker 5 years ago
parent d0c7b51693
commit f85d6cee6a
  1. 67
      mesonbuild/dependencies/base.py
  2. 8
      mesonbuild/dependencies/dev.py
  3. 16
      mesonbuild/dependencies/misc.py
  4. 8
      mesonbuild/dependencies/ui.py

@ -70,38 +70,6 @@ class DependencyMethods(Enum):
class Dependency:
@classmethod
def _process_method_kw(cls, kwargs):
method = kwargs.get('method', 'auto')
if isinstance(method, DependencyMethods):
return method
if method not in [e.value for e in DependencyMethods]:
raise DependencyException('method {!r} is invalid'.format(method))
method = DependencyMethods(method)
# This sets per-tool config methods which are deprecated to to the new
# generic CONFIG_TOOL value.
if method in [DependencyMethods.SDLCONFIG, DependencyMethods.CUPSCONFIG,
DependencyMethods.PCAPCONFIG, DependencyMethods.LIBWMFCONFIG]:
mlog.warning(textwrap.dedent("""\
Configuration method {} has been deprecated in favor of
'config-tool'. This will be removed in a future version of
meson.""".format(method)))
method = DependencyMethods.CONFIG_TOOL
# Set the detection method. If the method is set to auto, use any available method.
# If method is set to a specific string, allow only that detection method.
if method == DependencyMethods.AUTO:
methods = cls.get_methods()
elif method in cls.get_methods():
methods = [method]
else:
raise DependencyException(
'Unsupported detection method: {}, allowed methods are {}'.format(
method.value,
mlog.format_list([x.value for x in [DependencyMethods.AUTO] + cls.get_methods()])))
return methods
@classmethod
def _process_include_type_kw(cls, kwargs) -> str:
@ -125,7 +93,7 @@ class Dependency:
# If None, self.link_args will be used
self.raw_link_args = None
self.sources = []
self.methods = self._process_method_kw(kwargs)
self.methods = process_method_kw(self.get_methods(), kwargs)
self.include_type = self._process_include_type_kw(kwargs)
self.ext_deps = [] # type: T.List[Dependency]
@ -2405,3 +2373,36 @@ def strip_system_libdirs(environment, for_machine: MachineChoice, link_args):
"""
exclude = {'-L{}'.format(p) for p in environment.get_compiler_system_dirs(for_machine)}
return [l for l in link_args if l not in exclude]
def process_method_kw(possible: T.List[DependencyMethods], kwargs) -> T.List[DependencyMethods]:
method = kwargs.get('method', 'auto')
if isinstance(method, DependencyMethods):
return method
if method not in [e.value for e in DependencyMethods]:
raise DependencyException('method {!r} is invalid'.format(method))
method = DependencyMethods(method)
# This sets per-tool config methods which are deprecated to to the new
# generic CONFIG_TOOL value.
if method in [DependencyMethods.SDLCONFIG, DependencyMethods.CUPSCONFIG,
DependencyMethods.PCAPCONFIG, DependencyMethods.LIBWMFCONFIG]:
mlog.warning(textwrap.dedent("""\
Configuration method {} has been deprecated in favor of
'config-tool'. This will be removed in a future version of
meson.""".format(method)))
method = DependencyMethods.CONFIG_TOOL
# Set the detection method. If the method is set to auto, use any available method.
# If method is set to a specific string, allow only that detection method.
if method == DependencyMethods.AUTO:
methods = possible
elif method in possible:
methods = [method]
else:
raise DependencyException(
'Unsupported detection method: {}, allowed methods are {}'.format(
method.value,
mlog.format_list([x.value for x in [DependencyMethods.AUTO] + possible])))
return methods

@ -25,7 +25,7 @@ from ..mesonlib import version_compare, stringlistify, extract_as_list, MachineC
from ..environment import get_llvm_tool_names
from .base import (
DependencyException, DependencyMethods, ExternalDependency, PkgConfigDependency,
strip_system_libdirs, ConfigToolDependency, CMakeDependency
strip_system_libdirs, ConfigToolDependency, CMakeDependency, process_method_kw
)
from .misc import ThreadDependency
@ -100,7 +100,7 @@ class GTestDependency(ExternalDependency):
@classmethod
def _factory(cls, environment, kwargs):
methods = cls._process_method_kw(kwargs)
methods = process_method_kw(cls.get_methods(), kwargs)
candidates = []
if DependencyMethods.PKGCONFIG in methods:
@ -179,7 +179,7 @@ class GMockDependency(ExternalDependency):
@classmethod
def _factory(cls, environment, kwargs):
methods = cls._process_method_kw(kwargs)
methods = process_method_kw(cls.get_methods(), kwargs)
candidates = []
if DependencyMethods.PKGCONFIG in methods:
@ -439,7 +439,7 @@ class LLVMDependency(ExternalDependency):
@classmethod
def _factory(cls, env, kwargs):
methods = cls._process_method_kw(kwargs)
methods = process_method_kw(cls.get_methods(), kwargs)
candidates = []
if DependencyMethods.CONFIG_TOOL in methods:

@ -27,7 +27,7 @@ from ..mesonlib import listify
from .base import (
DependencyException, DependencyMethods, ExternalDependency,
ExtraFrameworkDependency, PkgConfigDependency,
CMakeDependency, ConfigToolDependency,
CMakeDependency, ConfigToolDependency, process_method_kw,
)
@ -205,7 +205,7 @@ class Python3Dependency(ExternalDependency):
@classmethod
def _factory(cls, environment, kwargs):
methods = cls._process_method_kw(kwargs)
methods = process_method_kw(cls.get_methods(), kwargs)
candidates = []
if DependencyMethods.PKGCONFIG in methods:
@ -329,7 +329,7 @@ class PcapDependency(ExternalDependency):
@classmethod
def _factory(cls, environment, kwargs):
methods = cls._process_method_kw(kwargs)
methods = process_method_kw(cls.get_methods(), kwargs)
candidates = []
if DependencyMethods.PKGCONFIG in methods:
@ -374,7 +374,7 @@ class CupsDependency(ExternalDependency):
@classmethod
def _factory(cls, environment, kwargs):
methods = cls._process_method_kw(kwargs)
methods = process_method_kw(cls.get_methods(), kwargs)
candidates = []
if DependencyMethods.PKGCONFIG in methods:
@ -416,7 +416,7 @@ class LibWmfDependency(ExternalDependency):
@classmethod
def _factory(cls, environment, kwargs):
methods = cls._process_method_kw(kwargs)
methods = process_method_kw(cls.get_methods(), kwargs)
candidates = []
if DependencyMethods.PKGCONFIG in methods:
@ -444,7 +444,7 @@ class LibGCryptDependency(ExternalDependency):
@classmethod
def _factory(cls, environment, kwargs):
methods = cls._process_method_kw(kwargs)
methods = process_method_kw(cls.get_methods(), kwargs)
candidates = []
if DependencyMethods.PKGCONFIG in methods:
@ -475,7 +475,7 @@ class GpgmeDependency(ExternalDependency):
@classmethod
def _factory(cls, environment, kwargs):
methods = cls._process_method_kw(kwargs)
methods = process_method_kw(cls.get_methods(), kwargs)
candidates = []
if DependencyMethods.PKGCONFIG in methods:
@ -530,7 +530,7 @@ class ShadercDependency(ExternalDependency):
@classmethod
def _factory(cls, environment, kwargs):
methods = cls._process_method_kw(kwargs)
methods = process_method_kw(cls.get_methods(), kwargs)
candidates = []
if DependencyMethods.PKGCONFIG in methods:

@ -30,7 +30,7 @@ from ..environment import detect_cpu_family
from .base import DependencyException, DependencyMethods
from .base import ExternalDependency, ExternalProgram, NonExistingExternalProgram
from .base import ExtraFrameworkDependency, PkgConfigDependency
from .base import ConfigToolDependency
from .base import ConfigToolDependency, process_method_kw
class GLDependency(ExternalDependency):
@ -52,7 +52,7 @@ class GLDependency(ExternalDependency):
@classmethod
def _factory(cls, environment, kwargs):
methods = cls._process_method_kw(kwargs)
methods = process_method_kw(cls.get_methods(), kwargs)
candidates = []
if DependencyMethods.PKGCONFIG in methods:
@ -532,7 +532,7 @@ class SDL2Dependency(ExternalDependency):
@classmethod
def _factory(cls, environment, kwargs):
methods = cls._process_method_kw(kwargs)
methods = process_method_kw(cls.get_methods(), kwargs)
candidates = []
if DependencyMethods.PKGCONFIG in methods:
@ -648,7 +648,7 @@ class VulkanDependency(ExternalDependency):
@classmethod
def _factory(cls, environment, kwargs):
methods = cls._process_method_kw(kwargs)
methods = process_method_kw(cls.get_methods(), kwargs)
candidates = []
if DependencyMethods.PKGCONFIG in methods:

Loading…
Cancel
Save