mlog: Add built-in support for quoting bolded messages

This allows us to drop wonky sep='' hacks and manual addition of
spaces across the codebase.
pull/3843/merge
Nirbheek Chauhan 7 years ago committed by Nirbheek Chauhan
parent f2b008f874
commit 1415cd2d07
  1. 42
      mesonbuild/interpreter.py
  2. 14
      mesonbuild/mlog.py

@ -1012,7 +1012,7 @@ class CompilerHolder(InterpreterObject):
extra_args = mesonlib.stringlistify(kwargs.get('args', [])) extra_args = mesonlib.stringlistify(kwargs.get('args', []))
deps = self.determine_dependencies(kwargs) deps = self.determine_dependencies(kwargs)
result = self.compiler.alignment(typename, prefix, self.environment, extra_args, deps) result = self.compiler.alignment(typename, prefix, self.environment, extra_args, deps)
mlog.log('Checking for alignment of "', mlog.bold(typename), '": ', result, sep='') mlog.log('Checking for alignment of', mlog.bold(typename, True), ':', result)
return result return result
@permittedKwargs({ @permittedKwargs({
@ -1044,7 +1044,7 @@ class CompilerHolder(InterpreterObject):
h = mlog.green('YES') h = mlog.green('YES')
else: else:
h = mlog.red('NO (%d)' % result.returncode) h = mlog.red('NO (%d)' % result.returncode)
mlog.log('Checking if "', mlog.bold(testname), '" runs: ', h, sep='') mlog.log('Checking if', mlog.bold(testname, True), 'runs:', h)
return TryRunResultHolder(result) return TryRunResultHolder(result)
@noPosargs @noPosargs
@ -1097,8 +1097,8 @@ class CompilerHolder(InterpreterObject):
hadtxt = mlog.green('YES') hadtxt = mlog.green('YES')
else: else:
hadtxt = mlog.red('NO') hadtxt = mlog.red('NO')
mlog.log('Checking whether type "', mlog.bold(typename), mlog.log('Checking whether type', mlog.bold(typename, True),
'" has member "', mlog.bold(membername), '": ', hadtxt, sep='') 'has member', mlog.bold(membername, True), ':', hadtxt)
return had return had
@permittedKwargs({ @permittedKwargs({
@ -1126,8 +1126,8 @@ class CompilerHolder(InterpreterObject):
else: else:
hadtxt = mlog.red('NO') hadtxt = mlog.red('NO')
members = mlog.bold(', '.join(['"{}"'.format(m) for m in membernames])) members = mlog.bold(', '.join(['"{}"'.format(m) for m in membernames]))
mlog.log('Checking whether type "', mlog.bold(typename), mlog.log('Checking whether type', mlog.bold(typename, True),
'" has members ', members, ': ', hadtxt, sep='') 'has members', members, ':', hadtxt)
return had return had
@permittedKwargs({ @permittedKwargs({
@ -1152,7 +1152,7 @@ class CompilerHolder(InterpreterObject):
hadtxt = mlog.green('YES') hadtxt = mlog.green('YES')
else: else:
hadtxt = mlog.red('NO') hadtxt = mlog.red('NO')
mlog.log('Checking for function "', mlog.bold(funcname), '": ', hadtxt, sep='') mlog.log('Checking for function', mlog.bold(funcname, True), ':', hadtxt)
return had return had
@permittedKwargs({ @permittedKwargs({
@ -1177,7 +1177,7 @@ class CompilerHolder(InterpreterObject):
hadtxt = mlog.green('YES') hadtxt = mlog.green('YES')
else: else:
hadtxt = mlog.red('NO') hadtxt = mlog.red('NO')
mlog.log('Checking for type "', mlog.bold(typename), '": ', hadtxt, sep='') mlog.log('Checking for type', mlog.bold(typename, True), ':', hadtxt)
return had return had
@FeatureNew('compiler.compute_int', '0.40.0') @FeatureNew('compiler.compute_int', '0.40.0')
@ -1284,7 +1284,7 @@ class CompilerHolder(InterpreterObject):
h = mlog.green('YES') h = mlog.green('YES')
else: else:
h = mlog.red('NO') h = mlog.red('NO')
mlog.log('Checking if "', mlog.bold(testname), '" compiles: ', h, sep='') mlog.log('Checking if', mlog.bold(testname, True), 'compiles:', h)
return result return result
@permittedKwargs({ @permittedKwargs({
@ -1314,7 +1314,7 @@ class CompilerHolder(InterpreterObject):
h = mlog.green('YES') h = mlog.green('YES')
else: else:
h = mlog.red('NO') h = mlog.red('NO')
mlog.log('Checking if "', mlog.bold(testname), '" links: ', h, sep='') mlog.log('Checking if', mlog.bold(testname, True), 'links:', h)
return result return result
@FeatureNew('compiler.check_header', '0.47.0') @FeatureNew('compiler.check_header', '0.47.0')
@ -2236,7 +2236,7 @@ external dependencies (including libraries) must go to "dependencies".''')
self.global_args_frozen = True self.global_args_frozen = True
mlog.log() mlog.log()
with mlog.nested(): with mlog.nested():
mlog.log('\nExecuting subproject ', mlog.bold(dirname), '.\n', sep='') mlog.log('\nExecuting subproject', mlog.bold(dirname), '\n')
subi = Interpreter(self.build, self.backend, dirname, subdir, self.subproject_dir, subi = Interpreter(self.build, self.backend, dirname, subdir, self.subproject_dir,
self.modules, default_options) self.modules, default_options)
subi.subprojects = self.subprojects subi.subprojects = self.subprojects
@ -2439,8 +2439,8 @@ external dependencies (including libraries) must go to "dependencies".''')
if not mesonlib.version_compare(cv, pv): if not mesonlib.version_compare(cv, pv):
raise InterpreterException('Meson version is %s but project requires %s.' % (cv, pv)) raise InterpreterException('Meson version is %s but project requires %s.' % (cv, pv))
self.build.projects[self.subproject] = proj_name self.build.projects[self.subproject] = proj_name
mlog.log('Project name: ', mlog.bold(proj_name), sep='') mlog.log('Project name:', mlog.bold(proj_name))
mlog.log('Project version: ', mlog.bold(self.project_version), sep='') mlog.log('Project version:', mlog.bold(self.project_version))
self.add_languages(proj_langs, True) self.add_languages(proj_langs, True)
langs = self.coredata.compilers.keys() langs = self.coredata.compilers.keys()
if 'vala' in langs: if 'vala' in langs:
@ -2593,14 +2593,16 @@ external dependencies (including libraries) must go to "dependencies".''')
else: else:
raise raise
if comp.full_version is not None: if comp.full_version is not None:
version_string = ' (%s %s "%s")' % (comp.id, comp.version, comp.full_version) version_string = '(%s %s "%s")' % (comp.id, comp.version, comp.full_version)
else: else:
version_string = ' (%s %s)' % (comp.id, comp.version) version_string = '(%s %s)' % (comp.id, comp.version)
mlog.log('Native %s compiler: ' % comp.get_display_language(), mlog.bold(' '.join(comp.get_exelist())), version_string, sep='') mlog.log('Native', comp.get_display_language(), 'compiler:',
mlog.bold(' '.join(comp.get_exelist())), version_string)
self.build.add_compiler(comp) self.build.add_compiler(comp)
if need_cross_compiler: if need_cross_compiler:
mlog.log('Cross %s compiler: ' % cross_comp.get_display_language(), mlog.bold(' '.join(cross_comp.get_exelist())), ' (%s %s)' % (cross_comp.id, cross_comp.version), sep='') version_string = '(%s %s)' % (cross_comp.id, cross_comp.version)
mlog.log('Cross', cross_comp.get_display_language(), 'compiler:',
mlog.bold(' '.join(cross_comp.get_exelist())), version_string)
self.build.add_cross_compiler(cross_comp) self.build.add_cross_compiler(cross_comp)
if self.environment.is_cross_build() and not need_cross_compiler: if self.environment.is_cross_build() and not need_cross_compiler:
self.build.add_cross_compiler(comp) self.build.add_cross_compiler(comp)
@ -3207,10 +3209,10 @@ root and issuing %s.
env, should_fail, timeout, workdir) env, should_fail, timeout, workdir)
if is_base_test: if is_base_test:
self.build.tests.append(t) self.build.tests.append(t)
mlog.debug('Adding test "', mlog.bold(args[0]), '".', sep='') mlog.debug('Adding test', mlog.bold(args[0], True))
else: else:
self.build.benchmarks.append(t) self.build.benchmarks.append(t)
mlog.debug('Adding benchmark "', mlog.bold(args[0]), '".', sep='') mlog.debug('Adding benchmark', mlog.bold(args[0], True))
@FeatureNewKwargs('install_headers', '0.47.0', ['install_mode']) @FeatureNewKwargs('install_headers', '0.47.0', ['install_mode'])
@permittedKwargs(permitted_kwargs['install_headers']) @permittedKwargs(permitted_kwargs['install_headers'])

@ -57,17 +57,21 @@ def shutdown():
class AnsiDecorator: class AnsiDecorator:
plain_code = "\033[0m" plain_code = "\033[0m"
def __init__(self, text, code): def __init__(self, text, code, quoted=False):
self.text = text self.text = text
self.code = code self.code = code
self.quoted = quoted
def get_text(self, with_codes): def get_text(self, with_codes):
text = self.text
if with_codes: if with_codes:
return self.code + self.text + AnsiDecorator.plain_code text = self.code + self.text + AnsiDecorator.plain_code
return self.text if self.quoted:
text = '"{}"'.format(text)
return text
def bold(text): def bold(text, quoted=False):
return AnsiDecorator(text, "\033[1m") return AnsiDecorator(text, "\033[1m", quoted=quoted)
def red(text): def red(text):
return AnsiDecorator(text, "\033[1;31m") return AnsiDecorator(text, "\033[1;31m")

Loading…
Cancel
Save