diff options
author | Peter Seebach <peter.seebach@windriver.com> | 2012-10-10 17:11:54 -0500 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2013-08-20 22:43:42 +0100 |
commit | f6ab9274bc453eee9b93fa377ccce6134c43899c (patch) | |
tree | 186a7fa0e05b3dc9a2fd4d6a3df3168a04feb1ba /bitbake/lib | |
parent | fe227a023e30f6651618423ab527cde21a350d1a (diff) | |
download | poky-f6ab9274bc453eee9b93fa377ccce6134c43899c.tar.gz |
bitbake: 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.
(Bitbake rev: e213e6a4c297a4f1c22eed15bd7b4cbc0e9eab4f)
Signed-off-by: Peter Seebach <peter.seebach@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib')
-rw-r--r-- | bitbake/lib/bb/build.py | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/bitbake/lib/bb/build.py b/bitbake/lib/bb/build.py index e28655e4b7..6fffbc5da3 100644 --- a/bitbake/lib/bb/build.py +++ b/bitbake/lib/bb/build.py | |||
@@ -250,7 +250,24 @@ def exec_func_shell(func, d, runfile, cwd=None): | |||
250 | d.delVarFlag('PWD', 'export') | 250 | d.delVarFlag('PWD', 'export') |
251 | 251 | ||
252 | with open(runfile, 'w') as script: | 252 | with open(runfile, 'w') as script: |
253 | script.write('#!/bin/sh -e\n') | 253 | script.write('''#!/bin/sh\n |
254 | # Emit a useful diagnostic if something fails: | ||
255 | bb_exit_handler() { | ||
256 | ret=$? | ||
257 | case $ret in | ||
258 | 0) ;; | ||
259 | *) case $BASH_VERSION in | ||
260 | "") echo "WARNING: exit code $ret from a shell command.";; | ||
261 | *) echo "WARNING: ${BASH_SOURCE[0]}:${BASH_LINENO[0]} exit $ret from | ||
262 | \"$BASH_COMMAND\"";; | ||
263 | esac | ||
264 | exit $ret | ||
265 | esac | ||
266 | } | ||
267 | trap 'bb_exit_handler' 0 | ||
268 | set -e | ||
269 | ''') | ||
270 | |||
254 | bb.data.emit_func(func, script, d) | 271 | bb.data.emit_func(func, script, d) |
255 | 272 | ||
256 | if bb.msg.loggerVerboseLogs: | 273 | if bb.msg.loggerVerboseLogs: |
@@ -258,6 +275,12 @@ def exec_func_shell(func, d, runfile, cwd=None): | |||
258 | if cwd: | 275 | if cwd: |
259 | script.write("cd %s\n" % cwd) | 276 | script.write("cd %s\n" % cwd) |
260 | script.write("%s\n" % func) | 277 | script.write("%s\n" % func) |
278 | script.write(''' | ||
279 | # cleanup | ||
280 | ret=$? | ||
281 | trap '' 0 | ||
282 | exit $? | ||
283 | ''') | ||
261 | 284 | ||
262 | os.chmod(runfile, 0775) | 285 | os.chmod(runfile, 0775) |
263 | 286 | ||