From cc3d5dfeb097d1d64fc39c7724de4b195eb957b7 Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Mon, 18 Nov 2019 17:40:37 -0800 Subject: [PATCH] scons: Add "warning" and "error" methods. These methods will make reporting errors less verbose and more consistent, since they'll handle some formating, setting colors, prefixing with an appropriate "Warning:" or "Error:" tag, and exiting in the case of an error. Change-Id: Iddea5bf342a4fc4b26002d8e98292f9dc57fa8cc Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/22885 Reviewed-by: Jason Lowe-Power Maintainer: Jason Lowe-Power Tested-by: kokoro --- site_scons/gem5_scons/__init__.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/site_scons/gem5_scons/__init__.py b/site_scons/gem5_scons/__init__.py index 0521862df..86494cf6a 100644 --- a/site_scons/gem5_scons/__init__.py +++ b/site_scons/gem5_scons/__init__.py @@ -38,9 +38,12 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +from __future__ import print_function + import os from gem5_scons.util import get_termcap +import SCons.Script termcap = get_termcap() @@ -124,4 +127,18 @@ class Transform(object): return ', '.join(f) return self.format % (com_pfx, fmt(srcs), fmt(tgts)) -__all__ = ['Transform'] +def print_message(prefix, color, message, **kwargs): + lines = message.split('\n') + message = prefix + ('\n' + ' ' * len(prefix)).join(lines) + print(color + termcap.Bold + message + termcap.Normal, **kwargs) + +def warning(*args, **kwargs): + message = ' '.join(args) + print_message('Warning: ', termcap.Yellow, message, **kwargs) + +def error(*args, **kwargs): + message = ' '.join(args) + print_message('Error: ', termcap.Red, message, **kwargs) + SCons.Script.Exit(1) + +__all__ = ['Transform', 'warning', 'error'] -- 2.30.2