build: Fix linking multiple libraries and some are promoted

When a link() is promoted to link_whole() we still have to handle the
rest of the list.

Fixes: #11956
pull/11960/head
Xavier Claessens 2 years ago committed by Jussi Pakkanen
parent ad13d9f4a3
commit cd63853ad2
  1. 3
      mesonbuild/build.py
  2. 9
      test cases/unit/113 complex link cases/meson.build
  3. 1
      unittests/linuxliketests.py

@ -1398,7 +1398,8 @@ You probably should put it in link_with instead.''')
elif t.is_internal():
# When we're a static library and we link_with to an
# internal/convenience library, promote to link_whole.
return self.link_whole([t])
self.link_whole([t])
continue
if not isinstance(t, (Target, CustomTargetIndex)):
if isinstance(t, dependencies.ExternalLibrary):
raise MesonException(textwrap.dedent('''\

@ -38,3 +38,12 @@ s1 = static_library('t6-s1', 's1.c')
s2 = static_library('t6-s2', 's2.c', link_with: s1, install: true)
s3 = static_library('t6-s3', 's3.c', link_with: s2, install: true)
e = executable('t6-e1', 'main.c', link_with: s3)
# Regression test: s1 gets promoted to link_whole and that used to make all other
# libraries in the list (s2) to be ignored.
# Executable only needs to link with s3.
# See https://github.com/mesonbuild/meson/issues/11956.
s1 = static_library('t7-s1', 's1.c')
s2 = static_library('t7-s2', 's2.c')
s3 = static_library('t7-s3', 's3.c', link_with: [s1, s2], install: true)
e = executable('t7-e1', 'main.c', link_with: s3)

@ -1845,3 +1845,4 @@ class LinuxlikeTests(BasePlatformTests):
self.assertIn('build t4-e1: c_LINKER t4-e1.p/main.c.o | libt4-s2.so.p/libt4-s2.so.symbols libt4-s3.a\n', content)
self.assertIn('build t5-e1: c_LINKER t5-e1.p/main.c.o | libt5-s1.so.p/libt5-s1.so.symbols libt5-s3.a\n', content)
self.assertIn('build t6-e1: c_LINKER t6-e1.p/main.c.o | libt6-s2.a libt6-s3.a\n', content)
self.assertIn('build t7-e1: c_LINKER t7-e1.p/main.c.o | libt7-s3.a\n', content)

Loading…
Cancel
Save