From ea8bceb5933efb5880c44502cca9423c1d1d6f7f Mon Sep 17 00:00:00 2001 From: Earl Ou Date: Mon, 5 Oct 2020 15:51:56 +0800 Subject: [PATCH] scons: only wrap message with positive value In case we have small TTY, scons failed with wrong testwrap value. Fix the issue. Change-Id: I8ec1d55c6856c1e592a57a68067091b796ac84ae Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/35596 Reviewed-by: Gabe Black Maintainer: Gabe Black Tested-by: kokoro --- site_scons/gem5_scons/__init__.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/site_scons/gem5_scons/__init__.py b/site_scons/gem5_scons/__init__.py index 33231127c..4208cf1a5 100644 --- a/site_scons/gem5_scons/__init__.py +++ b/site_scons/gem5_scons/__init__.py @@ -160,20 +160,23 @@ if text_width is None: text_width = 80 def print_message(prefix, color, message, **kwargs): - # Precompute some useful values. prefix_len = len(prefix) - wrap_width = text_width - prefix_len - padding = ' ' * prefix_len - - # First split on newlines. - lines = message.split('\n') - # Then wrap each line to the required width. - wrapped_lines = [] - for line in lines: - wrapped_lines.extend(textwrap.wrap(line, wrap_width)) - # Finally add the prefix and padding on extra lines, and glue it all back - # together. - message = prefix + ('\n' + padding).join(wrapped_lines) + if text_width > prefix_len: + wrap_width = text_width - prefix_len + padding = ' ' * prefix_len + + # First split on newlines. + lines = message.split('\n') + # Then wrap each line to the required width. + wrapped_lines = [] + for line in lines: + wrapped_lines.extend(textwrap.wrap(line, wrap_width)) + # Finally add the prefix and padding on extra lines, and glue it all + # back together. + message = prefix + ('\n' + padding).join(wrapped_lines) + else: + # We have very small terminal, indent formatting doesn't help. + message = prefix + message # Add in terminal escape sequences. message = color + termcap.Bold + message + termcap.Normal # Actually print the message. -- 2.30.2