twister: Add option to always force color output

Colorama, by default, strips out the color escape characters when the
output is redirected, and this may have an unintended consequence of
disabling color outputs when using a utility such as `tee` and in the
CI runners that redirect the stdout and stderr console outputs.

This commit adds a new command line option called `--force-color` to
always force the ANSI color escape sequence output even when the output
is redirected.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
This commit is contained in:
Stephanos Ioannidis 2022-05-25 03:39:40 +09:00
commit 39956ec835
2 changed files with 13 additions and 3 deletions

View file

@ -4716,4 +4716,5 @@ class HardwareMap:
print(tabulate(table, headers=header, tablefmt="github"))
colorama.init()
def init(colorama_strip):
colorama.init(strip=colorama_strip)

View file

@ -205,6 +205,7 @@ except ImportError:
sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/pylib/twister"))
import twisterlib
from twisterlib import HardwareMap, TestPlan, SizeCalculator, CoverageTool, ExecutionCounter
logger = logging.getLogger('twister')
@ -493,6 +494,10 @@ structure in the main Zephyr tree: boards/<arch>/<board_name>/""")
is run. This option allows for example to only build tests that can
actually be run. Runnable is a subset of buildable.""")
parser.add_argument("--force-color", action="store_true",
help="Always output ANSI color escape sequences "
"even when the output is redirected (not a tty)")
parser.add_argument("--force-toolchain", action="store_true",
help="Do not filter based on toolchain, use the set "
" toolchain unconditionally")
@ -833,10 +838,14 @@ def setup_logging(outdir, log_file, verbose, timestamps):
def main():
start_time = time.time()
colorama.init()
options = parse_arguments()
# Configure color output
color_strip = False if options.force_color else None
colorama.init(strip=color_strip)
twisterlib.init(colorama_strip=color_strip)
previous_results = None
# Cleanup
if options.no_clean or options.only_failed or options.test_only: