diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2017-09-28 12:18:58 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2017-09-28 12:18:58 +0200 |
commit | baee03c569c91b745a1e025660b19a718db16e7d (patch) | |
tree | 1aaa25835bd24c5c95649cd8ab34d97bafded599 /src/engine/SCons/Errors.py | |
parent | 4c7fed99e5554ba71d62987c0ec5f1302011b122 (diff) |
New upstream version 3.0.0upstream/3.0.0
Diffstat (limited to 'src/engine/SCons/Errors.py')
-rw-r--r-- | src/engine/SCons/Errors.py | 128 |
1 files changed, 76 insertions, 52 deletions
diff --git a/src/engine/SCons/Errors.py b/src/engine/SCons/Errors.py index 801cf55..8388a0f 100644 --- a/src/engine/SCons/Errors.py +++ b/src/engine/SCons/Errors.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2001 - 2016 The SCons Foundation +# Copyright (c) 2001 - 2017 The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -28,72 +28,74 @@ and user errors in SCons. """ -__revision__ = "src/engine/SCons/Errors.py rel_2.5.1:3735:9dc6cee5c168 2016/11/03 14:02:02 bdbaddog" +__revision__ = "src/engine/SCons/Errors.py rel_3.0.0:4395:8972f6a2f699 2017/09/18 12:59:24 bdbaddog" +import shutil import SCons.Util -import exceptions class BuildError(Exception): - """ Errors occuring while building. + """ Errors occurring while building. BuildError have the following attributes: + ========================================= - Information about the cause of the build error: - ----------------------------------------------- + Information about the cause of the build error: + ----------------------------------------------- - errstr : a description of the error message + errstr : a description of the error message - status : the return code of the action that caused the build - error. Must be set to a non-zero value even if the - build error is not due to an action returning a - non-zero returned code. + status : the return code of the action that caused the build error. + Must be set to a non-zero value even if the build error is not due + to an action returning a non-zero returned code. - exitstatus : SCons exit status due to this build error. - Must be nonzero unless due to an explicit Exit() - call. Not always the same as status, since - actions return a status code that should be - respected, but SCons typically exits with 2 - irrespective of the return value of the failed - action. + exitstatus : SCons exit status due to this build error. + Must be nonzero unless due to an explicit Exit() + call. Not always the same as status, since + actions return a status code that should be + respected, but SCons typically exits with 2 + irrespective of the return value of the failed + action. - filename : The name of the file or directory that caused the - build error. Set to None if no files are associated with - this error. This might be different from the target - being built. For example, failure to create the - directory in which the target file will appear. It - can be None if the error is not due to a particular - filename. + filename : The name of the file or directory that caused the + build error. Set to None if no files are associated with + this error. This might be different from the target + being built. For example, failure to create the + directory in which the target file will appear. It + can be None if the error is not due to a particular + filename. - exc_info : Info about exception that caused the build - error. Set to (None, None, None) if this build - error is not due to an exception. + exc_info : Info about exception that caused the build + error. Set to (None, None, None) if this build + error is not due to an exception. - Information about the cause of the location of the error: - --------------------------------------------------------- + Information about the cause of the location of the error: + --------------------------------------------------------- - node : the error occured while building this target node(s) - - executor : the executor that caused the build to fail (might - be None if the build failures is not due to the - executor failing) - - action : the action that caused the build to fail (might be - None if the build failures is not due to the an - action failure) + node : the error occured while building this target node(s) + + executor : the executor that caused the build to fail (might + be None if the build failures is not due to the + executor failing) - command : the command line for the action that caused the - build to fail (might be None if the build failures - is not due to the an action failure) - """ + action : the action that caused the build to fail (might be + None if the build failures is not due to the an + action failure) + + command : the command line for the action that caused the + build to fail (might be None if the build failures + is not due to the an action failure) + """ - def __init__(self, + def __init__(self, node=None, errstr="Unknown error", status=2, exitstatus=2, filename=None, executor=None, action=None, command=None, exc_info=(None, None, None)): - - self.errstr = errstr + + # py3: errstr should be string and not bytes. + + self.errstr = SCons.Util.to_str(errstr) self.status = status self.exitstatus = exitstatus self.filename = filename @@ -104,7 +106,7 @@ class BuildError(Exception): self.action = action self.command = command - Exception.__init__(self, node, errstr, status, exitstatus, filename, + Exception.__init__(self, node, errstr, status, exitstatus, filename, executor, action, command, exc_info) def __str__(self): @@ -139,13 +141,17 @@ def convert_to_BuildError(status, exc_info=None): """ Convert any return code a BuildError Exception. - `status' can either be a return code or an Exception. + :Parameters: + - `status`: can either be a return code or an Exception. + The buildError.status we set here will normally be used as the exit status of the "scons" process. """ + if not exc_info and isinstance(status, Exception): exc_info = (status.__class__, status, None) + if isinstance(status, BuildError): buildError = status buildError.exitstatus = 2 # always exit with 2 on build errors @@ -163,14 +169,32 @@ def convert_to_BuildError(status, exc_info=None): status=2, exitstatus=2, exc_info=exc_info) - elif isinstance(status, exceptions.EnvironmentError): + elif isinstance(status, shutil.SameFileError): + # PY3 has a exception for when copying file to itself + # It's object provides info differently than below + try: + filename = status.filename + except AttributeError: + filename = None + + buildError = BuildError( + errstr=status.args[0], + status=status.errno, + exitstatus=2, + filename=filename, + exc_info=exc_info) + + elif isinstance(status, (EnvironmentError, OSError, IOError)): # If an IOError/OSError happens, raise a BuildError. # Report the name of the file or directory that caused the # error, which might be different from the target being built # (for example, failure to create the directory in which the # target file will appear). - try: filename = status.filename - except AttributeError: filename = None + try: + filename = status.filename + except AttributeError: + filename = None + buildError = BuildError( errstr=status.strerror, status=status.errno, @@ -195,7 +219,7 @@ def convert_to_BuildError(status, exc_info=None): exitstatus=2) #import sys - #sys.stderr.write("convert_to_BuildError: status %s => (errstr %s, status %s)"%(status,buildError.errstr, buildError.status)) + #sys.stderr.write("convert_to_BuildError: status %s => (errstr %s, status %s)\n"%(status,buildError.errstr, buildError.status)) return buildError # Local Variables: |