Rewriter infodump modifications

pull/4858/head
Daniel Mensinger 6 years ago
parent be3c58d638
commit 8bb942ef25
No known key found for this signature in database
GPG Key ID: 54DD94C131E277D4
  1. 20
      mesonbuild/rewriter.py
  2. 13
      run_unittests.py

@ -299,6 +299,7 @@ class Rewriter:
'kwargs': self.process_kwargs, 'kwargs': self.process_kwargs,
'target': self.process_target, 'target': self.process_target,
} }
self.info_dump = None
def analyze_meson(self): def analyze_meson(self):
mlog.log('Analyzing meson file:', mlog.bold(os.path.join(self.sourcedir, environment.build_filename))) 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(AstIndentationGenerator())
self.interpreter.ast.accept(self.id_generator) 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 find_target(self, target: str):
def check_list(name: str): def check_list(name: str):
for i in self.interpreter.targets: for i in self.interpreter.targets:
@ -322,7 +338,6 @@ class Rewriter:
# Check the assignments # Check the assignments
if target in self.interpreter.assignments: if target in self.interpreter.assignments:
node = self.interpreter.assignments[target][0] node = self.interpreter.assignments[target][0]
print(node)
if isinstance(node, mparser.FunctionNode): if isinstance(node, mparser.FunctionNode):
if node.func_name in ['executable', 'jar', 'library', 'shared_library', 'shared_module', 'static_library', 'both_libraries']: if node.func_name in ['executable', 'jar', 'library', 'shared_library', 'shared_module', 'static_library', 'both_libraries']:
name = self.interpreter.flatten_args(node.args)[0] name = self.interpreter.flatten_args(node.args)[0]
@ -489,7 +504,7 @@ class Rewriter:
'name': target['name'], 'name': target['name'],
'sources': src_list '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): def process(self, cmd):
if 'type' not in cmd: if 'type' not in cmd:
@ -601,4 +616,5 @@ def run(options):
rewriter.process(i) rewriter.process(i)
rewriter.apply_changes() rewriter.apply_changes()
rewriter.print_info()
return 0 return 0

@ -5022,7 +5022,7 @@ class PythonTests(BasePlatformTests):
class RewriterTests(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): def setUp(self):
super().setUp() super().setUp()
@ -5045,17 +5045,10 @@ class RewriterTests(BasePlatformTests):
return p.stdout return p.stdout
def extract_test_data(self, out): def extract_test_data(self, out):
lines = out.split('\n') match = RewriterTests.data_regex.match(out)
result = {} result = {}
for i in lines:
match = RewriterTests.data_regex.match(i)
if match: if match:
typ = match.group(1) result = json.loads(match.group(1))
id = match.group(2)
data = json.loads(match.group(3))
if typ not in result:
result[typ] = {}
result[typ][id] = data
return result return result
def test_target_source_list(self): def test_target_source_list(self):

Loading…
Cancel
Save