align the filename and line numbers in the output of the stack
authorZac Medico <zmedico@gentoo.org>
Thu, 27 Sep 2007 01:38:27 +0000 (01:38 -0000)
committerZac Medico <zmedico@gentoo.org>
Thu, 27 Sep 2007 01:38:27 +0000 (01:38 -0000)
dump so that it is much easier to read (trunk r7842)

svn path=/main/branches/2.1.2/; revision=7843

bin/ebuild.sh

index c2b06b69181e957bf77bd3f38a6e38695ba6dbc2..c85a49da79921816cc8567f5a84eafcdafc02fcc 100755 (executable)
@@ -284,23 +284,34 @@ register_die_hook() {
 diefunc() {
        local funcname="$1" lineno="$2" exitcode="$3"
        shift 3
+
+       local n filespacing=0 linespacing=0
+       # setup spacing to make output easier to read
+       for ((n = ${#FUNCNAME[@]} - 1; n >= 0; --n)); do
+               sourcefile=${BASH_SOURCE[${n}]} sourcefile=${sourcefile##*/}
+               lineno=${BASH_LINENO[${n}]}
+               ((filespacing < ${#sourcefile})) && filespacing=${#sourcefile}
+               ((linespacing < ${#lineno}))     && linespacing=${#lineno}
+       done
+
        eerror
        eerror "ERROR: $CATEGORY/$PF failed."
-       dump_trace 2
-       eerror "  ${BASH_SOURCE[1]##*/}, line ${BASH_LINENO[0]}:   Called die"
+       dump_trace 2 ${filespacing} ${linespacing}
+       eerror "  $(printf "%${filespacing}s" "${BASH_SOURCE[1]##*/}"), line $(printf "%${linespacing}s" "${BASH_LINENO[0]}"):  Called die"
+       eerror
+       eerror " ${*:-(no error message)}"
        eerror
-       eerror "${*:-(no error message)}"
        eerror "If you need support, post the topmost build error, and the call stack if relevant."
-       [ -n "${PORTAGE_LOG_FILE}" ] && \
-               eerror "A complete build log is located at '${PORTAGE_LOG_FILE}'."
-       if [ -n "${EBUILD_OVERLAY_ECLASSES}" ] ; then
+       [[ -n ${PORTAGE_LOG_FILE} ]] \
+               && eerror "A complete build log is located at '${PORTAGE_LOG_FILE}'."
+       if [[ -n ${EBUILD_OVERLAY_ECLASSES} ]] ; then
                eerror "This ebuild used the following eclasses from overlays:"
                local x
                for x in ${EBUILD_OVERLAY_ECLASSES} ; do
                        eerror "  ${x}"
                done
        fi
-       if [ "${EBUILD#${PORTDIR}/}" == "${EBUILD}" ] ; then
+       if [[ "${EBUILD#${PORTDIR}/}" == "${EBUILD}" ]] ; then
                local overlay=${EBUILD%/*}
                overlay=${overlay%/*}
                overlay=${overlay%/*}
@@ -308,7 +319,7 @@ diefunc() {
        fi
        eerror
 
-       if [ "${EBUILD_PHASE/depend}" == "${EBUILD_PHASE}" ]; then
+       if [[ "${EBUILD_PHASE/depend}" == "${EBUILD_PHASE}" ]] ; then
                local x
                for x in $EBUILD_DEATH_HOOKS; do
                        ${x} "$@" >&2 1>&2
@@ -322,19 +333,16 @@ diefunc() {
 
 shopt -s extdebug &> /dev/null
 
-# usage- first arg is the number of funcs on the stack to ignore.
-# defaults to 1 (ignoring dump_trace)
+# dump_trace([number of funcs on stack to skip],
+#            [whitespacing for filenames],
+#            [whitespacing for line numbers])
 dump_trace() {
        local funcname="" sourcefile="" lineno="" n e s="yes"
+       declare -i strip=${1:-1}
+       local filespacing=$2 linespacing=$3
 
-       declare -i strip=1
-
-       if [[ -n $1 ]]; then
-               strip=$(( $1 ))
-       fi
-       
        eerror "Call stack:"
-       for (( n = ${#FUNCNAME[@]} - 1, p = ${#BASH_ARGV[@]} ; n > $strip ; n-- )) ; do
+       for (( n = ${#FUNCNAME[@]} - 1, p = ${#BASH_ARGV[@]} ; n > ${strip} ; n-- )) ; do
                funcname=${FUNCNAME[${n} - 1]}
                sourcefile=$(basename ${BASH_SOURCE[${n}]})
                lineno=${BASH_LINENO[${n} - 1]}
@@ -347,7 +355,7 @@ dump_trace() {
                        done
                        (( p -= ${BASH_ARGC[${n} - 1]} ))
                fi
-               eerror "  ${sourcefile}, line ${lineno}:   Called ${funcname}${args:+ ${args}}"
+               eerror "  $(printf "%${filespacing}s" "${sourcefile}"), line $(printf "%${linespacing}s" "${lineno}"):  Called ${funcname}${args:+ ${args}}"
        done
 }