From bf32d3623092f80eeefacc0b76fb381f4c6843f8 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Sat, 13 Jan 2018 17:56:41 +0100 Subject: [PATCH] Disable colored output and progress bar when building outside of a TTY This makes the output more readable if it is written to a file, and more compact in continuous integration environments, keeping the log sizes low. This commit also adds myself to .mailmap. --- .mailmap | 3 +++ SConstruct | 7 ++++++- methods.py | 30 +++++++++++++++++++----------- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/.mailmap b/.mailmap index b37cd2884d8..aa2e0911ecf 100644 --- a/.mailmap +++ b/.mailmap @@ -8,6 +8,9 @@ Bastiaan Olij Bernhard Liebl Bernhard Liebl Geequlim +Hugo Locurcio +Hugo Locurcio +Hugo Locurcio Ignacio Etcheverry Indah Sylvia Jakub Grzesik diff --git a/SConstruct b/SConstruct index 7e82e582d03..dcf8134c934 100644 --- a/SConstruct +++ b/SConstruct @@ -498,7 +498,12 @@ node_count_interval = 1 node_pruning = 8 # Number of nodes to process before prunning the cache if ('env' in locals()): node_count_fname = str(env.Dir('#')) + '/.scons_node_count' -show_progress = env['progress'] +# Progress reporting is not available in non-TTY environments since it +# messes with the output (for example, when writing to a file) +if sys.stdout.isatty(): + show_progress = env['progress'] +else: + show_progress = False import time, math diff --git a/methods.py b/methods.py index fbdac8a9666..3ffe8cb3109 100644 --- a/methods.py +++ b/methods.py @@ -1549,18 +1549,26 @@ def save_active_platforms(apnames, ap): def no_verbose(sys, env): - # If the output is not a terminal, do nothing - if not sys.stdout.isatty(): - return - colors = {} - colors['cyan'] = '\033[96m' - colors['purple'] = '\033[95m' - colors['blue'] = '\033[94m' - colors['green'] = '\033[92m' - colors['yellow'] = '\033[93m' - colors['red'] = '\033[91m' - colors['end'] = '\033[0m' + + # Colors are disabled in non-TTY environments such as pipes. This means + # that if output is redirected to a file, it will not contain color codes + if sys.stdout.isatty(): + colors['cyan'] = '\033[96m' + colors['purple'] = '\033[95m' + colors['blue'] = '\033[94m' + colors['green'] = '\033[92m' + colors['yellow'] = '\033[93m' + colors['red'] = '\033[91m' + colors['end'] = '\033[0m' + else: + colors['cyan'] = '' + colors['purple'] = '' + colors['blue'] = '' + colors['green'] = '' + colors['yellow'] = '' + colors['red'] = '' + colors['end'] = '' compile_source_message = '%sCompiling %s==> %s$SOURCE%s' % (colors['blue'], colors['purple'], colors['yellow'], colors['end']) java_compile_source_message = '%sCompiling %s==> %s$SOURCE%s' % (colors['blue'], colors['purple'], colors['yellow'], colors['end'])