From 7199cd2095127770600b1c54eea53b044ce462c3 Mon Sep 17 00:00:00 2001 From: Daniel Mensinger Date: Sat, 2 Mar 2019 12:06:07 +0100 Subject: [PATCH] rewriter: Avoid duplicates --- mesonbuild/rewriter.py | 12 +++++++++++- test cases/rewrite/1 basic/addSrc.json | 4 ++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/mesonbuild/rewriter.py b/mesonbuild/rewriter.py index bd00ff888..fc4c2cf9d 100644 --- a/mesonbuild/rewriter.py +++ b/mesonbuild/rewriter.py @@ -573,9 +573,19 @@ class Rewriter: node = target['node'] assert(node is not None) + # Generate the current source list + src_list = [] + for i in target['sources']: + for j in arg_list_from_node(i): + if isinstance(j, StringNode): + src_list += [j.value] + # Generate the new String nodes to_append = [] - for i in cmd['sources']: + for i in sorted(set(cmd['sources'])): + if i in src_list: + mlog.log(' -- Source', mlog.green(i), 'is already defined for the target --> skipping') + continue mlog.log(' -- Adding source', mlog.green(i), 'at', mlog.yellow('{}:{}'.format(os.path.join(node.subdir, environment.build_filename), node.lineno))) token = Token('string', node.subdir, 0, 0, 0, None, i) diff --git a/test cases/rewrite/1 basic/addSrc.json b/test cases/rewrite/1 basic/addSrc.json index 9d6dafd64..7b6144a79 100644 --- a/test cases/rewrite/1 basic/addSrc.json +++ b/test cases/rewrite/1 basic/addSrc.json @@ -3,7 +3,7 @@ "type": "target", "target": "trivialprog1", "operation": "src_add", - "sources": ["a1.cpp", "a2.cpp"] + "sources": ["a1.cpp", "a2.cpp", "a1.cpp"] }, { "type": "target", @@ -39,7 +39,7 @@ "type": "target", "target": "trivialprog9", "operation": "src_add", - "sources": ["a6.cpp"] + "sources": ["a6.cpp", "a1.cpp"] }, { "type": "target",