aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2017-12-03 22:53:44 +0200
committerGitHub <noreply@github.com>2017-12-03 22:53:44 +0200
commit018deb48feee88a1de73f8bcaea4d944dade7827 (patch)
tree684c53ed5a3938ddb5eaa00e6731b6e5a0aba350
parent312bc2ca810e333e7d8dd42e55ae9bd348757a07 (diff)
parentf8aab2f011afc93767a487cb68e856e21f9786d8 (diff)
downloadmeson-018deb48feee88a1de73f8bcaea4d944dade7827.zip
meson-018deb48feee88a1de73f8bcaea4d944dade7827.tar.gz
meson-018deb48feee88a1de73f8bcaea4d944dade7827.tar.bz2
Merge pull request #2663 from inigomartinez/pkg-config-define-variable
dependencies: Allow pkg-config to define variables
-rw-r--r--mesonbuild/dependencies/base.py18
-rw-r--r--mesonbuild/dependencies/misc.py6
-rw-r--r--mesonbuild/dependencies/ui.py6
-rw-r--r--mesonbuild/interpreter.py2
-rw-r--r--mesonbuild/modules/gnome.py4
-rwxr-xr-xrun_unittests.py4
-rw-r--r--test cases/linuxlike/1 pkg-config/meson.build2
7 files changed, 28 insertions, 14 deletions
diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py
index cdeaf5e..f8469c5 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 5bd9d93..1d19b04 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 bf74029..1db518c 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 f112d7b..ff93feb 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 f916c2c..56765a5 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 8c61111..0002f6c 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 17feb21..30e5d25 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)