diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2018-03-17 00:37:05 +0200 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2018-03-17 00:44:56 +0200 |
commit | c385f7973777e0e7b7e4694d69d6584e2ceae69f (patch) | |
tree | 3df52287253b853741d04350c39e836af3069e5c | |
parent | d532650b0d7fb8bb062d852a8fdecd10be00ce21 (diff) | |
download | meson-c385f7973777e0e7b7e4694d69d6584e2ceae69f.zip meson-c385f7973777e0e7b7e4694d69d6584e2ceae69f.tar.gz meson-c385f7973777e0e7b7e4694d69d6584e2ceae69f.tar.bz2 |
Do not leak out private dependencies for shared libraries.
-rw-r--r-- | mesonbuild/modules/pkgconfig.py | 12 | ||||
-rwxr-xr-x | run_unittests.py | 7 |
2 files changed, 18 insertions, 1 deletions
diff --git a/mesonbuild/modules/pkgconfig.py b/mesonbuild/modules/pkgconfig.py index 2f4dfae..5254731 100644 --- a/mesonbuild/modules/pkgconfig.py +++ b/mesonbuild/modules/pkgconfig.py @@ -93,7 +93,17 @@ class DependenciesHelper: if obj.found(): processed_libs += obj.get_link_args() processed_cflags += obj.get_compile_args() - elif isinstance(obj, (build.SharedLibrary, build.StaticLibrary)): + elif isinstance(obj, build.SharedLibrary): + processed_libs.append(obj) + elif isinstance(obj, build.StaticLibrary): + # Due to a "feature" in pkgconfig, it leaks out private dependencies. + # Thus we will not add them to the pc file unless the target + # we are processing is a static library. + # + # This way (hopefully) "pkgconfig --libs --static foobar" works + # and "pkgconfig --cflags/--libs foobar" does not have any trace + # of dependencies that the build file creator has not explicitly + # added to the dependency list. processed_libs.append(obj) if public: if not hasattr(obj, 'generated_pc'): diff --git a/run_unittests.py b/run_unittests.py index 1e8bec4..44d5c9d 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -2726,6 +2726,13 @@ endian = 'little' self.assertTrue(os.path.exists(os.path.join(pkg_dir, 'libpkgdep.pc'))) lib_dir = os.path.join(tempdirname, 'lib') os.environ['PKG_CONFIG_PATH'] = pkg_dir + # Private internal libraries must not leak out. + pkg_out = subprocess.check_output(['pkg-config', '--static', '--libs', 'libpkgdep']) + self.assertFalse(b'libpkgdep-int' in pkg_out, 'Internal library leaked out.') + # Dependencies must not leak to cflags when building only a shared library. + pkg_out = subprocess.check_output(['pkg-config', '--cflags', 'libpkgdep']) + self.assertFalse(b'glib' in pkg_out, 'Internal dependency leaked to headers.') + # Test that the result is usable. self.init(testdir2) self.build() myenv = os.environ.copy() |