rewriter: Quiet logging by default

pull/4992/head
Daniel Mensinger 6 years ago
parent dd5791309e
commit 5d2f14fce7
No known key found for this signature in database
GPG Key ID: 54DD94C131E277D4
  1. 21
      mesonbuild/mlog.py
  2. 8
      mesonbuild/rewriter.py
  3. 2
      run_unittests.py

@ -48,6 +48,7 @@ log_depth = 0
log_timestamp_start = None
log_fatal_warnings = False
log_disable_stdout = False
log_errors_only = False
def disable():
global log_disable_stdout
@ -57,6 +58,14 @@ def enable():
global log_disable_stdout
log_disable_stdout = False
def set_quiet():
global log_errors_only
log_errors_only = True
def set_verbose():
global log_errors_only
log_errors_only = False
def initialize(logdir, fatal_warnings=False):
global log_dir, log_file, log_fatal_warnings
log_dir = logdir
@ -152,14 +161,16 @@ def debug(*args, **kwargs):
print(*arr, file=log_file, **kwargs) # Log file never gets ANSI codes.
log_file.flush()
def log(*args, **kwargs):
def log(*args, is_error=False, **kwargs):
global log_errors_only
arr = process_markup(args, False)
if log_file is not None:
print(*arr, file=log_file, **kwargs) # Log file never gets ANSI codes.
log_file.flush()
if colorize_console:
arr = process_markup(args, True)
force_print(*arr, **kwargs)
if not log_errors_only or is_error:
force_print(*arr, **kwargs)
def _log_error(severity, *args, **kwargs):
from .mesonlib import get_error_location_string
@ -187,13 +198,13 @@ def _log_error(severity, *args, **kwargs):
raise MesonException("Fatal warnings enabled, aborting")
def error(*args, **kwargs):
return _log_error('error', *args, **kwargs)
return _log_error('error', *args, **kwargs, is_error=True)
def warning(*args, **kwargs):
return _log_error('warning', *args, **kwargs)
return _log_error('warning', *args, **kwargs, is_error=True)
def deprecation(*args, **kwargs):
return _log_error('deprecation', *args, **kwargs)
return _log_error('deprecation', *args, **kwargs, is_error=True)
def exception(e, prefix=red('ERROR:')):
log()

@ -36,6 +36,7 @@ class RewriterException(MesonException):
def add_arguments(parser, formater=None):
parser.add_argument('--sourcedir', type=str, default='.', metavar='SRCDIR', help='Path to source directory.')
parser.add_argument('-V', '--verbose', action='store_true', default=False, help='Enable verbose output')
subparsers = parser.add_subparsers(dest='type', title='Rewriter commands', description='Rewrite command to execute')
# Target
@ -904,11 +905,15 @@ cli_type_map = {
}
def run(options):
if not options.verbose:
mlog.set_quiet()
rewriter = Rewriter(options.sourcedir)
rewriter.analyze_meson()
if options.type is None:
print('No command specified')
mlog.error('No command specified')
mlog.set_verbose()
return 1
commands = cli_type_map[options.type](options)
@ -923,4 +928,5 @@ def run(options):
rewriter.apply_changes()
rewriter.print_info()
mlog.set_verbose()
return 0

@ -5197,7 +5197,7 @@ class RewriterTests(BasePlatformTests):
def rewrite_raw(self, directory, args):
if isinstance(args, str):
args = [args]
command = self.rewrite_command + ['--sourcedir', directory] + args
command = self.rewrite_command + ['--verbose', '--sourcedir', directory] + args
p = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
universal_newlines=True, timeout=60)
print('STDOUT:')

Loading…
Cancel
Save