From d23e6b34c77f1e6bee8ab475ab05e3f5250949e7 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Mon, 12 Jun 2017 20:55:19 +0530 Subject: Preserve -L -l pairings fetched from external deps While adding link args for external deps, sometimes different libraries come from different prefixes, and an older version of the same library might be present in other prefixes and we don't want to accidentally pick that up. For example: /usr/local/lib/libglib-2.0.so /usr/local/lib/pkgconfig/glib-2.0.pc /usr/local/lib/libz.so /usr/local/lib/pkgconfig/zlib.pc /home/mesonuser/.local/lib/libglib-2.0.so /home/mesonuser/.local/lib/pkgconfig/glib-2.0.pc PKG_CONFIG_PATH="/home/mesonuser/.local/lib/pkgconfig/:/usr/local/lib/pkgconfig/" If a target uses `dependencies : [glib_dep, zlib_dep]`, it will end up using /usr/local/lib/libglib-2.0.so instead of /home/mesonuser/.local/lib/libglib-2.0.so despite using the pkg-config file in /home/mesonuser/.local/lib/pkgconfig because we reorder the -L flag and separate it from the -l flag. With this change, external link arguments will be added to the compiler list without de-dup or reordering. Closes https://github.com/mesonbuild/meson/issues/1718 --- run_unittests.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'run_unittests.py') diff --git a/run_unittests.py b/run_unittests.py index dbfd638..9f39890 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -176,6 +176,16 @@ class InternalTests(unittest.TestCase): l += ['-lbar'] self.assertEqual(l, ['-Lbardir', '-Lfoodir', '-lfoo', '-lbar']) + ## Test that 'direct' append and extend works + l = cargsfunc(c, ['-Lfoodir', '-lfoo']) + self.assertEqual(l, ['-Lfoodir', '-lfoo']) + # Direct-adding a library and a libpath appends both correctly + l.extend_direct(['-Lbardir', '-lbar']) + self.assertEqual(l, ['-Lfoodir', '-lfoo', '-Lbardir', '-lbar']) + # Direct-adding the same library again still adds it + l.append_direct('-lbar') + self.assertEqual(l, ['-Lfoodir', '-lfoo', '-Lbardir', '-lbar', '-lbar']) + def test_commonpath(self): from os.path import sep commonpath = mesonbuild.mesonlib.commonpath -- cgit v1.1 From 8244f4c6a6436a7ddf585592c184714f803cfef8 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Sun, 11 Jun 2017 21:45:12 +0300 Subject: Created unit test to ensure linker arguments from consecutive dependencies are kept in order. --- run_unittests.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'run_unittests.py') diff --git a/run_unittests.py b/run_unittests.py index 9f39890..ab41f54 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -1755,6 +1755,22 @@ class LinuxlikeTests(BasePlatformTests): env['LD_LIBRARY_PATH'] = installed_libdir self.assertEqual(subprocess.call(installed_exe, env=env), 0) + def test_order_of_l_arguments(self): + testdir = os.path.join(self.unit_test_dir, '8 L order') + os.environ['PKG_CONFIG_PATH'] = testdir + self.init(testdir) + expected_order = ['-L/me/first', '-L/me/second', '-L/me/third', '-L/me/fourth'] + with open(os.path.join(self.builddir, 'build.ninja')) as ifile: + for line in ifile: + if expected_order[0] in line: + previous_index = line.index(expected_order[0]) + for entry in expected_order[1:]: + current_index = line.index(entry) + self.assertLess(previous_index, current_index) + previous_index = current_index + return + raise RuntimeError('Linker entries not found in the Ninja file.') + class LinuxArmCrossCompileTests(BasePlatformTests): ''' Tests that verify cross-compilation to Linux/ARM -- cgit v1.1 From 1865425b4bbf87f9198353dd730de748680d3979 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Mon, 12 Jun 2017 22:39:33 +0530 Subject: tests/unit/8: Rename to 9 and add -l flags --- run_unittests.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'run_unittests.py') diff --git a/run_unittests.py b/run_unittests.py index ab41f54..a405b01 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -1756,10 +1756,13 @@ class LinuxlikeTests(BasePlatformTests): self.assertEqual(subprocess.call(installed_exe, env=env), 0) def test_order_of_l_arguments(self): - testdir = os.path.join(self.unit_test_dir, '8 L order') + testdir = os.path.join(self.unit_test_dir, '9 -L -l order') os.environ['PKG_CONFIG_PATH'] = testdir self.init(testdir) - expected_order = ['-L/me/first', '-L/me/second', '-L/me/third', '-L/me/fourth'] + # NOTE: .pc file has -Lfoo -lfoo -Lbar -lbar but pkg-config reorders + # the flags before returning them to -Lfoo -Lbar -lfoo -lbar + expected_order = ['-L/me/first', '-L/me/second','-lfoo1', '-lfoo2', + '-L/me/third', '-L/me/fourth', '-lfoo3', '-lfoo4'] with open(os.path.join(self.builddir, 'build.ninja')) as ifile: for line in ifile: if expected_order[0] in line: -- cgit v1.1