pkgconfig: Include dependencies of uninstalled static libraries

This commit is contained in:
Xavier Claessens 2019-09-18 23:50:12 -04:00 committed by Xavier Claessens
parent dc5ad1fad9
commit 19fc692b25
7 changed files with 56 additions and 17 deletions

View File

@ -974,20 +974,17 @@ This will become a hard error in a future Meson release.''')
transitive_deps = []
if exclude is None:
exclude = []
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
# `Libs:` and `Libs.private:` lists in pkg-config files.
link_targets = self.link_targets
for t in link_targets:
for t in itertools.chain(self.link_targets, self.link_whole_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)
# When generating `Libs:` and `Libs.private:` lists in pkg-config
# files we don't want to include static libraries that we link_whole
# or are uninstalled (they're implicitly promoted to link_whole).
# But we still need to include their transitive dependencies,
# a static library we link_whole would itself link to a shared
# library or an installed static library.
if not for_pkgconfig or (not t.is_internal() and t not in self.link_whole_targets):
transitive_deps.append(t)
if isinstance(t, StaticLibrary):
transitive_deps += t.get_dependencies(transitive_deps + exclude, for_pkgconfig)
return transitive_deps
@ -1114,11 +1111,7 @@ You probably should put it in link_with instead.''')
# When we're a static library and we link_whole: to another static
# library, we need to add that target's objects to ourselves.
self.objects.append(t.extract_all_objects())
# Add internal and external deps
self.external_deps += t.external_deps
self.link_targets += t.link_targets
else:
self.link_whole_targets.append(t)
self.link_whole_targets.append(t)
def add_pch(self, language, pchlist):
if not pchlist:

View File

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

View File

@ -0,0 +1,6 @@
int func7();
int func8()
{
return func7() + 1;
}

View File

@ -0,0 +1,6 @@
int func8();
int func9()
{
return func8() + 1;
}

View File

@ -26,3 +26,18 @@ libfunc6 = both_libraries('func6', 'func6.c',
link_with : libfunc5,
install : true)
pkg.generate(libfunc6)
# libfunc9 should contain both func8() and func9() but not func7() because that
# one gets installed. Also test that link_with and link_whole works the same way
# because libfunc8 is uninstalled.
libfunc7 = static_library('func7', 'func7.c',
install : true)
libfunc8 = static_library('func8', 'func8.c',
link_with : libfunc7,
install : false)
libfunc9_linkwith = static_library('func9_linkwith', 'func9.c',
link_with : libfunc8,
install : true)
libfunc9_linkwhole = static_library('func9_linkwhole', 'func9.c',
link_whole : libfunc8,
install : true)

View File

@ -17,3 +17,12 @@ test('test3-static', executable('test3-static', 'test3.c',
func6_shared_dep = dependency('func6', static : false)
test('test3-shared', executable('test3-shared', 'test3.c',
dependencies : func6_shared_dep))
# Verify that installed libfunc9.a contains func8() and func8() but not func7()
func7_dep = cc.find_library('func7')
func9_linkwhole_dep = cc.find_library('func9_linkwhole')
test('test4-linkwhole', executable('test4-linkwhole', 'test4.c',
dependencies : [func7_dep, func9_linkwhole_dep]))
func9_linkwith_dep = cc.find_library('func9_linkwith')
test('test4-linkwith', executable('test4-linkwith', 'test4.c',
dependencies : [func7_dep, func9_linkwith_dep]))

View File

@ -0,0 +1,6 @@
int func9();
int main(int argc, char *argv[])
{
return func9() == 3 ? 0 : 1;
}