build.py: Emit meaningful errors when exiting automatically
cover build.py: Emit meaningful errors when exiting automatically
The behavior of "set -e" has flaws, the biggest of which is that the exit is silent. Add an exit handler to run.* scripts so that the failure will be diagnosed meaningfully.
The following changes since commit 90fd57ee3cb2856c10bda1f5af4879d2b7cf2668:
Cristiana Voicu (1):
hob/imageconfigurationpage: a 'hob-image' appears listed in the base image combo box
are available in the git repository at:
git://git.yoctoproject.org/poky-contrib seebs/errors
http://git.yoctoproject.org/cgit.cgi/poky-contrib/log/?h=seebs/errors
Peter Seebach (1):
build.py: Provide useful diagnostics when exiting.
lib/bb/build.py | 24 +++++++++++++++++++++++- 1 files changed, 23 insertions(+), 1 deletions(-)
PATCH 1/1 build.py: Provide useful diagnostics when exiting.
Running scripts with 'set -e' produces silent failures with no diagnostic. Add an exit handler which produces diagnostics, including details of what was running if the shell seems to be bash.
--- lib/bb/build.py | 24 +++++++++++++++++++++++- 1 files changed, 23 insertions(+), 1 deletions(-)
lib/bb/build.py +23 -1
@@ -249,7 +249,23 @@ def exec_func_shell(func, d, runfile, cwd=None): d.delVarFlag('PWD', 'export') with open(runfile, 'w') as script: - script.write('#!/bin/sh -e\n') + script.write('''#!/bin/sh\n +# Emit a useful diagnostic if something fails: +bb_exit_handler() { + ret=$? + case $ret in + 0) ;; + *) case $BASH_VERSION in + "") echo "WARNING: exit code $ret from a shell command.";; + *) echo "WARNING: ${BASH_SOURCE[0]}:${BASH_LINENO[0]} exit $ret from + \"$BASH_COMMAND\"";; + esac + exit $ret + esac +} +trap 'bb_exit_handler' 0 +set -e +''') data.emit_func(func, script, d) if bb.msg.loggerVerboseLogs:
@@ -257,6 +273,12 @@ def exec_func_shell(func, d, runfile, cwd=None): if cwd: script.write("cd %s\n" % cwd) script.write("%s\n" % func) + script.write(''' +# cleanup +ret=$? +trap '' 0 +exit $? +''') os.chmod(runfile, 0775)
Signature · 1 line
1.7.0.4