From a78af236862008f284d84ab9327a38886e086d8c Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Wed, 26 Apr 2023 10:05:19 -0400 Subject: Fix niche cases when linking static libs Case 1: - Prog links to static lib A - A link_whole to static lib B - B link to static lib C - Prog dependencies should be A and C but not B which is already included in A. Case 2: - Same as case 1, but with A being installed. - To be useful, A must also include all objects from C that is not installed. - Prog only need to link on A. --- unittests/linuxliketests.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'unittests') diff --git a/unittests/linuxliketests.py b/unittests/linuxliketests.py index c94169a..b1b9c4c 100644 --- a/unittests/linuxliketests.py +++ b/unittests/linuxliketests.py @@ -1828,3 +1828,20 @@ class LinuxlikeTests(BasePlatformTests): with self.assertRaises(subprocess.CalledProcessError) as e: self.run_tests() self.assertNotIn('Traceback', e.exception.output) + + @skipUnless(is_linux(), "Ninja file differs on different platforms") + def test_complex_link_cases(self): + testdir = os.path.join(self.unit_test_dir, '113 complex link cases') + self.init(testdir) + self.build() + with open(os.path.join(self.builddir, 'build.ninja'), encoding='utf-8') as f: + content = f.read() + # Verify link dependencies, see comments in meson.build. + self.assertIn('build libt1-s3.a: STATIC_LINKER libt1-s2.a.p/s2.c.o libt1-s3.a.p/s3.c.o\n', content) + self.assertIn('build t1-e1: c_LINKER t1-e1.p/main.c.o | libt1-s1.a libt1-s3.a\n', content) + self.assertIn('build libt2-s3.a: STATIC_LINKER libt2-s2.a.p/s2.c.o libt2-s1.a.p/s1.c.o libt2-s3.a.p/s3.c.o\n', content) + self.assertIn('build t2-e1: c_LINKER t2-e1.p/main.c.o | libt2-s3.a\n', content) + self.assertIn('build t3-e1: c_LINKER t3-e1.p/main.c.o | libt3-s3.so.p/libt3-s3.so.symbols\n', content) + 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) -- cgit v1.1 From 3162b901cab46d66a30c66a4406195523714ecdc Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Thu, 27 Apr 2023 13:45:47 -0400 Subject: build: Process compilers before calling link() and link_whole() To take good decisions we'll need to know if we are a Rust library which is only know after processing source files and compilers. Note that is it not the final list of compilers, some can be added in process_compilers_late(), but those are compilers for which we don't have source files any way. --- unittests/allplatformstests.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'unittests') diff --git a/unittests/allplatformstests.py b/unittests/allplatformstests.py index d6ff3b0..b003ddd 100644 --- a/unittests/allplatformstests.py +++ b/unittests/allplatformstests.py @@ -4376,8 +4376,7 @@ class AllPlatformTests(BasePlatformTests): structured_sources=None, objects=[], environment=env, compilers=env.coredata.compilers[MachineChoice.HOST], kwargs={}) - target.process_compilers() - target.process_compilers_late([]) + target.process_compilers_late() return target.filename shared_lib_name = lambda name: output_name(name, SharedLibrary) -- cgit v1.1