aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Turney <jon.turney@dronecode.org.uk>2018-01-10 18:03:26 +0000
committerJon Turney <jon.turney@dronecode.org.uk>2018-01-15 20:28:23 +0000
commitc59ec8749661f242c6a15634cdb32fab65eda7c8 (patch)
tree23771e9392e49b09c6827b870ef393e7d0a2c05b
parent153a7fb33240dc04f459147b418f58e30d448d56 (diff)
downloadmeson-c59ec8749661f242c6a15634cdb32fab65eda7c8.zip
meson-c59ec8749661f242c6a15634cdb32fab65eda7c8.tar.gz
meson-c59ec8749661f242c6a15634cdb32fab65eda7c8.tar.bz2
Create GL dependency objects via a factory function
Create GL dependency objects via a factory function, so they can be the correct type of object (e.g. a PkgConfigDependency when it's found by pkg-config) Factor out method: kwarg processing, so it can be used by the factory before the dependency object is constructed
-rw-r--r--mesonbuild/dependencies/base.py39
-rw-r--r--mesonbuild/dependencies/ui.py24
2 files changed, 36 insertions, 27 deletions
diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py
index 20a234d..04ca706 100644
--- a/mesonbuild/dependencies/base.py
+++ b/mesonbuild/dependencies/base.py
@@ -61,15 +61,8 @@ class DependencyMethods(Enum):
class Dependency:
- def __init__(self, type_name, kwargs):
- self.name = "null"
- self.version = 'none'
- self.language = None # None means C-like
- self.is_found = False
- self.type_name = type_name
- self.compile_args = []
- self.link_args = []
- self.sources = []
+ @classmethod
+ def _process_method_kw(cls, kwargs):
method = kwargs.get('method', 'auto')
if method not in [e.value for e in DependencyMethods]:
raise DependencyException('method {!r} is invalid'.format(method))
@@ -88,14 +81,27 @@ class Dependency:
# 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:
- self.methods = self.get_methods()
- elif method in self.get_methods():
- self.methods = [method]
+ 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] + self.get_methods()])))
+ mlog.format_list([x.value for x in [DependencyMethods.AUTO] + cls.get_methods()])))
+
+ return methods
+
+ def __init__(self, type_name, kwargs):
+ self.name = "null"
+ self.version = 'none'
+ self.language = None # None means C-like
+ self.is_found = False
+ self.type_name = type_name
+ self.compile_args = []
+ self.link_args = []
+ self.sources = []
+ self.methods = self._process_method_kw(kwargs)
def __repr__(self):
s = '<{0} {1}: {2}>'
@@ -890,7 +896,12 @@ def find_external_dependency(name, env, kwargs):
if lname in packages:
if lname not in _packages_accept_language and 'language' in kwargs:
raise DependencyException('%s dependency does not accept "language" keyword argument' % (lname, ))
- dep = packages[lname](env, kwargs)
+ # Create the dependency object using a factory class method, if one
+ # exists, otherwise it is just constructed directly.
+ if getattr(packages[lname], '_factory', None):
+ dep = packages[lname]._factory(env, kwargs)
+ else:
+ dep = packages[lname](env, kwargs)
if required and not dep.found():
raise DependencyException('Dependency "%s" not found' % name)
return dep
diff --git a/mesonbuild/dependencies/ui.py b/mesonbuild/dependencies/ui.py
index 00cd56d..bc332fc 100644
--- a/mesonbuild/dependencies/ui.py
+++ b/mesonbuild/dependencies/ui.py
@@ -38,19 +38,6 @@ from .base import ConfigToolDependency
class GLDependency(ExternalDependency):
def __init__(self, environment, kwargs):
super().__init__('gl', environment, None, kwargs)
- if DependencyMethods.PKGCONFIG in self.methods:
- try:
- pcdep = PkgConfigDependency('gl', environment, kwargs)
- if pcdep.found():
- self.type_name = 'pkgconfig'
- self.is_found = True
- self.compile_args = pcdep.get_compile_args()
- self.link_args = pcdep.get_link_args()
- self.version = pcdep.get_version()
- self.pcdep = pcdep
- return
- except Exception:
- pass
if DependencyMethods.SYSTEM in self.methods:
if mesonlib.is_osx():
self.is_found = True
@@ -67,6 +54,17 @@ class GLDependency(ExternalDependency):
self.version = '1'
return
+ @classmethod
+ def _factory(cls, environment, kwargs):
+ if DependencyMethods.PKGCONFIG in cls._process_method_kw(kwargs):
+ try:
+ pcdep = PkgConfigDependency('gl', environment, kwargs)
+ if pcdep.found():
+ return pcdep
+ except Exception:
+ pass
+ return GLDependency(environment, kwargs)
+
@staticmethod
def get_methods():
if mesonlib.is_osx() or mesonlib.is_windows():