Simplify debug-print*() functions code.
authorMichał Górny <mgorny@gentoo.org>
Sun, 24 Oct 2010 07:41:33 +0000 (09:41 +0200)
committerZac Medico <zmedico@gentoo.org>
Sun, 24 Oct 2010 18:34:12 +0000 (11:34 -0700)
Make debug-print() and friends a lot simpler. Thanks to Mike Frysinger
for his suggestions.

bin/ebuild.sh

index 2036094e3428225f408b75610c091084c89233d3..c7f81c50e544488b4ab2397416027a6db5a30da5 100755 (executable)
@@ -1273,36 +1273,28 @@ dyn_help() {
 debug-print() {
        # if $T isn't defined, we're in dep calculation mode and
        # shouldn't do anything
-       [ ! -d "$T" ] && return 0
+       [[ ! -d ${T} || ${#} -eq 0 ]] && return 0
 
-       while [ "$1" ]; do
-
-               # extra user-configurable targets
-               if [ "$ECLASS_DEBUG_OUTPUT" == "on" ]; then
-                       echo "debug: $1" >&2
-               elif [ -n "$ECLASS_DEBUG_OUTPUT" ]; then
-                       echo "debug: $1" >> $ECLASS_DEBUG_OUTPUT
-               fi
-
-               # default target
-               echo "$1" 2>/dev/null >> "${T}/eclass-debug.log"
-               # let the portage user own/write to this file
-               chmod g+w "${T}/eclass-debug.log" &>/dev/null
+       if [[ ${ECLASS_DEBUG_OUTPUT} == on ]]; then
+               printf 'debug: %s\n' "${@}" >&2
+       elif [[ -n ${ECLASS_DEBUG_OUTPUT} ]]; then
+               printf 'debug: %s\n' "${@}" >> "${ECLASS_DEBUG_OUTPUT}"
+       fi
 
-               shift
-       done
+       # default target
+       printf '%s\n' "${@}" >> "${T}/eclass-debug.log"
+       # let the portage user own/write to this file
+       chmod g+w "${T}/eclass-debug.log" &>/dev/null
 }
 
 # The following 2 functions are debug-print() wrappers
 
 debug-print-function() {
-       str="$1: entering function"
-       shift
-       debug-print "$str, parameters: $*"
+       debug-print "${1}, parameters: ${*:2}"
 }
 
 debug-print-section() {
-       debug-print "now in section $*"
+       debug-print "now in section ${*}"
 }
 
 # Sources all eclasses in parameters