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
pull/3514/head
Nirbheek Chauhan 7 years ago committed by Nirbheek Chauhan
parent 2b5766980b
commit badbfa125c
  1. 12
      mesonbuild/build.py
  2. 4
      mesonbuild/modules/pkgconfig.py
  3. 11
      run_unittests.py
  4. 5
      test cases/unit/31 pkgconfig format/meson.build
  5. 4
      test cases/unit/31 pkgconfig format/somelib.c
  6. 3
      test cases/unit/31 pkgconfig format/someret.c

@ -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):

@ -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)

@ -3108,11 +3108,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):
'''

@ -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')

@ -1,5 +1,7 @@
#include<stdio.h>
int get_returnvalue (void);
int some_func() {
return 0;
return get_returnvalue();
}

@ -0,0 +1,3 @@
int get_returnvalue (void) {
return 0;
}
Loading…
Cancel
Save