aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mesonbuild/compilers/compilers.py14
-rwxr-xr-xrun_unittests.py37
2 files changed, 39 insertions, 12 deletions
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py
index 5af4b5d..95f937d 100644
--- a/mesonbuild/compilers/compilers.py
+++ b/mesonbuild/compilers/compilers.py
@@ -602,16 +602,20 @@ class CompilerArgs(list):
return True
return False
- def to_native(self):
+ def to_native(self, copy=False):
# Check if we need to add --start/end-group for circular dependencies
# between static libraries, and for recursively searching for symbols
# needed by static libraries that are provided by object files or
# shared libraries.
+ if copy:
+ new = self.copy()
+ else:
+ new = self
if get_compiler_uses_gnuld(self.compiler):
global soregex
group_start = -1
group_end = -1
- for i, each in enumerate(self):
+ for i, each in enumerate(new):
if not each.startswith('-l') and not each.endswith('.a') and \
not soregex.match(each):
continue
@@ -621,9 +625,9 @@ class CompilerArgs(list):
group_start = i
if group_start >= 0:
# Last occurrence of a library
- self.insert(group_end + 1, '-Wl,--end-group')
- self.insert(group_start, '-Wl,--start-group')
- return self.compiler.unix_args_to_native(self)
+ new.insert(group_end + 1, '-Wl,--end-group')
+ new.insert(group_start, '-Wl,--start-group')
+ return self.compiler.unix_args_to_native(new)
def append_direct(self, arg):
'''
diff --git a/run_unittests.py b/run_unittests.py
index f4c50a5..5da2798 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -168,19 +168,19 @@ class InternalTests(unittest.TestCase):
def test_compiler_args_class(self):
cargsfunc = mesonbuild.compilers.CompilerArgs
- c = mesonbuild.compilers.CCompiler([], 'fake', False)
+ cc = mesonbuild.compilers.CCompiler([], 'fake', False)
# Test that bad initialization fails
self.assertRaises(TypeError, cargsfunc, [])
self.assertRaises(TypeError, cargsfunc, [], [])
- self.assertRaises(TypeError, cargsfunc, c, [], [])
+ self.assertRaises(TypeError, cargsfunc, cc, [], [])
# Test that empty initialization works
- a = cargsfunc(c)
+ a = cargsfunc(cc)
self.assertEqual(a, [])
# Test that list initialization works
- a = cargsfunc(['-I.', '-I..'], c)
+ a = cargsfunc(['-I.', '-I..'], cc)
self.assertEqual(a, ['-I.', '-I..'])
# Test that there is no de-dup on initialization
- self.assertEqual(cargsfunc(['-I.', '-I.'], c), ['-I.', '-I.'])
+ self.assertEqual(cargsfunc(['-I.', '-I.'], cc), ['-I.', '-I.'])
## Test that appending works
a.append('-I..')
@@ -226,7 +226,7 @@ class InternalTests(unittest.TestCase):
self.assertEqual(a, ['-Ibar', '-Ifoo', '-Ibaz', '-I..', '-I.', '-Ldir', '-Lbah', '-Werror', '-O3', '-O2', '-Wall'])
## Test that adding libraries works
- l = cargsfunc(c, ['-Lfoodir', '-lfoo'])
+ l = cargsfunc(cc, ['-Lfoodir', '-lfoo'])
self.assertEqual(l, ['-Lfoodir', '-lfoo'])
# Adding a library and a libpath appends both correctly
l += ['-Lbardir', '-lbar']
@@ -236,7 +236,7 @@ class InternalTests(unittest.TestCase):
self.assertEqual(l, ['-Lbardir', '-Lfoodir', '-lfoo', '-lbar'])
## Test that 'direct' append and extend works
- l = cargsfunc(c, ['-Lfoodir', '-lfoo'])
+ l = cargsfunc(cc, ['-Lfoodir', '-lfoo'])
self.assertEqual(l, ['-Lfoodir', '-lfoo'])
# Direct-adding a library and a libpath appends both correctly
l.extend_direct(['-Lbardir', '-lbar'])
@@ -251,6 +251,29 @@ class InternalTests(unittest.TestCase):
l.append_direct('/libbaz.a')
self.assertEqual(l, ['-Lfoodir', '-lfoo', '-Lbardir', '-lbar', '-lbar', '/libbaz.a'])
+ def test_compiler_args_class_gnuld(self):
+ cargsfunc = mesonbuild.compilers.CompilerArgs
+ ## Test --start/end-group
+ gcc = mesonbuild.compilers.GnuCCompiler([], 'fake', 0, False)
+ ## Test that 'direct' append and extend works
+ l = cargsfunc(gcc, ['-Lfoodir', '-lfoo'])
+ self.assertEqual(l.to_native(copy=True), ['-Lfoodir', '-Wl,--start-group', '-lfoo', '-Wl,--end-group'])
+ # Direct-adding a library and a libpath appends both correctly
+ l.extend_direct(['-Lbardir', '-lbar'])
+ self.assertEqual(l.to_native(copy=True), ['-Lfoodir', '-Wl,--start-group', '-lfoo', '-Lbardir', '-lbar', '-Wl,--end-group'])
+ # Direct-adding the same library again still adds it
+ l.append_direct('-lbar')
+ self.assertEqual(l.to_native(copy=True), ['-Lfoodir', '-Wl,--start-group', '-lfoo', '-Lbardir', '-lbar', '-lbar', '-Wl,--end-group'])
+ # Direct-adding with absolute path deduplicates
+ l.append_direct('/libbaz.a')
+ self.assertEqual(l.to_native(copy=True), ['-Lfoodir', '-Wl,--start-group', '-lfoo', '-Lbardir', '-lbar', '-lbar', '/libbaz.a', '-Wl,--end-group'])
+ # Adding libbaz again does nothing
+ l.append_direct('/libbaz.a')
+ self.assertEqual(l.to_native(copy=True), ['-Lfoodir', '-Wl,--start-group', '-lfoo', '-Lbardir', '-lbar', '-lbar', '/libbaz.a', '-Wl,--end-group'])
+ # Adding a non-library argument doesn't include it in the group
+ l += ['-Lfoo', '-Wl,--export-dynamic']
+ self.assertEqual(l.to_native(copy=True), ['-Lfoo', '-Lfoodir', '-Wl,--start-group', '-lfoo', '-Lbardir', '-lbar', '-lbar', '/libbaz.a', '-Wl,--end-group', '-Wl,--export-dynamic'])
+
def test_string_templates_substitution(self):
dictfunc = mesonbuild.mesonlib.get_filenames_templates_dict
substfunc = mesonbuild.mesonlib.substitute_values