[Scons-users] SCons.Script.GetBuildFailures not reporting BuildError raised by pseudo-builder
Jean-Baptiste Lab
jeanbaptiste.lab at gmail.com
Mon Mar 6 07:43:18 EST 2017
On 2017-03-06 11:51, Vrijnsen, Jeroen wrote:
>
> No-one?
>
> To be more specific, I use SCons 2.3.4, and the following is a simple
> way to reproduce it:
>
>
> /_SConstruct:_/
>
> import os
> import SCons.Errors
>
> env = Environment(ENV = {'PATH' : os.environ['PATH']})
> env.SConscript(dirs='.', name='scons_hooks.py', exports='env',
> duplicate=0)
>
> raise SCons.Errors.BuildError(errstr="RAISED MY ERROR")
>
> /_scons_hooks.py:_/
> import atexit
> import os
> import SCons.Errors
> import SCons.Script
> import sys
>
> def buildFailureToString(bf):
> """Convert an element of GetBuildFailures() to a string
> in a useful way."""
> if bf is None: # unknown targets product None in list
> return '(unknown tgt)'
> elif isinstance(bf, SCons.Errors.StopError):
> return str(bf)
> elif bf.node:
> return str(bf.node) + ': ' + bf.errstr
> elif bf.filename:
> return bf.filename + ': ' + bf.errstr
> return 'unknown failure: ' + bf.errstr
>
> def buildStatus():
> """Convert the build status to a 2-tuple, (status, msg)."""
> bf = SCons.Script.GetBuildFailures()
> if bf:
> # bf is normally a list of build failures; if an element is None,
> # it's because of a target that scons doesn't know anything about.
> status = 1
> message = os.linesep.join(["Failed building %s" %
> buildFailureToString(x) for x in bf if x is not None])
> else:
> # if bf is None, the build completed successfully.
> status = 0
> message = ''
>
> return (status, message)
>
> def displayBuildStatus():
> """
> Display the build status. Called by atexit. Here you could do all
> kinds of complicated things.
> """
> status, message = buildStatus()
> if status:
> print message
> print "Build FAILED!!!!"
> else:
> print "Build SUCCEEDED"
> atexit.register(displayBuildStatus)
>
>
> This happily prints 'succeeded', but I want it to print 'failed'... is
> that possible?
>
> -Jeroen
>
>
> ------------------------------------------------------------------------
> The information contained in this message may be confidential and
> legally protected under applicable law. The message is intended solely
> for the addressee(s). If you are not the intended recipient, you are
> hereby notified that any use, forwarding, dissemination, or
> reproduction of this message is strictly prohibited and may be
> unlawful. If you are not the intended recipient, please contact the
> sender by return e-mail and destroy all copies of the original message.
>
>
> _______________________________________________
> Scons-users mailing list
> Scons-users at scons.org
> https://pairlist4.pair.net/mailman/listinfo/scons-users
There's an issue in the example you give which I think is the source of
the behaviour you are seeing: you're raising the BuildError exception
outside of a builder.
I modified your example to raise the exception from a Builder function:
import os
import SCons.Errors
def build_function(target, source, env):
raise SCons.Errors.BuildError(errstr="RAISED MY ERROR") # HERE
return None
bld = Builder(action = build_function)
env = Environment(BUILDERS = {'Foo' : bld}, ENV = {'PATH' : os.environ['PATH']})
env.Foo('scons_hooks.py')
env.SConscript(dirs='.', name='scons_hooks.py', exports='env', duplicate=0)
And I get the output you're expecting:
jbl at jbl-mint:~/tmp $ scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
build_function(["scons_hooks"], ["scons_hooks.py"])
scons: *** [scons_hooks] RAISED MY ERROR
scons: building terminated because of errors.
[BuildError(None, 'RAISED MY ERROR', 2, 2, None, None, None, None,
(None, None, None))]
Failed building scons_hooks: RAISED MY ERROR
Build FAILED!!!!
jbl at jbl-mint:~/tmp $
As opposed to the output from your example:
jbl at jbl-mint:~/tmp $ scons
scons: Reading SConscript files ...
RAISED MY ERROR
Build SUCCEEDED
jbl at jbl-mint:~/tmp $
Hope this helps,
JB
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20170306/cfab86c6/attachment-0001.html>
More information about the Scons-users
mailing list