Do not leak out private dependencies for shared libraries.

pull/3251/head
Jussi Pakkanen 7 years ago
parent d532650b0d
commit c385f79737
  1. 12
      mesonbuild/modules/pkgconfig.py
  2. 7
      run_unittests.py

@ -93,7 +93,17 @@ class DependenciesHelper:
if obj.found(): if obj.found():
processed_libs += obj.get_link_args() processed_libs += obj.get_link_args()
processed_cflags += obj.get_compile_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) processed_libs.append(obj)
if public: if public:
if not hasattr(obj, 'generated_pc'): if not hasattr(obj, 'generated_pc'):

@ -2726,6 +2726,13 @@ endian = 'little'
self.assertTrue(os.path.exists(os.path.join(pkg_dir, 'libpkgdep.pc'))) self.assertTrue(os.path.exists(os.path.join(pkg_dir, 'libpkgdep.pc')))
lib_dir = os.path.join(tempdirname, 'lib') lib_dir = os.path.join(tempdirname, 'lib')
os.environ['PKG_CONFIG_PATH'] = pkg_dir 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.init(testdir2)
self.build() self.build()
myenv = os.environ.copy() myenv = os.environ.copy()

Loading…
Cancel
Save