summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mesonbuild/dependencies/base.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py
index 4f8474d4c..02b59662a 100644
--- a/mesonbuild/dependencies/base.py
+++ b/mesonbuild/dependencies/base.py
@@ -192,6 +192,27 @@ class ConfigToolDependency(ExternalDependency):
return
self.version = version
+ @classmethod
+ def factory(cls, name, environment, language, kwargs, tools, tool_name):
+ """Constructor for use in dependencies that can be found multiple ways.
+
+ In addition to the standard constructor values, this constructor sets
+ the tool_name and tools values of the instance.
+ """
+ # This deserves some explanation, because metaprogramming is hard.
+ # This uses type() to create a dynamic subclass of ConfigToolDependency
+ # with the tools and tool_name class attributes set, this class is then
+ # instantiated and returned. The reduce function (method) is also
+ # attached, since python's pickle module won't be able to do anything
+ # with this dynamically generated class otherwise.
+ def reduce(_):
+ return (cls.factory,
+ (name, environment, language, kwargs, tools, tool_name))
+ sub = type('{}Dependency'.format(name.capitalize()), (cls, ),
+ {'tools': tools, 'tool_name': tool_name, '__reduce__': reduce})
+
+ return sub(name, environment, language, kwargs)
+
def find_config(self, versions=None):
"""Helper method that searchs for config tool binaries in PATH and
returns the one that best matches the given version requirements.