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.
pull/2512/head
Dylan Baker 8 years ago
parent 38e2c0e8f5
commit cc28eba8d0
  1. 21
      mesonbuild/dependencies/base.py

@ -192,6 +192,27 @@ class ConfigToolDependency(ExternalDependency):
return return
self.version = version 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): def find_config(self, versions=None):
"""Helper method that searchs for config tool binaries in PATH and """Helper method that searchs for config tool binaries in PATH and
returns the one that best matches the given version requirements. returns the one that best matches the given version requirements.

Loading…
Cancel
Save