From patchwork Wed Oct 10 22:11:54 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [bitbake-devel, 1/1] build.py: Provide useful diagnostics when exiting. Date: Wed, 10 Oct 2012 22:11:54 -0000 From: Peter Seebach X-Patchwork-Id: 38065 Message-Id: <686b0589fc837fda588809544d71d9a4b9d041e8.1349907036.git.peter.seebach@windriver.com> To: bitbake-devel 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. Signed-off-by: Peter Seebach --- lib/bb/build.py | 24 +++++++++++++++++++++++- 1 files changed, 23 insertions(+), 1 deletions(-) diff --git a/lib/bb/build.py b/lib/bb/build.py index 85af42c..f65c415 100644 --- a/lib/bb/build.py +++ b/lib/bb/build.py @@ -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)