aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2017-06-12 21:26:09 +0300
committerGitHub <noreply@github.com>2017-06-12 21:26:09 +0300
commit1944a7a66d594b60eea32f76e049810d8adb0ed5 (patch)
tree104481bbbb8e1661718a1492f7b5ef0ffa88c6da
parentda64da3617f5327e4db866daf77668477ddb5e77 (diff)
parent1865425b4bbf87f9198353dd730de748680d3979 (diff)
downloadmeson-1944a7a66d594b60eea32f76e049810d8adb0ed5.zip
meson-1944a7a66d594b60eea32f76e049810d8adb0ed5.tar.gz
meson-1944a7a66d594b60eea32f76e049810d8adb0ed5.tar.bz2
Merge pull request #1932 from centricular/fix-libpath-reordering
Preserve -L -l pairings fetched from external deps
-rw-r--r--mesonbuild/backend/ninjabackend.py6
-rw-r--r--mesonbuild/backend/vs2010backend.py6
-rw-r--r--mesonbuild/compilers.py13
-rwxr-xr-xrun_unittests.py29
-rw-r--r--test cases/unit/9 -L -l order/first.pc13
-rw-r--r--test cases/unit/9 -L -l order/meson.build6
-rw-r--r--test cases/unit/9 -L -l order/prog.c5
-rw-r--r--test cases/unit/9 -L -l order/second.pc13
8 files changed, 87 insertions, 4 deletions
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
index 8a2ee9a..9a48c4e 100644
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -2294,11 +2294,13 @@ rule FORTRAN_DEP_HACK
commands += target.link_args
# External deps must be last because target link libraries may depend on them.
for dep in target.get_external_deps():
- commands += dep.get_link_args()
+ # Extend without reordering or de-dup to preserve `-L -l` sets
+ # https://github.com/mesonbuild/meson/issues/1718
+ commands.extend_direct(dep.get_link_args())
for d in target.get_dependencies():
if isinstance(d, build.StaticLibrary):
for dep in d.get_external_deps():
- commands += dep.get_link_args()
+ commands.extend_direct(dep.get_link_args())
# Add link args for c_* or cpp_* build options. Currently this only
# adds c_winlibs and cpp_winlibs when building for Windows. This needs
# to be after all internal and external libraries so that unresolved
diff --git a/mesonbuild/backend/vs2010backend.py b/mesonbuild/backend/vs2010backend.py
index d4a7a19..57b0437 100644
--- a/mesonbuild/backend/vs2010backend.py
+++ b/mesonbuild/backend/vs2010backend.py
@@ -908,11 +908,13 @@ class Vs2010Backend(backends.Backend):
extra_link_args += target.link_args
# External deps must be last because target link libraries may depend on them.
for dep in target.get_external_deps():
- extra_link_args += dep.get_link_args()
+ # Extend without reordering or de-dup to preserve `-L -l` sets
+ # https://github.com/mesonbuild/meson/issues/1718
+ extra_link_args.extend_direct(dep.get_link_args())
for d in target.get_dependencies():
if isinstance(d, build.StaticLibrary):
for dep in d.get_external_deps():
- extra_link_args += dep.get_link_args()
+ extra_link_args.extend_direct(dep.get_link_args())
# Add link args for c_* or cpp_* build options. Currently this only
# adds c_winlibs and cpp_winlibs when building for Windows. This needs
# to be after all internal and external libraries so that unresolved
diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py
index 80d12a0..2b54cc8 100644
--- a/mesonbuild/compilers.py
+++ b/mesonbuild/compilers.py
@@ -465,6 +465,19 @@ class CompilerArgs(list):
self.insert(i + 1, '-Wl,--end-group')
return self.compiler.unix_args_to_native(self)
+ def append_direct(self, arg):
+ '''
+ Append the specified argument without any reordering or de-dup
+ '''
+ super().append(arg)
+
+ def extend_direct(self, iterable):
+ '''
+ Extend using the elements in the specified iterable without any
+ reordering or de-dup
+ '''
+ super().extend(iterable)
+
def __add__(self, args):
new = CompilerArgs(self, self.compiler)
new += args
diff --git a/run_unittests.py b/run_unittests.py
index dbfd638..a405b01 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
@@ -1745,6 +1755,25 @@ 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, '9 -L -l order')
+ os.environ['PKG_CONFIG_PATH'] = testdir
+ self.init(testdir)
+ # 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:
+ 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
diff --git a/test cases/unit/9 -L -l order/first.pc b/test cases/unit/9 -L -l order/first.pc
new file mode 100644
index 0000000..3b811b2
--- /dev/null
+++ b/test cases/unit/9 -L -l order/first.pc
@@ -0,0 +1,13 @@
+prefix=/usr
+exec_prefix=${prefix}
+libdir=${prefix}/lib/x86_64-linux-gnu
+sharedlibdir=${libdir}
+includedir=${prefix}/include
+
+Name: jonne
+Description: jonne library
+Version: 1.0.0
+
+Requires:
+Libs: -L/me/first -lfoo1 -L/me/second -lfoo2
+Cflags: -I${includedir}
diff --git a/test cases/unit/9 -L -l order/meson.build b/test cases/unit/9 -L -l order/meson.build
new file mode 100644
index 0000000..cfcf033
--- /dev/null
+++ b/test cases/unit/9 -L -l order/meson.build
@@ -0,0 +1,6 @@
+project('jonne', 'c')
+
+firstdep = dependency('first')
+seconddep = dependency('second')
+
+executable('lprog', 'prog.c', dependencies : [firstdep, seconddep])
diff --git a/test cases/unit/9 -L -l order/prog.c b/test cases/unit/9 -L -l order/prog.c
new file mode 100644
index 0000000..3a16ac3
--- /dev/null
+++ b/test cases/unit/9 -L -l order/prog.c
@@ -0,0 +1,5 @@
+#include<stdio.h>
+
+int main(int argc, char **argv) {
+ return 0;
+}
diff --git a/test cases/unit/9 -L -l order/second.pc b/test cases/unit/9 -L -l order/second.pc
new file mode 100644
index 0000000..196824b
--- /dev/null
+++ b/test cases/unit/9 -L -l order/second.pc
@@ -0,0 +1,13 @@
+prefix=/usr
+exec_prefix=${prefix}
+libdir=${prefix}/lib/x86_64-linux-gnu
+sharedlibdir=${libdir}
+includedir=${prefix}/include
+
+Name: jonne2
+Description: jonne2 library
+Version: 1.0.0
+
+Requires:
+Libs: -L/me/third -lfoo3 -L/me/fourth -lfoo4
+Cflags: -I${includedir}