summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbecker33 <becker33@llnl.gov>2016-11-21 14:22:26 -0800
committerGitHub <noreply@github.com>2016-11-21 14:22:26 -0800
commit294ad3e8181c561062876878d2dfafedc825452b (patch)
treeb3c1c4bcd29aeda14a36352456e8d251e87230f9
parent760bca30483ed6e9af959937865a2c1b5e7eb378 (diff)
parentf1b26cb72e643cebc0cf3a650c1a4189628ed7df (diff)
downloadspack-294ad3e8181c561062876878d2dfafedc825452b.tar.gz
spack-294ad3e8181c561062876878d2dfafedc825452b.tar.bz2
spack-294ad3e8181c561062876878d2dfafedc825452b.tar.xz
spack-294ad3e8181c561062876878d2dfafedc825452b.zip
Merge pull request #2343 from krafczyk/features/better_diagnostics
Improve diagnostics to ease debugging
-rwxr-xr-xbin/spack3
-rw-r--r--lib/spack/llnl/util/tty/__init__.py41
2 files changed, 42 insertions, 2 deletions
diff --git a/bin/spack b/bin/spack
index 1f5dec0b3d..7cc1b28a37 100755
--- a/bin/spack
+++ b/bin/spack
@@ -128,6 +128,8 @@ parser.add_argument('-p', '--profile', action='store_true',
help="Profile execution using cProfile.")
parser.add_argument('-v', '--verbose', action='store_true',
help="Print additional output during builds")
+parser.add_argument('-s', '--stacktrace', action='store_true',
+ help="Add stacktrace information to all printed statements")
parser.add_argument('-V', '--version', action='version',
version="%s" % spack.spack_version)
@@ -155,6 +157,7 @@ def main():
# Set up environment based on args.
tty.set_verbose(args.verbose)
tty.set_debug(args.debug)
+ tty.set_stacktrace(args.stacktrace)
spack.debug = args.debug
if spack.debug:
diff --git a/lib/spack/llnl/util/tty/__init__.py b/lib/spack/llnl/util/tty/__init__.py
index db74aaba6b..1381bb2f7d 100644
--- a/lib/spack/llnl/util/tty/__init__.py
+++ b/lib/spack/llnl/util/tty/__init__.py
@@ -28,12 +28,14 @@ import textwrap
import fcntl
import termios
import struct
+import traceback
from StringIO import StringIO
from llnl.util.tty.color import *
_debug = False
_verbose = False
+_stacktrace = False
indent = " "
@@ -45,6 +47,10 @@ def is_debug():
return _debug
+def is_stacktrace():
+ return _stacktrace
+
+
def set_debug(flag):
global _debug
_debug = flag
@@ -53,10 +59,35 @@ def set_debug(flag):
def set_verbose(flag):
global _verbose
_verbose = flag
+
+
+def set_stacktrace(flag):
+ global _stacktrace
+ _stacktrace = flag
+
+
+def process_stacktrace(countback):
+ """Gives file and line frame 'countback' frames from the bottom"""
+ st = traceback.extract_stack()
+ # Not all entries may be spack files, we have to remove those that aren't.
+ file_list = []
+ for frame in st:
+ # Check that the file is a spack file
+ if frame[0].find("/spack") >= 0:
+ file_list.append(frame[0])
+ # We use commonprefix to find what the spack 'root' directory is.
+ root_dir = os.path.commonprefix(file_list)
+ root_len = len(root_dir)
+ st_idx = len(st) - countback - 1
+ st_text = "%s:%i " % (st[st_idx][0][root_len:], st[st_idx][1])
+ return st_text
def msg(message, *args):
- cprint("@*b{==>} %s" % cescape(message))
+ st_text = ""
+ if _stacktrace:
+ st_text = process_stacktrace(2)
+ cprint("@*b{%s==>} %s" % (st_text, cescape(message)))
for arg in args:
print indent + str(arg)
@@ -66,8 +97,13 @@ def info(message, *args, **kwargs):
stream = kwargs.get('stream', sys.stdout)
wrap = kwargs.get('wrap', False)
break_long_words = kwargs.get('break_long_words', False)
+ st_countback = kwargs.get('countback', 3)
- cprint("@%s{==>} %s" % (format, cescape(str(message))), stream=stream)
+ st_text = ""
+ if _stacktrace:
+ st_text = process_stacktrace(st_countback)
+ cprint("@%s{%s==>} %s" % (format, st_text, cescape(str(message))),
+ stream=stream)
for arg in args:
if wrap:
lines = textwrap.wrap(
@@ -105,6 +141,7 @@ def warn(message, *args, **kwargs):
def die(message, *args, **kwargs):
+ kwargs.setdefault('countback', 4)
error(message, *args, **kwargs)
sys.exit(1)