diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py index cdeaf5edb..f8469c527 100644 --- a/mesonbuild/dependencies/base.py +++ b/mesonbuild/dependencies/base.py @@ -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: diff --git a/mesonbuild/dependencies/misc.py b/mesonbuild/dependencies/misc.py index 5bd9d9305..1d19b0456 100644 --- a/mesonbuild/dependencies/misc.py +++ b/mesonbuild/dependencies/misc.py @@ -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): diff --git a/mesonbuild/dependencies/ui.py b/mesonbuild/dependencies/ui.py index bf74029c5..1db518c12 100644 --- a/mesonbuild/dependencies/ui.py +++ b/mesonbuild/dependencies/ui.py @@ -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: diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index f112d7b63..ff93feb45 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -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) diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py index f916c2c81..56765a5da 100644 --- a/mesonbuild/modules/gnome.py +++ b/mesonbuild/modules/gnome.py @@ -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 diff --git a/run_unittests.py b/run_unittests.py index 8c6111169..0002f6cfd 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -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): ''' diff --git a/test cases/linuxlike/1 pkg-config/meson.build b/test cases/linuxlike/1 pkg-config/meson.build index 17feb219f..30e5d2508 100644 --- a/test cases/linuxlike/1 pkg-config/meson.build +++ b/test cases/linuxlike/1 pkg-config/meson.build @@ -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)