diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 6ecd28569105..b99a4132f14a 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -1862,21 +1862,23 @@ def do_subproject(self, dirname, kwargs): subdir = os.path.join(self.subproject_dir, resolved) os.makedirs(os.path.join(self.build.environment.get_build_dir(), subdir), exist_ok=True) self.global_args_frozen = True - mlog.log('\nExecuting subproject ', mlog.bold(dirname), '.\n', sep='') - subi = Interpreter(self.build, self.backend, dirname, subdir, self.subproject_dir, - mesonlib.stringlistify(kwargs.get('default_options', []))) - subi.subprojects = self.subprojects - - subi.subproject_stack = self.subproject_stack + [dirname] - current_active = self.active_projectname - subi.run() + mlog.log() + with mlog.nested(): + mlog.log('Executing subproject ', mlog.bold(dirname), '.\n', sep='') + subi = Interpreter(self.build, self.backend, dirname, subdir, self.subproject_dir, + mesonlib.stringlistify(kwargs.get('default_options', []))) + subi.subprojects = self.subprojects + + subi.subproject_stack = self.subproject_stack + [dirname] + current_active = self.active_projectname + subi.run() + mlog.log('\nSubproject', mlog.bold(dirname), 'finished.') if 'version' in kwargs: pv = subi.project_version wanted = kwargs['version'] if pv == 'undefined' or not mesonlib.version_compare(pv, wanted): raise InterpreterException('Subproject %s version is %s but %s required.' % (dirname, pv, wanted)) self.active_projectname = current_active - mlog.log('\nSubproject', mlog.bold(dirname), 'finished.') self.build.subprojects[dirname] = subi.project_version self.subprojects.update(subi.subprojects) self.subprojects[dirname] = SubprojectHolder(subi) diff --git a/mesonbuild/mlog.py b/mesonbuild/mlog.py index 347cededeb6d..6cbaf608514d 100644 --- a/mesonbuild/mlog.py +++ b/mesonbuild/mlog.py @@ -13,6 +13,7 @@ # limitations under the License. import sys, os, platform, io +from contextlib import contextmanager """This is (mostly) a standalone module used to write logging information about Meson runs. Some output goes to screen, @@ -25,6 +26,7 @@ log_dir = None log_file = None log_fname = 'meson-log.txt' +log_depth = 0 def initialize(logdir): global log_dir, log_file @@ -77,15 +79,21 @@ def process_markup(args, keep): return arr def force_print(*args, **kwargs): + iostr = io.StringIO() + kwargs['file'] = iostr + print(*args, **kwargs) + + raw = iostr.getvalue() + if log_depth > 0: + prepend = '|' * log_depth + raw = prepend + raw.replace('\n', '\n' + prepend, raw.count('\n') - 1) + # _Something_ is going to get printed. try: - print(*args, **kwargs) + print(raw, end='') except UnicodeEncodeError: - iostr = io.StringIO() - kwargs['file'] = iostr - print(*args, **kwargs) - cleaned = iostr.getvalue().encode('ascii', 'replace').decode('ascii') - print(cleaned) + cleaned = raw.encode('ascii', 'replace').decode('ascii') + print(cleaned, end='') def debug(*args, **kwargs): arr = process_markup(args, False) @@ -146,3 +154,12 @@ def format_list(list): return list[0] else: return '' + +@contextmanager +def nested(): + global log_depth + log_depth += 1 + try: + yield + finally: + log_depth -= 1