diff --git a/mesonbuild/dependencies.py b/mesonbuild/dependencies.py index d0c76632d..df6dcffe9 100644 --- a/mesonbuild/dependencies.py +++ b/mesonbuild/dependencies.py @@ -63,6 +63,9 @@ class Dependency(): def type_name(self): return self.type_name + def get_pkgconfig_variable(self, variable_name): + raise MesonException('Tried to get a pkg-config variable from a non-pkgconfig dependency.') + class InternalDependency(Dependency): def __init__(self, version, incdirs, compile_args, link_args, libraries, sources, ext_deps): super().__init__('internal') @@ -190,7 +193,7 @@ class PkgConfigDependency(Dependency): self.is_libtool = True self.libs.append(lib) - def get_variable(self, variable_name): + def get_pkgconfig_variable(self, variable_name): ret, out = self._call_pkgbin(['--variable=' + variable_name, self.name]) variable = '' if ret != 0: @@ -199,8 +202,7 @@ class PkgConfigDependency(Dependency): (self.type_string, self.name)) else: variable = out.strip() - mlog.debug('return of subprocess : %s' % variable) - + mlog.debug('Got pkgconfig variable %s : %s' % (variable_name, variable)) return variable def get_modversion(self): diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 27a46de99..44b574832 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -284,7 +284,10 @@ class DependencyHolder(InterpreterObject): self.held_object = dep self.methods.update({'found' : self.found_method, 'type_name': self.type_name_method, - 'version': self.version_method}) + 'version': self.version_method, + 'version': self.version_method, + 'get_pkgconfig_variable': self.pkgconfig_method, + }) def type_name_method(self, args, kwargs): return self.held_object.type_name @@ -298,6 +301,29 @@ class DependencyHolder(InterpreterObject): def version_method(self, args, kwargs): return self.held_object.get_version() + def pkgconfig_method(self, args, kwargs): + if not isinstance(args, list): + args = [args] + if len(args) != 1: + raise InterpreterException('get_pkgconfig_variable takes exactly one argument.') + varname = args[0] + if not isinstance(varname, str): + raise InterpreterException('Variable name must be a string.') + return self.held_object.get_pkgconfig_variable(varname) + +class InternalDependencyHolder(InterpreterObject): + def __init__(self, dep): + InterpreterObject.__init__(self) + self.held_object = dep + self.methods.update({'found' : self.found_method, + 'version': self.version_method, + }) + + def found_method(self, args, kwargs): + return True + + def version_method(self, args, kwargs): + return self.held_object.get_version() class ExternalProgramHolder(InterpreterObject): def __init__(self, ep): diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py index 287005b27..ea9b15a13 100644 --- a/mesonbuild/modules/gnome.py +++ b/mesonbuild/modules/gnome.py @@ -266,7 +266,7 @@ class GnomeModule: ldflags.update([lib]) if isinstance(dep, dependencies.PkgConfigDependency): - girdir = dep.get_variable("girdir") + girdir = dep.get_pkgconfig_variable("girdir") if girdir: gi_includes.update([girdir]) elif isinstance(dep, (build.StaticLibrary, build.SharedLibrary)): @@ -421,7 +421,7 @@ class GnomeModule: ) ] elif isinstance(dep, dependencies.PkgConfigDependency): - girdir = dep.get_variable("girdir") + girdir = dep.get_pkgconfig_variable("girdir") if girdir: typelib_cmd += ["--includedir=%s" % (girdir, )] diff --git a/test cases/linuxlike/1 pkg-config/meson.build b/test cases/linuxlike/1 pkg-config/meson.build index a18acc5ce..13361a7f3 100644 --- a/test cases/linuxlike/1 pkg-config/meson.build +++ b/test cases/linuxlike/1 pkg-config/meson.build @@ -9,6 +9,10 @@ assert(dep.version().version_compare('>=1.2.8'), 'Pkg-config version numbers exp 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.') + # Test that dependencies of dependencies work. dep2 = declare_dependency(dependencies : dep) exe2 = executable('zlibprog2', 'prog.c', dependencies : dep2)