diff options
author | David Spickett <david.spickett@linaro.org> | 2020-05-19 16:29:16 +0100 |
---|---|---|
committer | David Spickett <david.spickett@linaro.org> | 2020-05-22 10:08:40 +0000 |
commit | 8cddf6df427404ca93c9e05339cfa65840d495d3 (patch) | |
tree | fb4995f84bf3459753849eff289f336ed8c2d6cb | |
parent | b5a367d78edd5c46af667b39afedd61bf48a2b23 (diff) |
tcwg_bmk-build.sh/tcwg_gnu-build.sh:
Mark expected exits
It is expected that commands run by
run_step can fail and return non zero.
This causes the build scripts to exit
early and print misleading traceback.
So that we only catch unexpected exits,
mark expected failures with a magic
return code. Only print traceback
when the code is different from this.
Change-Id: I8b92ca1cb941481d4daa8ab87ee74b2b394b24ac
-rw-r--r-- | jenkins-helpers.sh | 47 | ||||
-rwxr-xr-x | tcwg_kernel-build.sh | 2 |
2 files changed, 31 insertions, 18 deletions
diff --git a/jenkins-helpers.sh b/jenkins-helpers.sh index 3ad79dda..389b7092 100644 --- a/jenkins-helpers.sh +++ b/jenkins-helpers.sh @@ -1245,7 +1245,7 @@ run_step () 0:*) ;; *:stop_on_fail) echo "STOPPING before ${step[*]} due to previous failure" - false + return $EXPECTED_EXIT ;; *:skip_on_fail) echo "SKIPPING ${step[*]} due to previous failure" @@ -1281,7 +1281,7 @@ run_step () 0:*) ;; *:stop_on_fail|*:reset_on_fail) echo "STOPPING at ${step[*]} due to failure" - false + return $EXPECTED_EXIT ;; *:skip_on_fail) echo "CARRYING ON after failure in ${step[*]}" @@ -1310,21 +1310,34 @@ EOF # Print Python style traceback from a trap EXIT # More readable version of running "caller" +# Use this as follows: +# trap 'print_traceback' EXIT +# Then remove the trap at the end of your script: +# trap "" EXIT +# Use EXPECTED_EXIT in your code to mark a non zero +# return as expected. +# return $EXPECTED_EDIT +# Anything other return code will get you a +# traceback (including assert/assert_with_msg) +EXPECTED_EXIT=123 print_traceback () { - echo "ERROR Traceback (most recent call last):" - # Show most recent calls last - # >=1 to skip the trap handler entry - # Start from end-2 to skip the top level "main" entry - # which isn't useful - for (( i=${#FUNCNAME[@]}-2 ; i>=1 ; i-- )) ; do - source_file=${BASH_SOURCE[$i+1]} - line_no=${BASH_LINENO[$i]} - echo " File: $source_file, line $line_no" - # Remove leading whitespace to keep indentation readable - echo " $(sed -e "${line_no}!d" -e 's/^[[:space:]]*//' "$source_file")" - done - # We don't know the line number of the exit itself when we trap EXIT - echo " File: ${BASH_SOURCE[0]}, line ${BASH_LINENO[0]}" - echo " (trap handler, 'exit' call line is unknown)" + local exit_status=$? + if [ $exit_status != $EXPECTED_EXIT ]; then + echo "ERROR Traceback (most recent call last):" + # Show most recent calls last + # >=1 to skip the trap handler entry + # Start from end-2 to skip the top level "main" entry + # which isn't useful + for (( i=${#FUNCNAME[@]}-2 ; i>=1 ; i-- )) ; do + source_file=${BASH_SOURCE[$i+1]} + line_no=${BASH_LINENO[$i]} + echo " File: $source_file, line $line_no" + # Remove leading whitespace to keep indentation readable + echo " $(sed -e "${line_no}!d" -e 's/^[[:space:]]*//' "$source_file")" + done + # We don't know the line number of the exit itself when we trap EXIT + echo " File: ${BASH_SOURCE[0]}, line ${BASH_LINENO[0]}" + echo " (trap handler, exit line unknown, exit status was $exit_status)" + fi } diff --git a/tcwg_kernel-build.sh b/tcwg_kernel-build.sh index ef8b4b0d..0010d520 100755 --- a/tcwg_kernel-build.sh +++ b/tcwg_kernel-build.sh @@ -64,7 +64,7 @@ verbose2="${verbose2-false}" if $verbose2; then set -x; fi -trap "eval \"echo ERROR at \${FUNCNAME[0]}:\${BASH_LINENO[0]}\"" EXIT +trap print_traceback EXIT # Set start and finish steps for different modes. default_start_at="" |