mirror of
https://git.yoctoproject.org/poky
synced 2026-05-08 17:19:20 +00:00
bitbake: build: print a backtrace when a Bash shell function fails
The trick here is to use a DEBUG trap to record the line number of each command as they execute. This is so we can report the real line number of the failing command, which is otherwise not possible in a Bash EXIT trap. See http://gnu-bash.2382.n7.nabble.com/trap-echo-quot-trap-exit-on-LINENO-quot-EXIT-gt-wrong-linenumber-td3666.html (Bitbake rev: 8366e2ad5fdad3972766b40b23188908330067ee) Signed-off-by: Chris Laplante <chris.laplante@agilent.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
committed by
Richard Purdie
parent
bd1da2aca0
commit
b1cd7723c4
+50
-11
@@ -303,20 +303,59 @@ def exec_func_python(func, d, runfile, cwd=None):
|
||||
|
||||
def shell_trap_code():
|
||||
return '''#!/bin/sh\n
|
||||
__BITBAKE_LAST_LINE=0
|
||||
|
||||
# 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_exit_handler() {
|
||||
ret=$?
|
||||
trap "" DEBUG
|
||||
if [ "$ret" != 0 ]; then
|
||||
echo "WARNING: ${BASH_SOURCE[0]}:${__BITBAKE_LAST_LINE} exit $ret from '$1'"
|
||||
|
||||
echo "WARNING: Backtrace (BB generated script): "
|
||||
for i in $(seq 1 $((${#FUNCNAME[@]} - 1))); do
|
||||
if [ "$i" -eq 1 ]; then
|
||||
echo -e "\t#$((i)): ${FUNCNAME[$i]}, ${BASH_SOURCE[$((i-1))]}, line ${__BITBAKE_LAST_LINE}"
|
||||
else
|
||||
echo -e "\t#$((i)): ${FUNCNAME[$i]}, ${BASH_SOURCE[$((i-1))]}, line ${BASH_LINENO[$((i-1))]}"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
exit $ret
|
||||
}
|
||||
|
||||
bb_bash_debug_handler() {
|
||||
local line=${BASH_LINENO[0]}
|
||||
# For some reason the DEBUG trap trips with lineno=1 when scripts exit; ignore it
|
||||
if [ "$line" -eq 1 ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
# Track the line number of commands as they execute. This is so we can have access to the failing line number
|
||||
# in the EXIT trap. See http://gnu-bash.2382.n7.nabble.com/trap-echo-quot-trap-exit-on-LINENO-quot-EXIT-gt-wrong-linenumber-td3666.html
|
||||
if [ "${FUNCNAME[1]}" != "bb_bash_exit_handler" ]; then
|
||||
__BITBAKE_LAST_LINE=$line
|
||||
fi
|
||||
}
|
||||
|
||||
case $BASH_VERSION in
|
||||
"") trap 'bb_sh_exit_handler' 0
|
||||
set -e
|
||||
;;
|
||||
*) trap 'bb_bash_exit_handler "$BASH_COMMAND"' 0
|
||||
trap 'bb_bash_debug_handler' DEBUG
|
||||
set -eE
|
||||
shopt -s extdebug
|
||||
;;
|
||||
esac
|
||||
'''
|
||||
|
||||
def create_progress_handler(func, progress, logfile, d):
|
||||
|
||||
Reference in New Issue
Block a user