From: Gabe Black Date: Tue, 19 Nov 2019 01:40:37 +0000 (-0800) Subject: scons: Add "warning" and "error" methods. X-Git-Tag: v19.0.0.0~276 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=cc3d5dfeb097d1d64fc39c7724de4b195eb957b7;p=gem5.git 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 --- 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']