pkgconfig: Do not include uninstalled static libraries

pull/5985/head
Xavier Claessens 5 years ago committed by Xavier Claessens
parent 484b721369
commit dc5ad1fad9
  1. 10
      mesonbuild/build.py
  2. 4
      mesonbuild/modules/pkgconfig.py
  3. 10
      run_unittests.py
  4. 4
      test cases/unit/69 static link/lib/func5.c
  5. 6
      test cases/unit/69 static link/lib/func6.c
  6. 12
      test cases/unit/69 static link/lib/meson.build
  7. 8
      test cases/unit/69 static link/meson.build
  8. 6
      test cases/unit/69 static link/test3.c

@ -970,11 +970,11 @@ 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, internal=True):
def get_dependencies(self, exclude=None, for_pkgconfig=False):
transitive_deps = []
if exclude is None:
exclude = []
if internal:
if not for_pkgconfig:
link_targets = itertools.chain(self.link_targets, self.link_whole_targets)
else:
# We don't want the 'internal' libraries when generating the
@ -983,9 +983,13 @@ This will become a hard error in a future Meson release.''')
for t in link_targets:
if t in transitive_deps or t in exclude:
continue
if for_pkgconfig and t.is_internal():
# Skip uninstalled static libraries, they have been promoted to
# link_whole into the static library.
continue
transitive_deps.append(t)
if isinstance(t, StaticLibrary):
transitive_deps += t.get_dependencies(transitive_deps + exclude, internal)
transitive_deps += t.get_dependencies(transitive_deps + exclude, for_pkgconfig)
return transitive_deps
def get_source_subdir(self):

@ -148,10 +148,10 @@ class DependenciesHelper:
elif isinstance(obj, (build.SharedLibrary, build.StaticLibrary)):
processed_libs.append(obj)
if isinstance(obj, build.StaticLibrary) and public:
self.add_pub_libs(obj.get_dependencies(internal=False))
self.add_pub_libs(obj.get_dependencies(for_pkgconfig=True))
self.add_pub_libs(obj.get_external_deps())
else:
self.add_priv_libs(obj.get_dependencies(internal=False))
self.add_priv_libs(obj.get_dependencies(for_pkgconfig=True))
self.add_priv_libs(obj.get_external_deps())
elif isinstance(obj, str):
processed_libs.append(obj)

@ -5637,6 +5637,9 @@ c = ['{0}']
self.init(testdir, override_envvars=env)
def test_static_link(self):
if is_cygwin():
raise unittest.SkipTest("Cygwin doesn't support LD_LIBRARY_PATH.")
# Build some libraries and install them
testdir = os.path.join(self.unit_test_dir, '69 static link/lib')
libdir = os.path.join(self.installdir, self.prefix[1:], self.libdir)
@ -5646,9 +5649,12 @@ c = ['{0}']
# Test that installed libraries works
self.new_builddir()
testdir = os.path.join(self.unit_test_dir, '69 static link')
self.init(testdir, extra_args=['-Dc_link_args="-L{}"'.format(libdir)])
env = {'PKG_CONFIG_LIBDIR': os.path.join(libdir, 'pkgconfig')}
run_env = {'LD_LIBRARY_PATH': libdir}
self.init(testdir, extra_args=['-Dc_link_args="-L{}"'.format(libdir)],
override_envvars=env)
self.build()
self.run_tests()
self.run_tests(override_envvars=run_env)
def should_run_cross_arm_tests():
return shutil.which('arm-linux-gnueabihf-gcc') and not platform.machine().lower().startswith('arm')

@ -0,0 +1,4 @@
int func5()
{
return 1;
}

@ -0,0 +1,6 @@
int func5();
int func6()
{
return func5() + 1;
}

@ -1,5 +1,7 @@
project('test static link libs', 'c')
pkg = import('pkgconfig')
# libfunc2 should contain both func1() and func2() symbols
libfunc1 = static_library('func1', 'func1.c',
install : false)
@ -14,3 +16,13 @@ libfunc3 = static_library('func3', 'func3.c',
libfunc4 = static_library('func4', 'func4.c',
link_with : libfunc3,
install : true)
# Same as above, but also generate an pkg-config file. Use both_libraries() to
# make sure a complete .pc file gets generated. libfunc5 should not be mentioned
# into the .pc file because it's not installed.
libfunc5 = static_library('func5', 'func5.c',
install : false)
libfunc6 = both_libraries('func6', 'func6.c',
link_with : libfunc5,
install : true)
pkg.generate(libfunc6)

@ -9,3 +9,11 @@ test('test1', executable('test1', 'test1.c', dependencies : func2_dep))
# Verify that installed libfunc4.a is usable
func4_dep = cc.find_library('func4')
test('test2', executable('test2', 'test2.c', dependencies : func4_dep))
# Verify that installed pkg-config file is usable for both shared and static link
func6_static_dep = dependency('func6', static : true)
test('test3-static', executable('test3-static', 'test3.c',
dependencies : func6_static_dep))
func6_shared_dep = dependency('func6', static : false)
test('test3-shared', executable('test3-shared', 'test3.c',
dependencies : func6_shared_dep))

@ -0,0 +1,6 @@
int func6();
int main(int argc, char *argv[])
{
return func6() == 2 ? 0 : 1;
}
Loading…
Cancel
Save