diff options
| author | Gary Oberbrunner <garyo@oberbrunner.com> | 2008-10-29 03:01:00 (GMT) |
|---|---|---|
| committer | Gary Oberbrunner <garyo@oberbrunner.com> | 2008-10-29 03:01:00 (GMT) |
| commit | 652d80b36bf9e80989336bf7a25b54c176ff626c (patch) | |
| tree | 93f780a267396d95f9bfeba9c48da963a81abf05 /src/engine/SCons/Script | |
| parent | d695652a34c6740b3c925a94b45256270027f473 (diff) | |
| download | SCons-652d80b36bf9e80989336bf7a25b54c176ff626c.zip SCons-652d80b36bf9e80989336bf7a25b54c176ff626c.tar.gz SCons-652d80b36bf9e80989336bf7a25b54c176ff626c.tar.bz2 | |
Applied Benoit Belley's patch in ticket 1957 improve the robustness of
GetBuildFailures(). New function convert_to_buildError, and use it in
several places so all build failures now go through it and are
returned as BuildError exceptions. Had a small effect on output
formatting in many tests but no significant change to behavior. I
reworked the patch a little to keep SCons exit status values the same
as before; this patch could make it simpler to change them in some
cases, e.g. exit with the errno of the failed action if desired. One
nice side effect of this patch is that more scons errors print the
node that caused the error now.
Diffstat (limited to 'src/engine/SCons/Script')
| -rw-r--r-- | src/engine/SCons/Script/Main.py | 67 |
1 files changed, 33 insertions, 34 deletions
diff --git a/src/engine/SCons/Script/Main.py b/src/engine/SCons/Script/Main.py index 7b6b52b..62a52d6 100644 --- a/src/engine/SCons/Script/Main.py +++ b/src/engine/SCons/Script/Main.py @@ -231,54 +231,51 @@ class BuildTask(SCons.Taskmaster.Task): # Handle the failure of a build task. The primary purpose here # is to display the various types of Errors and Exceptions # appropriately. - status = 2 exc_info = self.exc_info() try: t, e, tb = exc_info except ValueError: t, e = exc_info tb = None + if t is None: # The Taskmaster didn't record an exception for this Task; # see if the sys module has one. - t, e = sys.exc_info()[:2] - - def nodestring(n): - if not SCons.Util.is_List(n): - n = [ n ] - return string.join(map(str, n), ', ') + try: + t, e, tb = sys.exc_info()[:] + except ValueError: + t, e = exc_info + tb = None + + # Deprecated string exceptions will have their string stored + # in the first entry of the tuple. + if e is None: + e = t + + buildError = SCons.Errors.convert_to_BuildError(e) + if not buildError.node: + buildError.node = self.node + + node = buildError.node + if not SCons.Util.is_List(node): + node = [ node ] + nodename = string.join(map(str, node), ', ') errfmt = "scons: *** [%s] %s\n" + sys.stderr.write(errfmt % (nodename, buildError)) - if t == SCons.Errors.BuildError: - tname = nodestring(e.node) - errstr = e.errstr - if e.filename: - errstr = e.filename + ': ' + errstr - sys.stderr.write(errfmt % (tname, errstr)) - elif t == SCons.Errors.TaskmasterException: - tname = nodestring(e.node) - sys.stderr.write(errfmt % (tname, e.errstr)) - type, value, trace = e.exc_info + if (buildError.exc_info[2] and buildError.exc_info[1] and + not isinstance( + buildError.exc_info[1], + (EnvironmentError, SCons.Errors.StopError, SCons.Errors.UserError))): + type, value, trace = buildError.exc_info traceback.print_exception(type, value, trace) - elif t == SCons.Errors.ExplicitExit: - status = e.status - tname = nodestring(e.node) - errstr = 'Explicit exit, status %s' % status - sys.stderr.write(errfmt % (tname, errstr)) - else: - if e is None: - e = t - s = str(e) - if t == SCons.Errors.StopError and not self.options.keep_going: - s = s + ' Stop.' - sys.stderr.write("scons: *** %s\n" % s) - - if tb and print_stacktrace: - sys.stderr.write("scons: internal stack trace:\n") - traceback.print_tb(tb, file=sys.stderr) + elif tb and print_stacktrace: + sys.stderr.write("scons: internal stack trace:\n") + traceback.print_tb(tb, file=sys.stderr) - self.do_failed(status) + self.exception = (e, buildError, tb) # type, value, traceback + self.do_failed(buildError.exitstatus) self.exc_clear() @@ -1273,6 +1270,8 @@ def main(): except SConsPrintHelpException: parser.print_help() exit_status = 0 + except SCons.Errors.BuildError, e: + exit_status = e.exitstatus except: # An exception here is likely a builtin Python exception Python # code in an SConscript file. Show them precisely what the |
