aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Hollerbach <mail@marcel-hollerbach.de>2020-06-09 22:40:23 +0200
committerJussi Pakkanen <jpakkane@gmail.com>2020-06-11 01:42:59 +0300
commit18b99b3bc319f84db78ff489d6ca5e0cc0273bcc (patch)
tree973c5b66ad0424feb6dfa839f82fb5fd2053d9d2
parent71d68a940bdb31f0d66448fa9bde9abf403b54f2 (diff)
downloadmeson-18b99b3bc319f84db78ff489d6ca5e0cc0273bcc.zip
meson-18b99b3bc319f84db78ff489d6ca5e0cc0273bcc.tar.gz
meson-18b99b3bc319f84db78ff489d6ca5e0cc0273bcc.tar.bz2
compilers: corretify deduplication direction
so: when building compile args, meson is deduplicating flags. When a compiler argument is appended, a later appearance of a dedup'ed is going to remove a earlier one. If the argument is prepended, the element *before* the new one is going to be removed. And that is where the problem reported in https://github.com/mesonbuild/meson/pull/7119 is coming in. In the revision linked there, the order of replacement in the prepend case was revesered. With this patch, we restore this behaviour again.
-rw-r--r--mesonbuild/compilers/compilers.py4
-rwxr-xr-xrun_unittests.py19
2 files changed, 21 insertions, 2 deletions
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py
index 50e2188..f427262 100644
--- a/mesonbuild/compilers/compilers.py
+++ b/mesonbuild/compilers/compilers.py
@@ -481,10 +481,10 @@ class CompilerArgs(collections.abc.MutableSequence):
post_flush_set = set()
#The two lists are here walked from the front to the back, in order to not need removals for deduplication
- for a in reversed(self.pre):
+ for a in self.pre:
dedup = self._can_dedup(a)
if a not in pre_flush_set:
- pre_flush.appendleft(a)
+ pre_flush.append(a)
if dedup == 2:
pre_flush_set.add(a)
for a in reversed(self.post):
diff --git a/run_unittests.py b/run_unittests.py
index a6817c3..9572b27 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -350,6 +350,25 @@ class InternalTests(unittest.TestCase):
stat.S_IRWXU | stat.S_ISUID |
stat.S_IRGRP | stat.S_IXGRP)
+ def test_compiler_args_class_none_flush(self):
+ cargsfunc = mesonbuild.compilers.CompilerArgs
+ cc = mesonbuild.compilers.CCompiler([], 'fake', False, MachineChoice.HOST, mock.Mock())
+ a = cargsfunc(cc, ['-I.'])
+ #first we are checking if the tree construction deduplicates the correct -I argument
+ a += ['-I..']
+ a += ['-I./tests/']
+ a += ['-I./tests2/']
+ #think this here as assertion, we cannot apply it, otherwise the CompilerArgs would already flush the changes:
+ # assertEqual(a, ['-I.', '-I./tests2/', '-I./tests/', '-I..', '-I.'])
+ a += ['-I.']
+ a += ['-I.', '-I./tests/']
+ self.assertEqual(a, ['-I.', '-I./tests/', '-I./tests2/', '-I..'])
+
+ #then we are checking that when CompilerArgs already have a build container list, that the deduplication is taking the correct one
+ a += ['-I.', '-I./tests2/']
+ self.assertEqual(a, ['-I.', '-I./tests2/', '-I./tests/', '-I..'])
+
+
def test_compiler_args_class(self):
cargsfunc = mesonbuild.compilers.CompilerArgs
cc = mesonbuild.compilers.CCompiler([], 'fake', False, MachineChoice.HOST, mock.Mock())