From bd5d54513c14898535330aa807ed41a5c7c9a80a Mon Sep 17 00:00:00 2001 From: Daniel Mensinger Date: Sun, 3 Mar 2019 18:29:49 +0100 Subject: [PATCH] rewriter: Handle Arithmetic node --- mesonbuild/ast/introspection.py | 6 ++++-- run_unittests.py | 4 ++++ test cases/rewrite/1 basic/addSrc.json | 5 +++++ test cases/rewrite/1 basic/info.json | 5 +++++ test cases/rewrite/1 basic/meson.build | 1 + test cases/rewrite/1 basic/rmSrc.json | 5 +++++ test cases/rewrite/1 basic/rmTgt.json | 5 +++++ 7 files changed, 29 insertions(+), 2 deletions(-) diff --git a/mesonbuild/ast/introspection.py b/mesonbuild/ast/introspection.py index 4a6e6de7f..7544b608e 100644 --- a/mesonbuild/ast/introspection.py +++ b/mesonbuild/ast/introspection.py @@ -143,7 +143,7 @@ class IntrospectionInterpreter(AstInterpreter): def build_target(self, node, args, kwargs, targetclass): args = self.flatten_args(args) - if not args: + if not args or not isinstance(args[0], str): return kwargs = self.flatten_kwargs(kwargs, True) name = args[0] @@ -166,10 +166,12 @@ class IntrospectionInterpreter(AstInterpreter): tmp_node = self.assignments[id][0] if isinstance(tmp_node, (mparser.ArrayNode, mparser.IdNode, mparser.FunctionNode)): srcqueue += [tmp_node] + elif isinstance(curr, mparser.ArithmeticNode): + srcqueue += [curr.left, curr.right] if arg_node is None: continue elemetary_nodes = list(filter(lambda x: isinstance(x, (str, mparser.StringNode)), arg_node.arguments)) - srcqueue += list(filter(lambda x: isinstance(x, (mparser.FunctionNode, mparser.ArrayNode, mparser.IdNode)), arg_node.arguments)) + srcqueue += list(filter(lambda x: isinstance(x, (mparser.FunctionNode, mparser.ArrayNode, mparser.IdNode, mparser.ArithmeticNode)), arg_node.arguments)) # Pop the first element if the function is a build target function if isinstance(curr, mparser.FunctionNode) and curr.func_name in build_target_functions: elemetary_nodes.pop(0) diff --git a/run_unittests.py b/run_unittests.py index e13903a65..b5cb53c37 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -5158,6 +5158,7 @@ class RewriterTests(BasePlatformTests): out = self.extract_test_data(out) expected = { 'target': { + 'trivialprog0@exe': {'name': 'trivialprog0', 'sources': ['main.cpp', 'fileA.cpp', 'fileB.cpp', 'fileC.cpp']}, 'trivialprog1@exe': {'name': 'trivialprog1', 'sources': ['main.cpp', 'fileA.cpp']}, 'trivialprog2@exe': {'name': 'trivialprog2', 'sources': ['fileB.cpp', 'fileC.cpp']}, 'trivialprog3@exe': {'name': 'trivialprog3', 'sources': ['main.cpp', 'fileA.cpp']}, @@ -5177,6 +5178,7 @@ class RewriterTests(BasePlatformTests): out = self.extract_test_data(out) expected = { 'target': { + 'trivialprog0@exe': {'name': 'trivialprog0', 'sources': ['main.cpp', 'fileA.cpp', 'a1.cpp', 'a2.cpp', 'a6.cpp', 'fileB.cpp', 'fileC.cpp', 'a7.cpp']}, 'trivialprog1@exe': {'name': 'trivialprog1', 'sources': ['main.cpp', 'fileA.cpp', 'a1.cpp', 'a2.cpp', 'a6.cpp']}, 'trivialprog2@exe': {'name': 'trivialprog2', 'sources': ['fileB.cpp', 'fileC.cpp', 'a7.cpp']}, 'trivialprog3@exe': {'name': 'trivialprog3', 'sources': ['main.cpp', 'fileA.cpp', 'a5.cpp']}, @@ -5201,6 +5203,7 @@ class RewriterTests(BasePlatformTests): out = self.extract_test_data(out) expected = { 'target': { + 'trivialprog0@exe': {'name': 'trivialprog0', 'sources': ['main.cpp', 'fileC.cpp']}, 'trivialprog1@exe': {'name': 'trivialprog1', 'sources': ['main.cpp']}, 'trivialprog2@exe': {'name': 'trivialprog2', 'sources': ['fileC.cpp']}, 'trivialprog3@exe': {'name': 'trivialprog3', 'sources': ['main.cpp']}, @@ -5258,6 +5261,7 @@ class RewriterTests(BasePlatformTests): expected = { 'target': { + 'trivialprog0@exe': {'name': 'trivialprog0', 'sources': ['main.cpp', 'fileA.cpp', 'fileB.cpp', 'fileC.cpp']}, 'trivialprog1@exe': {'name': 'trivialprog1', 'sources': ['main.cpp', 'fileA.cpp']}, 'trivialprog2@exe': {'name': 'trivialprog2', 'sources': ['fileB.cpp', 'fileC.cpp']}, 'trivialprog3@exe': {'name': 'trivialprog3', 'sources': ['main.cpp', 'fileA.cpp']}, diff --git a/test cases/rewrite/1 basic/addSrc.json b/test cases/rewrite/1 basic/addSrc.json index 7b6144a79..1a8630fd1 100644 --- a/test cases/rewrite/1 basic/addSrc.json +++ b/test cases/rewrite/1 basic/addSrc.json @@ -41,6 +41,11 @@ "operation": "src_add", "sources": ["a6.cpp", "a1.cpp"] }, + { + "type": "target", + "target": "trivialprog0", + "operation": "info" + }, { "type": "target", "target": "trivialprog1", diff --git a/test cases/rewrite/1 basic/info.json b/test cases/rewrite/1 basic/info.json index 7e44bec3f..0f1a3bd8c 100644 --- a/test cases/rewrite/1 basic/info.json +++ b/test cases/rewrite/1 basic/info.json @@ -1,4 +1,9 @@ [ + { + "type": "target", + "target": "trivialprog0", + "operation": "info" + }, { "type": "target", "target": "trivialprog1", diff --git a/test cases/rewrite/1 basic/meson.build b/test cases/rewrite/1 basic/meson.build index 920553d99..0f87c4520 100644 --- a/test cases/rewrite/1 basic/meson.build +++ b/test cases/rewrite/1 basic/meson.build @@ -7,6 +7,7 @@ src4 = [src3] # Magic comment +exe0 = executable('trivialprog0', src1 + src2) exe1 = executable('trivialprog1', src1) exe2 = executable('trivialprog2', [src2]) exe3 = executable('trivialprog3', ['main.cpp', 'fileA.cpp']) diff --git a/test cases/rewrite/1 basic/rmSrc.json b/test cases/rewrite/1 basic/rmSrc.json index 86880a9bb..2e7447c68 100644 --- a/test cases/rewrite/1 basic/rmSrc.json +++ b/test cases/rewrite/1 basic/rmSrc.json @@ -35,6 +35,11 @@ "operation": "src_rm", "sources": ["fileB.cpp"] }, + { + "type": "target", + "target": "trivialprog0", + "operation": "info" + }, { "type": "target", "target": "trivialprog1", diff --git a/test cases/rewrite/1 basic/rmTgt.json b/test cases/rewrite/1 basic/rmTgt.json index ac3f3a2df..577415748 100644 --- a/test cases/rewrite/1 basic/rmTgt.json +++ b/test cases/rewrite/1 basic/rmTgt.json @@ -1,4 +1,9 @@ [ + { + "type": "target", + "target": "exe0", + "operation": "tgt_rm" + }, { "type": "target", "target": "trivialprog1",