Skip to content

Commit

Permalink
interpreter: Move code that dumps generated AST
Browse files Browse the repository at this point in the history
That code is common to any method that generates an AST, like cargo
subprojects coming soon.
  • Loading branch information
xclaesse committed Sep 22, 2023
1 parent e9369be commit 586bd11
Showing 1 changed file with 14 additions and 24 deletions.
38 changes: 14 additions & 24 deletions mesonbuild/interpreter/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -953,12 +953,24 @@ def _do_subproject_meson(self, subp_name: str, subdir: str,
kwargs: kwtypes.DoSubproject,
ast: T.Optional[mparser.CodeBlockNode] = None,
build_def_files: T.Optional[T.List[str]] = None,
is_translated: bool = False,
relaxations: T.Optional[T.Set[InterpreterRuleRelaxation]] = None) -> SubprojectHolder:
with mlog.nested(subp_name):
if ast:
# Debug print the generated meson file
from ..ast import AstIndentationGenerator, AstPrinter
printer = AstPrinter(update_ast_line_nos=True)
ast.accept(AstIndentationGenerator())
ast.accept(printer)
printer.post_process()
meson_filename = os.path.join(self.build.environment.get_build_dir(), subdir, 'meson.build')
with open(meson_filename, "w", encoding='utf-8') as f:
f.write(printer.result)
mlog.log('Generated Meson AST:', meson_filename)
mlog.cmd_ci_include(meson_filename)

new_build = self.build.copy()
subi = Interpreter(new_build, self.backend, subp_name, subdir, self.subproject_dir,
default_options, ast=ast, is_translated=is_translated,
default_options, ast=ast, is_translated=(ast is not None),
relaxations=relaxations,
user_defined_options=self.user_defined_options)
# Those lists are shared by all interpreters. That means that
Expand Down Expand Up @@ -1013,37 +1025,15 @@ def _do_subproject_cmake(self, subp_name: str, subdir: str,

# Generate a meson ast and execute it with the normal do_subproject_meson
ast = cm_int.pretend_to_be_meson(options.target_options)

mlog.log()
with mlog.nested('cmake-ast'):
mlog.log('Processing generated meson AST')

# Debug print the generated meson file
from ..ast import AstIndentationGenerator, AstPrinter
printer = AstPrinter(update_ast_line_nos=True)
ast.accept(AstIndentationGenerator())
ast.accept(printer)
printer.post_process()
meson_filename = os.path.join(self.build.environment.get_build_dir(), subdir, 'meson.build')
with open(meson_filename, "w", encoding='utf-8') as f:
f.write(printer.result)

mlog.log('Build file:', meson_filename)
mlog.cmd_ci_include(meson_filename)
mlog.log()

result = self._do_subproject_meson(
subp_name, subdir, default_options,
kwargs, ast,
[str(f) for f in cm_int.bs_files],
is_translated=True,
relaxations={
InterpreterRuleRelaxation.ALLOW_BUILD_DIR_FILE_REFERENCES,
}
)
result.cm_interpreter = cm_int

mlog.log()
return result

def get_option_internal(self, optname: str) -> coredata.UserOption:
Expand Down

0 comments on commit 586bd11

Please sign in to comment.