From 57654bf36784c771fb16d90fd39ed58849d19564 Mon Sep 17 00:00:00 2001 From: Daniel Schulte Date: Wed, 11 Apr 2018 23:14:32 +0200 Subject: [PATCH] Deduplicate dependencies resolved to absolute paths If paths are absolute the order of search directories is not relevant as the path is already resolved. --- mesonbuild/compilers/compilers.py | 13 ++++++++++--- run_unittests.py | 6 ++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index a28a225f341e..69ab6ef9a6aa 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -526,15 +526,22 @@ def to_native(self): def append_direct(self, arg): ''' Append the specified argument without any reordering or de-dup + except for absolute paths where the order of include search directories + is not relevant ''' - super().append(arg) + if os.path.isabs(arg): + self.append(arg) + else: + super().append(arg) def extend_direct(self, iterable): ''' Extend using the elements in the specified iterable without any - reordering or de-dup + reordering or de-dup except for absolute paths where the order of + include search directories is not relevant ''' - super().extend(iterable) + for elem in iterable: + self.append_direct(elem) def __add__(self, args): new = CompilerArgs(self, self.compiler) diff --git a/run_unittests.py b/run_unittests.py index 4f688cd918d2..a65f15db6784 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -198,6 +198,12 @@ def test_compiler_args_class(self): # Direct-adding the same library again still adds it l.append_direct('-lbar') self.assertEqual(l, ['-Lfoodir', '-lfoo', '-Lbardir', '-lbar', '-lbar']) + # Direct-adding with absolute path deduplicates + l.append_direct('/libbaz.a') + self.assertEqual(l, ['-Lfoodir', '-lfoo', '-Lbardir', '-lbar', '-lbar', '/libbaz.a']) + # Adding libbaz again does nothing + l.append_direct('/libbaz.a') + self.assertEqual(l, ['-Lfoodir', '-lfoo', '-Lbardir', '-lbar', '-lbar', '/libbaz.a']) def test_string_templates_substitution(self): dictfunc = mesonbuild.mesonlib.get_filenames_templates_dict