diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2017-10-19 00:06:03 -0700 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2017-11-23 19:54:48 -0800 |
commit | cc28eba8d08b2e270b0313f679dc7d390cc2fe44 (patch) | |
tree | 4160ff3ecc58a5bea2330edcd1c03416a4202114 | |
parent | 38e2c0e8f57993d795e72589ac1bc728409c0553 (diff) | |
download | meson-cc28eba8d08b2e270b0313f679dc7d390cc2fe44.tar.gz |
Add factory to ConfigToolDependency
Some dependencies can be detected multiple ways, such as a config tool
and pkg-config. For pkg-config a new PkgConfigDependency is created and
used to check for the dependency, config tool dependencies are handled
ad-hoc. This allows the ConfigToolDependency to be used in the same way
that PkgConfigDependency is.
-rw-r--r-- | mesonbuild/dependencies/base.py | 21 |
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. |