From 8bb942ef25c40014ca952e26fc70f927ab1694ff Mon Sep 17 00:00:00 2001 From: Daniel Mensinger Date: Thu, 31 Jan 2019 14:56:19 +0100 Subject: [PATCH] Rewriter infodump modifications --- mesonbuild/rewriter.py | 20 ++++++++++++++++++-- run_unittests.py | 15 ++++----------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/mesonbuild/rewriter.py b/mesonbuild/rewriter.py index de39f6362..aea185b1f 100644 --- a/mesonbuild/rewriter.py +++ b/mesonbuild/rewriter.py @@ -299,6 +299,7 @@ class Rewriter: 'kwargs': self.process_kwargs, 'target': self.process_target, } + self.info_dump = None def analyze_meson(self): mlog.log('Analyzing meson file:', mlog.bold(os.path.join(self.sourcedir, environment.build_filename))) @@ -308,6 +309,21 @@ class Rewriter: self.interpreter.ast.accept(AstIndentationGenerator()) self.interpreter.ast.accept(self.id_generator) + def add_info(self, cmd_type: str, cmd_id: str, data: dict): + if self.info_dump is None: + self.info_dump = {} + if cmd_type not in self.info_dump: + self.info_dump[cmd_type] = {} + self.info_dump[cmd_type][cmd_id] = data + + def print_info(self): + if self.info_dump is None: + return + # Wrap the dump in magic strings + print('!!==JSON DUMP: BEGIN==!!') + print(json.dumps(self.info_dump, indent=2)) + print('!!==JSON DUMP: END==!!') + def find_target(self, target: str): def check_list(name: str): for i in self.interpreter.targets: @@ -322,7 +338,6 @@ class Rewriter: # Check the assignments if target in self.interpreter.assignments: node = self.interpreter.assignments[target][0] - print(node) if isinstance(node, mparser.FunctionNode): if node.func_name in ['executable', 'jar', 'library', 'shared_library', 'shared_module', 'static_library', 'both_libraries']: name = self.interpreter.flatten_args(node.args)[0] @@ -489,7 +504,7 @@ class Rewriter: 'name': target['name'], 'sources': src_list } - mlog.log(' !! target {}={}'.format(target['id'], json.dumps(test_data))) + self.add_info('target', target['id'], test_data) def process(self, cmd): if 'type' not in cmd: @@ -601,4 +616,5 @@ def run(options): rewriter.process(i) rewriter.apply_changes() + rewriter.print_info() return 0 diff --git a/run_unittests.py b/run_unittests.py index 5539a7024..d68912f3f 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -5022,7 +5022,7 @@ class PythonTests(BasePlatformTests): class RewriterTests(BasePlatformTests): - data_regex = re.compile(r'^\s*!!\s*(\w+)\s+([^=]+)=(.*)$') + data_regex = re.compile(r'.*\n!!==JSON DUMP: BEGIN==!!\n(.*)\n!!==JSON DUMP: END==!!\n', re.MULTILINE | re.DOTALL) def setUp(self): super().setUp() @@ -5045,17 +5045,10 @@ class RewriterTests(BasePlatformTests): return p.stdout def extract_test_data(self, out): - lines = out.split('\n') + match = RewriterTests.data_regex.match(out) result = {} - for i in lines: - match = RewriterTests.data_regex.match(i) - if match: - typ = match.group(1) - id = match.group(2) - data = json.loads(match.group(3)) - if typ not in result: - result[typ] = {} - result[typ][id] = data + if match: + result = json.loads(match.group(1)) return result def test_target_source_list(self):