dependencies: Allow pkg-config to define variables

pkg-config enables to define variables by using the define-variable
option. This allows some packages to redefine relative paths, so
files can be installed in the same relative paths but under prefix.
pull/2663/head
Iñigo Martínez 7 years ago
parent eba6972306
commit 935ca12822
  1. 18
      mesonbuild/dependencies/base.py
  2. 6
      mesonbuild/dependencies/misc.py
  3. 2
      mesonbuild/interpreter.py
  4. 2
      test cases/linuxlike/1 pkg-config/meson.build

@ -117,7 +117,7 @@ class Dependency:
def need_threads(self):
return False
def get_pkgconfig_variable(self, variable_name):
def get_pkgconfig_variable(self, variable_name, kwargs):
raise NotImplementedError('{!r} is not a pkgconfig dependency'.format(self.name))
@ -316,8 +316,20 @@ class PkgConfigDependency(ExternalDependency):
self.is_libtool = True
self.link_args.append(lib)
def get_pkgconfig_variable(self, variable_name):
ret, out = self._call_pkgbin(['--variable=' + variable_name, self.name])
def get_pkgconfig_variable(self, variable_name, kwargs):
options = ['--variable=' + variable_name, self.name]
if 'define_variable' in kwargs:
definition = kwargs.get('define_variable', [])
if not isinstance(definition, list):
raise MesonException('define_variable takes a list')
if len(definition) != 2 or not all(isinstance(i, str) for i in definition):
raise MesonException('define_variable must be made up of 2 strings for VARIABLENAME and VARIABLEVALUE')
options = ['--define-variable=' + '='.join(definition)] + options
ret, out = self._call_pkgbin(options)
variable = ''
if ret != 0:
if self.required:

@ -677,11 +677,11 @@ class Python3Dependency(ExternalDependency):
else:
return [DependencyMethods.PKGCONFIG]
def get_pkgconfig_variable(self, variable_name):
def get_pkgconfig_variable(self, variable_name, kwargs):
if self.pkgdep:
return self.pkgdep.get_pkgconfig_variable(variable_name)
return self.pkgdep.get_pkgconfig_variable(variable_name, kwargs)
else:
return super().get_pkgconfig_variable(variable_name)
return super().get_pkgconfig_variable(variable_name, kwargs)
class PcapDependency(ExternalDependency):

@ -294,7 +294,7 @@ class DependencyHolder(InterpreterObject, ObjectHolder):
varname = args[0]
if not isinstance(varname, str):
raise InterpreterException('Variable name must be a string.')
return self.held_object.get_pkgconfig_variable(varname)
return self.held_object.get_pkgconfig_variable(varname, kwargs)
class InternalDependencyHolder(InterpreterObject, ObjectHolder):
def __init__(self, dep):

@ -17,6 +17,8 @@ test('zlibtest', exe)
zprefix = dep.get_pkgconfig_variable('prefix') # Always set but we can't be sure what the value is.
# pkg-config returns empty string for not defined variables
assert(dep.get_pkgconfig_variable('nonexisting') == '', 'Value of unknown variable is not empty.')
# pkg-config is able to replace variables
assert(dep.get_pkgconfig_variable('includedir', define_variable: ['prefix', '/tmp']) == '/tmp/include', 'prefix variable has not been replaced.')
# Test that dependencies of dependencies work.
dep2 = declare_dependency(dependencies : dep)

Loading…
Cancel
Save