1.1 --- a/scripts/functions Mon Nov 21 23:35:21 2011 +0100
1.2 +++ b/scripts/functions Tue Dec 13 23:32:39 2011 +0100
1.3 @@ -6,52 +6,52 @@
1.4 CT_OnError() {
1.5 local ret=$?
1.6 local intro
1.7 - local file
1.8 - local line
1.9 - local func
1.10 - local step_depth
1.11 + local file line func
1.12 + local step step_depth
1.13
1.14 - # Bail out early in subshell, the upper level shell will act accordingly.
1.15 - [ ${BASH_SUBSHELL} -eq 0 ] || exit $ret
1.16 + # To avoid printing the backtace for each sub-shell
1.17 + # up to the top-level, just remember we've dumped it
1.18 + if [ ! -f "${CT_BUILD_DIR}/backtrace" ]; then
1.19 + touch "${CT_BUILD_DIR}/backtrace"
1.20
1.21 - # Print steps backtrace
1.22 - step_depth=${CT_STEP_COUNT}
1.23 - CT_STEP_COUNT=2
1.24 - CT_DoLog ERROR ""
1.25 - intro="Build failed"
1.26 - for((step=step_depth; step>1; step--)); do
1.27 - CT_DoLog ERROR ">> ${intro} in step '${CT_STEP_MESSAGE[${step}]}'"
1.28 - intro=" called"
1.29 - done
1.30 + # Print steps backtrace
1.31 + step_depth=${CT_STEP_COUNT}
1.32 + CT_STEP_COUNT=1 # To have a zero-indentation
1.33 + CT_DoLog ERROR ""
1.34 + CT_DoLog ERROR ">>"
1.35 + intro="Build failed"
1.36 + for((step=step_depth; step>0; step--)); do
1.37 + CT_DoLog ERROR ">> ${intro} in step '${CT_STEP_MESSAGE[${step}]}'"
1.38 + intro=" called"
1.39 + done
1.40
1.41 - # Print functions backtrace
1.42 - intro="Error happened in"
1.43 - offset=1
1.44 - CT_DoLog ERROR ">>"
1.45 - for((depth=1; ${BASH_LINENO[$((${depth}-1))]}>0; depth++)); do
1.46 - file="${BASH_SOURCE[${depth}]#${CT_LIB_DIR}/}"
1.47 - case "${depth}" in
1.48 - 1) line="";;
1.49 - *) line="@${BASH_LINENO[${depth}-1]}"
1.50 - esac
1.51 - func="${FUNCNAME[${depth}]}"
1.52 - CT_DoLog ERROR ">> ${intro}: ${func}[${file}${line}]"
1.53 - intro=" called from"
1.54 - done
1.55 + # Print functions backtrace
1.56 + intro="Error happened in"
1.57 + CT_DoLog ERROR ">>"
1.58 + for((depth=1; ${BASH_LINENO[$((${depth}-1))]}>0; depth++)); do
1.59 + file="${BASH_SOURCE[${depth}]#${CT_LIB_DIR}/}"
1.60 + func="${FUNCNAME[${depth}]}"
1.61 + line="@${BASH_LINENO[${depth}-1]:-?}"
1.62 + CT_DoLog ERROR ">> ${intro}: ${func}[${file}${line}]"
1.63 + intro=" called from"
1.64 + done
1.65 + fi
1.66
1.67 - # Help diagnose the error
1.68 - CT_DoLog ERROR ">>"
1.69 - if [ "${CT_LOG_TO_FILE}" = "y" ]; then
1.70 - CT_DoLog ERROR ">> For more info on this error, look at the file: '${tmp_log_file#${CT_TOP_DIR}/}'"
1.71 + # And finally, in top-level shell, print some hints
1.72 + if [ ${BASH_SUBSHELL} -eq 0 ]; then
1.73 + # Help diagnose the error
1.74 + CT_STEP_COUNT=1 # To have a zero-indentation
1.75 + CT_DoLog ERROR ">>"
1.76 + if [ "${CT_LOG_TO_FILE}" = "y" ]; then
1.77 + CT_DoLog ERROR ">> For more info on this error, look at the file: '${tmp_log_file#${CT_TOP_DIR}/}'"
1.78 + fi
1.79 + CT_DoLog ERROR ">> There is a list of known issues, some with workarounds, in:"
1.80 + CT_DoLog ERROR ">> '${CT_DOC_DIR#${CT_TOP_DIR}/}/B - Known issues.txt'"
1.81 +
1.82 + CT_DoLog ERROR ""
1.83 + CT_DoEnd ERROR
1.84 + rm -f "${CT_BUILD_DIR}/backtrace"
1.85 fi
1.86 - CT_DoLog ERROR ">> There is a list of known issues, some with workarounds, in:"
1.87 - CT_DoLog ERROR ">> '${CT_DOC_DIR#${CT_TOP_DIR}/}/B - Known issues.txt'"
1.88 -
1.89 - CT_DoLog ERROR ""
1.90 - CT_DoLog ERROR "Build failed in step '${CT_STEP_MESSAGE[${CT_STEP_COUNT}]}'"
1.91 -
1.92 - CT_DoLog ERROR ""
1.93 - CT_DoEnd ERROR
1.94 exit $ret
1.95 }
1.96
1.97 @@ -288,7 +288,7 @@
1.98 }
1.99
1.100 CT_STEP_COUNT=1
1.101 -CT_STEP_MESSAGE[${CT_STEP_COUNT}]="<none>"
1.102 +CT_STEP_MESSAGE[${CT_STEP_COUNT}]="(top-level)"
1.103 # Memorise a step being done so that any error is caught
1.104 # Usage: CT_DoStep <loglevel> <message>
1.105 CT_DoStep() {