133 lines
5.5 KiB
Diff
133 lines
5.5 KiB
Diff
|
From a3b2ae8ebcdcebd68b8a217d03102c6d03fcb766 Mon Sep 17 00:00:00 2001
|
||
|
From: Nirbheek Chauhan <nirbheek@centricular.com>
|
||
|
Date: Tue, 1 May 2018 17:54:54 +0530
|
||
|
Subject: [PATCH 16/16] pkgconfig: Don't expose internal libraries in .pc files
|
||
|
|
||
|
Libraries that have been linked with link_whole: are internal
|
||
|
implementation details and should never be exposed to the outside
|
||
|
world in either Libs: or Libs.private:
|
||
|
|
||
|
Closes https://github.com/mesonbuild/meson/issues/3509
|
||
|
---
|
||
|
mesonbuild/build.py | 12 +++++++++---
|
||
|
mesonbuild/modules/pkgconfig.py | 4 ++--
|
||
|
run_unittests.py | 11 ++++++-----
|
||
|
test cases/unit/31 pkgconfig format/meson.build | 5 +++--
|
||
|
test cases/unit/31 pkgconfig format/somelib.c | 4 +++-
|
||
|
test cases/unit/31 pkgconfig format/someret.c | 3 +++
|
||
|
6 files changed, 26 insertions(+), 13 deletions(-)
|
||
|
create mode 100644 test cases/unit/31 pkgconfig format/someret.c
|
||
|
|
||
|
diff --git a/mesonbuild/build.py b/mesonbuild/build.py
|
||
|
index 3d531d18..a2d024ae 100644
|
||
|
--- a/mesonbuild/build.py
|
||
|
+++ b/mesonbuild/build.py
|
||
|
@@ -817,16 +817,22 @@ This will become a hard error in a future Meson release.''')
|
||
|
def get_extra_args(self, language):
|
||
|
return self.extra_args.get(language, [])
|
||
|
|
||
|
- def get_dependencies(self, exclude=None):
|
||
|
+ def get_dependencies(self, exclude=None, internal=True):
|
||
|
transitive_deps = []
|
||
|
if exclude is None:
|
||
|
exclude = []
|
||
|
- for t in itertools.chain(self.link_targets, self.link_whole_targets):
|
||
|
+ if internal:
|
||
|
+ link_targets = itertools.chain(self.link_targets, self.link_whole_targets)
|
||
|
+ else:
|
||
|
+ # We don't want the 'internal' libraries when generating the
|
||
|
+ # `Libs:` and `Libs.private:` lists in pkg-config files.
|
||
|
+ link_targets = self.link_targets
|
||
|
+ for t in link_targets:
|
||
|
if t in transitive_deps or t in exclude:
|
||
|
continue
|
||
|
transitive_deps.append(t)
|
||
|
if isinstance(t, StaticLibrary):
|
||
|
- transitive_deps += t.get_dependencies(transitive_deps + exclude)
|
||
|
+ transitive_deps += t.get_dependencies(transitive_deps + exclude, internal)
|
||
|
return transitive_deps
|
||
|
|
||
|
def get_source_subdir(self):
|
||
|
diff --git a/mesonbuild/modules/pkgconfig.py b/mesonbuild/modules/pkgconfig.py
|
||
|
index 419a14c7..365d3cd3 100644
|
||
|
--- a/mesonbuild/modules/pkgconfig.py
|
||
|
+++ b/mesonbuild/modules/pkgconfig.py
|
||
|
@@ -123,10 +123,10 @@ class DependenciesHelper:
|
||
|
if not hasattr(obj, 'generated_pc'):
|
||
|
obj.generated_pc = self.name
|
||
|
if isinstance(obj, build.StaticLibrary) and public:
|
||
|
- self.add_pub_libs(obj.get_dependencies())
|
||
|
+ self.add_pub_libs(obj.get_dependencies(internal=False))
|
||
|
self.add_pub_libs(obj.get_external_deps())
|
||
|
else:
|
||
|
- self.add_priv_libs(obj.get_dependencies())
|
||
|
+ self.add_priv_libs(obj.get_dependencies(internal=False))
|
||
|
self.add_priv_libs(obj.get_external_deps())
|
||
|
elif isinstance(obj, str):
|
||
|
processed_libs.append(obj)
|
||
|
diff --git a/run_unittests.py b/run_unittests.py
|
||
|
index 6773bbd1..befba2d1 100755
|
||
|
--- a/run_unittests.py
|
||
|
+++ b/run_unittests.py
|
||
|
@@ -2989,11 +2989,12 @@ endian = 'little'
|
||
|
self.init(testdir)
|
||
|
myenv = os.environ.copy()
|
||
|
myenv['PKG_CONFIG_PATH'] = self.privatedir
|
||
|
- ro = subprocess.run(['pkg-config', '--libs', 'libsomething'], stdout=subprocess.PIPE,
|
||
|
- env=myenv)
|
||
|
- self.assertEqual(ro.returncode, 0)
|
||
|
- self.assertIn(b'-lgobject-2.0', ro.stdout)
|
||
|
- self.assertIn(b'-lgio-2.0', ro.stdout)
|
||
|
+ stdo = subprocess.check_output(['pkg-config', '--libs-only-l', 'libsomething'], env=myenv)
|
||
|
+ deps = [b'-lgobject-2.0', b'-lgio-2.0', b'-lglib-2.0', b'-lsomething']
|
||
|
+ if is_windows() or is_cygwin():
|
||
|
+ # On Windows, libintl is a separate library
|
||
|
+ deps.append(b'-lintl')
|
||
|
+ self.assertEqual(set(deps), set(stdo.split()))
|
||
|
|
||
|
class LinuxArmCrossCompileTests(BasePlatformTests):
|
||
|
'''
|
||
|
diff --git a/test cases/unit/31 pkgconfig format/meson.build b/test cases/unit/31 pkgconfig format/meson.build
|
||
|
index bbd3b125..ea00f5df 100644
|
||
|
--- a/test cases/unit/31 pkgconfig format/meson.build
|
||
|
+++ b/test cases/unit/31 pkgconfig format/meson.build
|
||
|
@@ -8,10 +8,11 @@ endif
|
||
|
|
||
|
pkgg = import('pkgconfig')
|
||
|
|
||
|
-l = shared_library('something', 'somelib.c')
|
||
|
+s = static_library('returner', 'someret.c')
|
||
|
+l = library('something', 'somelib.c', link_whole: s)
|
||
|
|
||
|
pkgg.generate(libraries: l,
|
||
|
version: '1.0',
|
||
|
name: 'libsomething',
|
||
|
description: 'A library that does something',
|
||
|
- requires: 'gobject-2.0 >= 2.54, gio-2.0 >= 2.54')
|
||
|
+ requires: 'gobject-2.0 >= 2.0, gio-2.0 >= 2.0')
|
||
|
diff --git a/test cases/unit/31 pkgconfig format/somelib.c b/test cases/unit/31 pkgconfig format/somelib.c
|
||
|
index 6d876c8f..0558024b 100644
|
||
|
--- a/test cases/unit/31 pkgconfig format/somelib.c
|
||
|
+++ b/test cases/unit/31 pkgconfig format/somelib.c
|
||
|
@@ -1,5 +1,7 @@
|
||
|
#include<stdio.h>
|
||
|
|
||
|
+int get_returnvalue (void);
|
||
|
+
|
||
|
int some_func() {
|
||
|
- return 0;
|
||
|
+ return get_returnvalue();
|
||
|
}
|
||
|
diff --git a/test cases/unit/31 pkgconfig format/someret.c b/test cases/unit/31 pkgconfig format/someret.c
|
||
|
new file mode 100644
|
||
|
index 00000000..69f42992
|
||
|
--- /dev/null
|
||
|
+++ b/test cases/unit/31 pkgconfig format/someret.c
|
||
|
@@ -0,0 +1,3 @@
|
||
|
+int get_returnvalue (void) {
|
||
|
+ return 0;
|
||
|
+}
|
||
|
--
|
||
|
2.17.0
|
||
|
|