Merge pull request #2663 from inigomartinez/pkg-config-define-variable

dependencies: Allow pkg-config to define variables
pull/2615/head
Jussi Pakkanen 7 years ago committed by GitHub
commit 018deb48fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      mesonbuild/dependencies/base.py
  2. 6
      mesonbuild/dependencies/misc.py
  3. 6
      mesonbuild/dependencies/ui.py
  4. 2
      mesonbuild/interpreter.py
  5. 4
      mesonbuild/modules/gnome.py
  6. 4
      run_unittests.py
  7. 2
      test cases/linuxlike/1 pkg-config/meson.build

@ -130,7 +130,7 @@ class Dependency:
def need_threads(self): def need_threads(self):
return False 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)) raise NotImplementedError('{!r} is not a pkgconfig dependency'.format(self.name))
def get_configtool_variable(self, variable_name): def get_configtool_variable(self, variable_name):
@ -491,8 +491,20 @@ class PkgConfigDependency(ExternalDependency):
self.is_libtool = True self.is_libtool = True
self.link_args.append(lib) self.link_args.append(lib)
def get_pkgconfig_variable(self, variable_name): def get_pkgconfig_variable(self, variable_name, kwargs):
ret, out = self._call_pkgbin(['--variable=' + variable_name, self.name]) 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 = '' variable = ''
if ret != 0: if ret != 0:
if self.required: if self.required:

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

@ -239,7 +239,7 @@ class QtBaseDependency(ExternalDependency):
self.bindir = self.get_pkgconfig_host_bins(core) self.bindir = self.get_pkgconfig_host_bins(core)
if not self.bindir: if not self.bindir:
# If exec_prefix is not defined, the pkg-config file is broken # 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: if prefix:
self.bindir = os.path.join(prefix, 'bin') self.bindir = os.path.join(prefix, 'bin')
@ -359,7 +359,7 @@ class Qt4Dependency(QtBaseDependency):
applications = ['moc', 'uic', 'rcc', 'lupdate', 'lrelease'] applications = ['moc', 'uic', 'rcc', 'lupdate', 'lrelease']
for application in applications: for application in applications:
try: 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: except MesonException:
pass pass
@ -369,7 +369,7 @@ class Qt5Dependency(QtBaseDependency):
QtBaseDependency.__init__(self, 'qt5', env, kwargs) QtBaseDependency.__init__(self, 'qt5', env, kwargs)
def get_pkgconfig_host_bins(self, core): 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: # There are three different ways of depending on SDL2:

@ -295,7 +295,7 @@ class DependencyHolder(InterpreterObject, ObjectHolder):
varname = args[0] varname = args[0]
if not isinstance(varname, str): if not isinstance(varname, str):
raise InterpreterException('Variable name must be a string.') 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): def configtool_method(self, args, kwargs):
args = listify(args) args = listify(args)

@ -362,7 +362,7 @@ class GnomeModule(ExtensionModule):
ldflags.update([lib]) ldflags.update([lib])
if isinstance(dep, PkgConfigDependency): if isinstance(dep, PkgConfigDependency):
girdir = dep.get_pkgconfig_variable("girdir") girdir = dep.get_pkgconfig_variable("girdir", {})
if girdir: if girdir:
gi_includes.update([girdir]) gi_includes.update([girdir])
elif isinstance(dep, (build.StaticLibrary, build.SharedLibrary)): elif isinstance(dep, (build.StaticLibrary, build.SharedLibrary)):
@ -553,7 +553,7 @@ class GnomeModule(ExtensionModule):
if subdir not in typelib_includes: if subdir not in typelib_includes:
typelib_includes.append(subdir) typelib_includes.append(subdir)
elif isinstance(dep, PkgConfigDependency): elif isinstance(dep, PkgConfigDependency):
girdir = dep.get_pkgconfig_variable("girdir") girdir = dep.get_pkgconfig_variable("girdir", {})
if girdir and girdir not in typelib_includes: if girdir and girdir not in typelib_includes:
typelib_includes.append(girdir) typelib_includes.append(girdir)
# ldflags will be misinterpreted by gir scanner (showing # ldflags will be misinterpreted by gir scanner (showing

@ -1891,8 +1891,8 @@ class LinuxlikeTests(BasePlatformTests):
self.assertTrue(foo_dep.found()) self.assertTrue(foo_dep.found())
self.assertEqual(foo_dep.get_version(), '1.0') self.assertEqual(foo_dep.get_version(), '1.0')
self.assertIn('-lfoo', foo_dep.get_link_args()) self.assertIn('-lfoo', foo_dep.get_link_args())
self.assertEqual(foo_dep.get_pkgconfig_variable('foo'), 'bar') self.assertEqual(foo_dep.get_pkgconfig_variable('foo', {}), 'bar')
self.assertPathEqual(foo_dep.get_pkgconfig_variable('datadir'), '/usr/data') self.assertPathEqual(foo_dep.get_pkgconfig_variable('datadir', {}), '/usr/data')
def test_vala_c_warnings(self): 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. 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 # pkg-config returns empty string for not defined variables
assert(dep.get_pkgconfig_variable('nonexisting') == '', 'Value of unknown variable is not empty.') 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. # Test that dependencies of dependencies work.
dep2 = declare_dependency(dependencies : dep) dep2 = declare_dependency(dependencies : dep)

Loading…
Cancel
Save