summaryrefslogtreecommitdiffstats
path: root/bitbake/lib
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib')
-rw-r--r--bitbake/lib/bb/build.py61
1 files changed, 50 insertions, 11 deletions
diff --git a/bitbake/lib/bb/build.py b/bitbake/lib/bb/build.py
index 977b02fc63..98cbc48cd4 100644
--- a/bitbake/lib/bb/build.py
+++ b/bitbake/lib/bb/build.py
@@ -303,20 +303,59 @@ def exec_func_python(func, d, runfile, cwd=None):
303 303
304def shell_trap_code(): 304def shell_trap_code():
305 return '''#!/bin/sh\n 305 return '''#!/bin/sh\n
306__BITBAKE_LAST_LINE=0
307
306# Emit a useful diagnostic if something fails: 308# Emit a useful diagnostic if something fails:
307bb_exit_handler() { 309bb_sh_exit_handler() {
308 ret=$? 310 ret=$?
309 case $ret in 311 if [ "$ret" != 0 ]; then
310 0) ;; 312 echo "WARNING: exit code $ret from a shell command."
311 *) case $BASH_VERSION in 313 fi
312 "") echo "WARNING: exit code $ret from a shell command.";; 314 exit $ret
313 *) echo "WARNING: ${BASH_SOURCE[0]}:${BASH_LINENO[0]} exit $ret from '$BASH_COMMAND'";;
314 esac
315 exit $ret
316 esac
317} 315}
318trap 'bb_exit_handler' 0 316
319set -e 317bb_bash_exit_handler() {
318 ret=$?
319 trap "" DEBUG
320 if [ "$ret" != 0 ]; then
321 echo "WARNING: ${BASH_SOURCE[0]}:${__BITBAKE_LAST_LINE} exit $ret from '$1'"
322
323 echo "WARNING: Backtrace (BB generated script): "
324 for i in $(seq 1 $((${#FUNCNAME[@]} - 1))); do
325 if [ "$i" -eq 1 ]; then
326 echo -e "\t#$((i)): ${FUNCNAME[$i]}, ${BASH_SOURCE[$((i-1))]}, line ${__BITBAKE_LAST_LINE}"
327 else
328 echo -e "\t#$((i)): ${FUNCNAME[$i]}, ${BASH_SOURCE[$((i-1))]}, line ${BASH_LINENO[$((i-1))]}"
329 fi
330 done
331 fi
332 exit $ret
333}
334
335bb_bash_debug_handler() {
336 local line=${BASH_LINENO[0]}
337 # For some reason the DEBUG trap trips with lineno=1 when scripts exit; ignore it
338 if [ "$line" -eq 1 ]; then
339 return
340 fi
341
342 # Track the line number of commands as they execute. This is so we can have access to the failing line number
343 # 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
344 if [ "${FUNCNAME[1]}" != "bb_bash_exit_handler" ]; then
345 __BITBAKE_LAST_LINE=$line
346 fi
347}
348
349case $BASH_VERSION in
350"") trap 'bb_sh_exit_handler' 0
351 set -e
352 ;;
353*) trap 'bb_bash_exit_handler "$BASH_COMMAND"' 0
354 trap 'bb_bash_debug_handler' DEBUG
355 set -eE
356 shopt -s extdebug
357 ;;
358esac
320''' 359'''
321 360
322def create_progress_handler(func, progress, logfile, d): 361def create_progress_handler(func, progress, logfile, d):