Merge pull request #2663 from inigomartinez/pkg-config-define-variable
dependencies: Allow pkg-config to define variables
This commit is contained in:
commit
018deb48fe
|
@ -130,7 +130,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))
|
||||
|
||||
def get_configtool_variable(self, variable_name):
|
||||
|
@ -491,8 +491,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:
|
||||
|
|
|
@ -682,11 +682,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):
|
||||
|
|
|
@ -239,7 +239,7 @@ class QtBaseDependency(ExternalDependency):
|
|||
self.bindir = self.get_pkgconfig_host_bins(core)
|
||||
if not self.bindir:
|
||||
# If exec_prefix is not defined, the pkg-config file is broken
|
||||
prefix = core.get_pkgconfig_variable('exec_prefix')
|
||||
prefix = core.get_pkgconfig_variable('exec_prefix', {})
|
||||
if prefix:
|
||||
self.bindir = os.path.join(prefix, 'bin')
|
||||
|
||||
|
@ -359,7 +359,7 @@ class Qt4Dependency(QtBaseDependency):
|
|||
applications = ['moc', 'uic', 'rcc', 'lupdate', 'lrelease']
|
||||
for application in applications:
|
||||
try:
|
||||
return os.path.dirname(core.get_pkgconfig_variable('%s_location' % application))
|
||||
return os.path.dirname(core.get_pkgconfig_variable('%s_location' % application, {}))
|
||||
except MesonException:
|
||||
pass
|
||||
|
||||
|
@ -369,7 +369,7 @@ class Qt5Dependency(QtBaseDependency):
|
|||
QtBaseDependency.__init__(self, 'qt5', env, kwargs)
|
||||
|
||||
def get_pkgconfig_host_bins(self, core):
|
||||
return core.get_pkgconfig_variable('host_bins')
|
||||
return core.get_pkgconfig_variable('host_bins', {})
|
||||
|
||||
|
||||
# There are three different ways of depending on SDL2:
|
||||
|
|
|
@ -295,7 +295,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)
|
||||
|
||||
def configtool_method(self, args, kwargs):
|
||||
args = listify(args)
|
||||
|
|
|
@ -362,7 +362,7 @@ class GnomeModule(ExtensionModule):
|
|||
ldflags.update([lib])
|
||||
|
||||
if isinstance(dep, PkgConfigDependency):
|
||||
girdir = dep.get_pkgconfig_variable("girdir")
|
||||
girdir = dep.get_pkgconfig_variable("girdir", {})
|
||||
if girdir:
|
||||
gi_includes.update([girdir])
|
||||
elif isinstance(dep, (build.StaticLibrary, build.SharedLibrary)):
|
||||
|
@ -553,7 +553,7 @@ class GnomeModule(ExtensionModule):
|
|||
if subdir not in typelib_includes:
|
||||
typelib_includes.append(subdir)
|
||||
elif isinstance(dep, PkgConfigDependency):
|
||||
girdir = dep.get_pkgconfig_variable("girdir")
|
||||
girdir = dep.get_pkgconfig_variable("girdir", {})
|
||||
if girdir and girdir not in typelib_includes:
|
||||
typelib_includes.append(girdir)
|
||||
# ldflags will be misinterpreted by gir scanner (showing
|
||||
|
|
|
@ -1891,8 +1891,8 @@ class LinuxlikeTests(BasePlatformTests):
|
|||
self.assertTrue(foo_dep.found())
|
||||
self.assertEqual(foo_dep.get_version(), '1.0')
|
||||
self.assertIn('-lfoo', foo_dep.get_link_args())
|
||||
self.assertEqual(foo_dep.get_pkgconfig_variable('foo'), 'bar')
|
||||
self.assertPathEqual(foo_dep.get_pkgconfig_variable('datadir'), '/usr/data')
|
||||
self.assertEqual(foo_dep.get_pkgconfig_variable('foo', {}), 'bar')
|
||||
self.assertPathEqual(foo_dep.get_pkgconfig_variable('datadir', {}), '/usr/data')
|
||||
|
||||
def test_vala_c_warnings(self):
|
||||
'''
|
||||
|
|
|
@ -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('prefix', define_variable: ['prefix', '/tmp']) == '/tmp', 'prefix variable has not been replaced.')
|
||||
|
||||
# Test that dependencies of dependencies work.
|
||||
dep2 = declare_dependency(dependencies : dep)
|
||||
|
|
Loading…
Reference in New Issue