summaryrefslogtreecommitdiff
path: root/site_scons
diff options
context:
space:
mode:
authorGabe Black <gabeblack@google.com>2019-11-18 17:40:37 -0800
committerGabe Black <gabeblack@google.com>2019-11-21 23:37:03 +0000
commitcc3d5dfeb097d1d64fc39c7724de4b195eb957b7 (patch)
treedc4afafce8cabde8e9bf4cdf8f58d48e29fcddad /site_scons
parenta434c6cc4558da46c7ac341cfe685a9189b9a7b8 (diff)
downloadgem5-cc3d5dfeb097d1d64fc39c7724de4b195eb957b7.tar.xz
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 <jason@lowepower.com> Maintainer: Jason Lowe-Power <jason@lowepower.com> Tested-by: kokoro <noreply+kokoro@google.com>
Diffstat (limited to 'site_scons')
-rw-r--r--site_scons/gem5_scons/__init__.py19
1 files changed, 18 insertions, 1 deletions
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']