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>
This commit is contained in:
@@ -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']
|
||||
|
||||
Reference in New Issue
Block a user