Skip to content

Commit

Permalink
build: print a backtrace when a Bash shell function fails
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Laplante <[email protected]>
Signed-off-by: Richard Purdie <[email protected]>
  • Loading branch information
chris-laplante authored and rpurdie committed Aug 7, 2020
1 parent 9747211 commit 81098a1
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions lib/bb/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,19 +304,33 @@ def exec_func_python(func, d, runfile, cwd=None):
def shell_trap_code():
return '''#!/bin/sh\n
# Emit a useful diagnostic if something fails:
bb_exit_handler() {
bb_sh_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
if [ "$ret" != 0 ]; then
echo "WARNING: exit code $ret from a shell command."
fi
exit $ret
}
trap 'bb_exit_handler' 0
set -e
bb_bash_err_handler() {
ret=$?
echo "WARNING: ${BASH_SOURCE[0]}:${BASH_LINENO[0]} exit $ret from '$BASH_COMMAND'"
echo "WARNING: Backtrace (BB generated script): "
for ((i=1; i<${#FUNCNAME[@]}; i++)); do
echo "\t#$((i-1)): ${FUNCNAME[$i]}, ${BASH_SOURCE[$((i-1))]}, line ${BASH_LINENO[$((i-1))]}"
done
exit $ret
}
case $BASH_VERSION in
"") trap 'bb_sh_exit_handler' 0
set -e
;;
*) trap 'bb_bash_err_handler' ERR
set -eE
esac
'''

def create_progress_handler(func, progress, logfile, d):
Expand Down

0 comments on commit 81098a1

Please sign in to comment.