# HG changeset patch # User "Yann E. MORIN" # Date 1300227517 -3600 # Node ID 580f427595bcf1789e024c78b7c59335f9b28c10 # Parent 730e2d63296b74541c77e2044c73abdf2a94534c scripts: allow logging of commands with variables In a lot of places, we need to call some commands with specific variable settings, a-la: var1=val1 var2=val2 /foo/bar/buz opt1 opt2 Unfortunately, we currently can not log the variable settings. Enhance CT_DoExecLog with a crude heuristic that works pretty well and that can also log setting variables. Reported-by: ANDY KENNEDY Signed-off-by: "Yann E. MORIN" diff -r 730e2d63296b -r 580f427595bc scripts/functions --- a/scripts/functions Sun Mar 20 00:02:21 2011 +0100 +++ b/scripts/functions Tue Mar 15 23:18:37 2011 +0100 @@ -119,12 +119,26 @@ } # Execute an action, and log its messages -# Usage: [VAR=val...] CT_DoExecLog +# It is possible to even log local variable assignments (a-la: var=val ./cmd opts) +# Usage: CT_DoExecLog [VAR=val...] [parameters...] CT_DoExecLog() { local level="$1" shift - CT_DoLog DEBUG "==> Executing: '${*}'" + ( + for i in "$@"; do + tmp_log+="'${i}' " + done + while true; do + case "${1}" in + *=*) eval export "'${1}'"; shift;; + *) break;; + esac + done + CT_DoLog DEBUG "==> Executing: ${tmp_log}" "${@}" 2>&1 |CT_DoLog "${level}" + ) + # Catch failure of the sub-shell + [ $? -eq 0 ] } # Tail message to be logged whatever happens