Add a finish_init callback to ConfigToolDependency()

Give ConfigToolDependency() a finish_init callback, so that tool-specific
initialization can be called from the constructor, rather than after
construction in the factory class.

v2:
finalize -> finish_init for clarity
pull/3657/head
Jon Turney 7 years ago
parent 82bdf07a9d
commit 01118ce2a4
No known key found for this signature in database
GPG Key ID: C7C86F0370285C81
  1. 6
      mesonbuild/dependencies/base.py
  2. 38
      mesonbuild/dependencies/misc.py
  3. 10
      mesonbuild/dependencies/ui.py

@ -297,6 +297,8 @@ class ConfigToolDependency(ExternalDependency):
self.config = None
return
self.version = version
if getattr(self, 'finish_init', None):
self.finish_init(self)
def _sanitize_version(self, version):
"""Remove any non-numeric, non-point version suffixes."""
@ -308,7 +310,7 @@ class ConfigToolDependency(ExternalDependency):
return version
@classmethod
def factory(cls, name, environment, language, kwargs, tools, tool_name):
def factory(cls, name, environment, language, kwargs, tools, tool_name, finish_init=None):
"""Constructor for use in dependencies that can be found multiple ways.
In addition to the standard constructor values, this constructor sets
@ -323,7 +325,7 @@ class ConfigToolDependency(ExternalDependency):
def reduce(self):
return (cls._unpickle, (), self.__dict__)
sub = type('{}Dependency'.format(name.capitalize()), (cls, ),
{'tools': tools, 'tool_name': tool_name, '__reduce__': reduce})
{'tools': tools, 'tool_name': tool_name, '__reduce__': reduce, 'finish_init': staticmethod(finish_init)})
return sub(name, environment, language, kwargs)

@ -444,15 +444,19 @@ class PcapDependency(ExternalDependency):
if DependencyMethods.CONFIG_TOOL in methods:
candidates.append(functools.partial(ConfigToolDependency.factory,
'pcap', environment, None, kwargs, ['pcap-config'], 'pcap-config'))
# if ctdep.found():
# ctdep.compile_args = ctdep.get_config_value(['--cflags'], 'compile_args')
# ctdep.link_args = ctdep.get_config_value(['--libs'], 'link_args')
# ctdep.version = cls.get_pcap_lib_version(ctdep)
# return ctdep
'pcap', environment, None,
kwargs, ['pcap-config'],
'pcap-config',
PcapDependency.tool_finish_init))
return candidates
@staticmethod
def tool_finish_init(ctdep):
ctdep.compile_args = ctdep.get_config_value(['--cflags'], 'compile_args')
ctdep.link_args = ctdep.get_config_value(['--libs'], 'link_args')
ctdep.version = PcapDependency.get_pcap_lib_version(ctdep)
@staticmethod
def get_methods():
return [DependencyMethods.PKGCONFIG, DependencyMethods.CONFIG_TOOL]
@ -479,10 +483,7 @@ class CupsDependency(ExternalDependency):
candidates.append(functools.partial(ConfigToolDependency.factory,
'cups', environment, None,
kwargs, ['cups-config'],
'cups-config'))
# if ctdep.found():
# ctdep.compile_args = ctdep.get_config_value(['--cflags'], 'compile_args')
# ctdep.link_args = ctdep.get_config_value(['--ldflags', '--libs'], 'link_args')
'cups-config', CupsDependency.tool_finish_init))
if DependencyMethods.EXTRAFRAMEWORK in methods:
if mesonlib.is_osx():
@ -492,6 +493,11 @@ class CupsDependency(ExternalDependency):
return candidates
@staticmethod
def tool_finish_init(ctdep):
ctdep.compile_args = ctdep.get_config_value(['--cflags'], 'compile_args')
ctdep.link_args = ctdep.get_config_value(['--ldflags', '--libs'], 'link_args')
@staticmethod
def get_methods():
if mesonlib.is_osx():
@ -514,15 +520,15 @@ class LibWmfDependency(ExternalDependency):
if DependencyMethods.CONFIG_TOOL in methods:
candidates.append(functools.partial(ConfigToolDependency.factory,
'libwmf', environment, None, kwargs, ['libwmf-config'], 'libwmf-config'))
# if ctdep.found():
# ctdep.compile_args = ctdep.get_config_value(['--cflags'], 'compile_args')
# ctdep.link_args = ctdep.get_config_value(['--libs'], 'link_args')
# return ctdep
'libwmf', environment, None, kwargs, ['libwmf-config'], 'libwmf-config', LibWmfDependency.tool_finish_init))
return candidates
@staticmethod
def tool_finish_init(ctdep):
ctdep.compile_args = ctdep.get_config_value(['--cflags'], 'compile_args')
ctdep.link_args = ctdep.get_config_value(['--libs'], 'link_args')
@staticmethod
def get_methods():
return [DependencyMethods.PKGCONFIG, DependencyMethods.CONFIG_TOOL]

@ -464,10 +464,7 @@ class SDL2Dependency(ExternalDependency):
candidates.append(functools.partial(ConfigToolDependency.factory,
'sdl2', environment, None,
kwargs, ['sdl2-config'],
'sdl2-config'))
# if ctdep.found():
# ctdep.compile_args = ctdep.get_config_value(['--cflags'], 'compile_args')
# ctdep.link_args = ctdep.get_config_value(['--libs'], 'link_args')
'sdl2-config', SDL2Dependency.tool_finish_init))
if DependencyMethods.EXTRAFRAMEWORK in methods:
if mesonlib.is_osx():
@ -477,6 +474,11 @@ class SDL2Dependency(ExternalDependency):
# fwdep.version = '2' # FIXME
return candidates
@staticmethod
def tool_finish_init(ctdep):
ctdep.compile_args = ctdep.get_config_value(['--cflags'], 'compile_args')
ctdep.link_args = ctdep.get_config_value(['--libs'], 'link_args')
@staticmethod
def get_methods():
if mesonlib.is_osx():

Loading…
Cancel
Save