diff options
author | Daniel Mensinger <daniel@mensinger-ka.de> | 2019-01-21 22:52:27 +0100 |
---|---|---|
committer | Daniel Mensinger <daniel@mensinger-ka.de> | 2019-01-22 16:41:25 +0100 |
commit | 0ce663239371576fcf4ad751d548cf2424525053 (patch) | |
tree | f7898be6e47bf6efb5362698656355e1562c561c | |
parent | 86d5799bc4d945927e26fdcb6e239905e0aa8146 (diff) | |
download | meson-0ce663239371576fcf4ad751d548cf2424525053.zip meson-0ce663239371576fcf4ad751d548cf2424525053.tar.gz meson-0ce663239371576fcf4ad751d548cf2424525053.tar.bz2 |
Added suport for adding sources to a target
-rw-r--r-- | mesonbuild/rewriter.py | 27 | ||||
-rwxr-xr-x | run_unittests.py | 19 | ||||
-rw-r--r-- | test cases/rewrite/1 basic/addSrc.json | 70 |
3 files changed, 89 insertions, 27 deletions
diff --git a/mesonbuild/rewriter.py b/mesonbuild/rewriter.py index 37099ce..9650d89 100644 --- a/mesonbuild/rewriter.py +++ b/mesonbuild/rewriter.py @@ -86,6 +86,7 @@ class Rewriter: self.sourcedir = sourcedir self.interpreter = IntrospectionInterpreter(sourcedir, '', generator) self.id_generator = AstIDGenerator() + self.modefied_nodes = [] self.functions = { 'target': self.process_target, } @@ -117,7 +118,31 @@ class Rewriter: pprint(target) if cmd['operation'] == 'src_add': - mlog.warning('TODO') + node = None + if target['sources']: + node = target['sources'][0] + else: + node = target['node'] + assert(node is not None) + + # Generate the new String nodes + to_append = [] + for i in cmd['sources']: + mlog.log(' -- Adding source', mlog.green(i), 'at', + mlog.yellow('{}:{}'.format(os.path.join(node.subdir, environment.build_filename), node.lineno))) + token = mparser.Token('string', node.subdir, 0, 0, 0, None, i) + to_append += [mparser.StringNode(token)] + + # Append to the AST at the right place + if isinstance(node, mparser.FunctionNode): + node.args.arguments += to_append + elif isinstance(node, mparser.ArrayNode): + node.args.arguments += to_append + elif isinstance(node, mparser.ArgumentNode): + node.arguments += to_append + + # Mark the node as modified + self.modefied_nodes += [node] elif cmd['operation'] == 'src_rm': mlog.warning('TODO') elif cmd['operation'] == 'test': diff --git a/run_unittests.py b/run_unittests.py index f0ab40f..0c94418 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -4965,6 +4965,25 @@ class RewriterTests(BasePlatformTests): } self.assertDictEqual(out, expected) + def test_target_add_sources(self): + self.prime('1 basic') + out = self.rewrite(self.builddir, os.path.join(self.builddir, 'addSrc.json')) + out = self.extract_test_data(out) + expected = { + 'target': { + 'trivialprog1@exe': {'name': 'trivialprog1', 'sources': ['main.cpp', 'fileA.cpp', 'a1.cpp', 'a2.cpp', 'a6.cpp']}, + 'trivialprog2@exe': {'name': 'trivialprog2', 'sources': ['fileB.cpp', 'fileC.cpp']}, + 'trivialprog3@exe': {'name': 'trivialprog3', 'sources': ['main.cpp', 'fileA.cpp', 'a5.cpp']}, + 'trivialprog4@exe': {'name': 'trivialprog4', 'sources': ['main.cpp', 'a5.cpp', 'fileA.cpp']}, + 'trivialprog5@exe': {'name': 'trivialprog5', 'sources': ['main.cpp', 'a3.cpp', 'fileB.cpp', 'fileC.cpp']}, + 'trivialprog6@exe': {'name': 'trivialprog6', 'sources': ['main.cpp', 'fileA.cpp', 'a4.cpp']}, + 'trivialprog7@exe': {'name': 'trivialprog7', 'sources': ['fileB.cpp', 'fileC.cpp', 'main.cpp', 'fileA.cpp', 'a1.cpp', 'a2.cpp', 'a6.cpp']}, + 'trivialprog8@exe': {'name': 'trivialprog8', 'sources': ['main.cpp', 'fileA.cpp', 'a1.cpp', 'a2.cpp', 'a6.cpp']}, + 'trivialprog9@exe': {'name': 'trivialprog9', 'sources': ['main.cpp', 'fileA.cpp', 'a1.cpp', 'a2.cpp', 'a6.cpp']}, + } + } + self.assertDictEqual(out, expected) + class NativeFileTests(BasePlatformTests): def setUp(self): diff --git a/test cases/rewrite/1 basic/addSrc.json b/test cases/rewrite/1 basic/addSrc.json index b609b08..6d8c599 100644 --- a/test cases/rewrite/1 basic/addSrc.json +++ b/test cases/rewrite/1 basic/addSrc.json @@ -3,63 +3,81 @@ "type": "target", "target": "trivialprog1", "operation": "src_add", - "sources": ["added1.cpp", "added2.cpp"], - "debug": true - }, - { - "type": "target", - "target": "trivialprog2", - "operation": "src_add", - "sources": ["added1.cpp"], - "debug": true + "sources": ["a1.cpp", "a2.cpp"] }, { "type": "target", "target": "trivialprog3", "operation": "src_add", - "sources": ["added1.cpp", "added2.cpp", "added3.cpp"], - "debug": true + "sources": ["a5.cpp"] }, { "type": "target", "target": "trivialprog4", "operation": "src_add", - "sources": ["added1.cpp"], - "debug": true + "sources": ["a5.cpp"] }, { "type": "target", "target": "trivialprog5", "operation": "src_add", - "sources": ["added1.cpp"], - "debug": true + "sources": ["a3.cpp"] }, { "type": "target", "target": "trivialprog6", "operation": "src_add", - "sources": ["added1.cpp"], - "debug": true + "sources": ["a4.cpp"] }, { "type": "target", - "target": "trivialprog7", + "target": "trivialprog9", "operation": "src_add", - "sources": ["added1.cpp"], - "debug": true + "sources": ["a6.cpp"] + }, + { + "type": "target", + "target": "trivialprog1", + "operation": "test" + }, + { + "type": "target", + "target": "trivialprog2", + "operation": "test" + }, + { + "type": "target", + "target": "trivialprog3", + "operation": "test" + }, + { + "type": "target", + "target": "trivialprog4", + "operation": "test" + }, + { + "type": "target", + "target": "trivialprog5", + "operation": "test" + }, + { + "type": "target", + "target": "trivialprog6", + "operation": "test" + }, + { + "type": "target", + "target": "trivialprog7", + "operation": "test" }, { "type": "target", "target": "trivialprog8", - "operation": "src_add", - "sources": ["added1.cpp"], - "debug": true + "operation": "test" }, { "type": "target", "target": "trivialprog9", - "operation": "src_add", - "sources": ["added1.cpp"], - "debug": true + "operation": "test" } ] |