Skip to content

Commit

Permalink
Indicate subproject depth in console output
Browse files Browse the repository at this point in the history
  • Loading branch information
jon-turney authored and nirbheek committed Apr 13, 2018
1 parent 57654bf commit cb597ad
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
20 changes: 11 additions & 9 deletions mesonbuild/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
29 changes: 23 additions & 6 deletions mesonbuild/mlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

0 comments on commit cb597ad

Please sign in to comment.