diff --git a/mesonbuild/modules/pkgconfig.py b/mesonbuild/modules/pkgconfig.py index 5ff26ecc7..2f4dfaec7 100644 --- a/mesonbuild/modules/pkgconfig.py +++ b/mesonbuild/modules/pkgconfig.py @@ -44,10 +44,30 @@ class DependenciesHelper: self.priv_reqs += reqs def add_pub_reqs(self, reqs): - self.pub_reqs += mesonlib.stringlistify(reqs) + self.pub_reqs += self._process_reqs(reqs) def add_priv_reqs(self, reqs): - self.priv_reqs += mesonlib.stringlistify(reqs) + self.priv_reqs += self._process_reqs(reqs) + + def _process_reqs(self, reqs): + '''Returns string names of requirements''' + processed_reqs = [] + for obj in mesonlib.listify(reqs, unholder=True): + if hasattr(obj, 'generated_pc'): + processed_reqs.append(obj.generated_pc) + elif hasattr(obj, 'pcdep'): + pcdeps = mesonlib.listify(obj.pcdep) + processed_reqs += [i.name for i in pcdeps] + elif isinstance(obj, dependencies.PkgConfigDependency): + if obj.found(): + processed_reqs.append(obj.name) + elif isinstance(obj, str): + processed_reqs.append(obj) + else: + raise mesonlib.MesonException('requires argument not a string, ' + 'library with pkgconfig-generated file ' + 'or pkgconfig-dependency object.') + return processed_reqs def add_cflags(self, cflags): self.cflags += mesonlib.stringlistify(cflags) diff --git a/run_unittests.py b/run_unittests.py index 41cbf3931..96d60457d 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -2169,6 +2169,14 @@ class LinuxlikeTests(BasePlatformTests): '-llibinternal', '-lcustom2', '-lfoo'])) + cmd = ['pkg-config', 'requires-test'] + out = self._run(cmd + ['--print-requires']).strip().split() + self.assertEqual(sorted(out), sorted(['libexposed', 'libfoo', 'libhello'])) + + cmd = ['pkg-config', 'requires-private-test'] + out = self._run(cmd + ['--print-requires-private']).strip().split() + self.assertEqual(sorted(out), sorted(['libexposed', 'libfoo', 'libhello'])) + def test_pkg_unfound(self): testdir = os.path.join(self.unit_test_dir, '22 unfound pkgconfig') self.init(testdir) diff --git a/test cases/common/51 pkgconfig-gen/dependencies/meson.build b/test cases/common/51 pkgconfig-gen/dependencies/meson.build index 61bc0df42..018b72fba 100644 --- a/test cases/common/51 pkgconfig-gen/dependencies/meson.build +++ b/test cases/common/51 pkgconfig-gen/dependencies/meson.build @@ -36,3 +36,17 @@ pkgg.generate(libraries : [main_lib, exposed_lib, threads_dep , custom_dep], filebase : 'dependency-test', description : 'A dependency test.' ) + +pkgg.generate( + name : 'requires-test', + version : '1.0', + description : 'Dependency Requires field test.', + requires : [exposed_lib, pc_dep, 'libhello'], +) + +pkgg.generate( + name : 'requires-private-test', + version : '1.0', + description : 'Dependency Requires.private field test.', + requires_private : [exposed_lib, pc_dep, 'libhello', notfound_dep], +) diff --git a/test cases/common/51 pkgconfig-gen/meson.build b/test cases/common/51 pkgconfig-gen/meson.build index f9d7f7fd1..7e6c67037 100644 --- a/test cases/common/51 pkgconfig-gen/meson.build +++ b/test cases/common/51 pkgconfig-gen/meson.build @@ -46,3 +46,9 @@ pkgg.generate( description : 'A foo library.', variables : ['foo=bar', 'datadir=${prefix}/data'] ) + +pkgg.generate( + name : 'libhello', + description : 'A minimalistic pkgconfig file.', + version : libver, +)