catalyst-auto: rework run_cmd pass through

Make the logfile the first arg so the rest of the args are the command
to actually run.  This allows us to properly quote arguments.
This commit is contained in:
Mike Frysinger 2016-12-08 23:51:29 -05:00
parent 12b23fa07e
commit e8186ef489

View file

@ -71,15 +71,16 @@ send_email() {
/usr/sbin/sendmail -f "${EMAIL_FROM}" ${EMAIL_TO//,/ } /usr/sbin/sendmail -f "${EMAIL_FROM}" ${EMAIL_TO//,/ }
} }
# Usage: run_cmd <logfile> <command to run>
run_cmd() { run_cmd() {
local cmd=$1 local logfile="$1"
local logfile=$2 shift
if [ $verbose = 1 ]; then if [ $verbose = 1 ]; then
echo "*** Running command: ${cmd}" echo "*** Running command: $*"
${cmd} 2>&1 | tee "${logfile}" "$@" 2>&1 | tee "${logfile}"
else else
${cmd} &> "${logfile}" "$@" &> "${logfile}"
fi fi
} }
@ -220,7 +221,7 @@ if ! mkdir -p "${TMPDIR}"/{specs,kconfig,log}; then
exit 1 exit 1
fi fi
if ! run_cmd "pre_build" "${TMPDIR}/log/pre_build.log"; then if ! run_cmd "${TMPDIR}/log/pre_build.log" pre_build; then
send_email "Catalyst build error - pre_build" "The pre_build function failed" "${TMPDIR}/log/pre_build.log" send_email "Catalyst build error - pre_build" "The pre_build function failed" "${TMPDIR}/log/pre_build.log"
exit 1 exit 1
fi fi
@ -299,15 +300,15 @@ if [[ ${preclean} -eq 1 ]]; then
fi fi
# Create snapshot # Create snapshot
if ! run_cmd "catalyst -c ${CATALYST_CONFIG} -s ${DATESTAMP}" "${TMPDIR}/log/snapshot.log"; then if ! run_cmd "${TMPDIR}/log/snapshot.log" catalyst -c "${CATALYST_CONFIG}" -s "${DATESTAMP}"; then
send_email "Catalyst build error - snapshot" "" "${TMPDIR}/log/snapshot.log" send_email "Catalyst build error - snapshot" "" "${TMPDIR}/log/snapshot.log"
exit 1 exit 1
fi fi
build_failure=0 build_failure=0
timeprefix="" timeprefix=()
which time >/dev/null && timeprefix="time" which time >/dev/null && timeprefix=( "time" )
for a in "" ${SETS}; do for a in "" ${SETS}; do
if [ -z "${a}" ]; then if [ -z "${a}" ]; then
@ -320,7 +321,7 @@ for a in "" ${SETS}; do
for i in ${!specs_var}; do for i in ${!specs_var}; do
LOGFILE="${TMPDIR}/log/$(echo "${i}" | sed -e 's:/:_:' -e 's:\.spec$::').log" LOGFILE="${TMPDIR}/log/$(echo "${i}" | sed -e 's:/:_:' -e 's:\.spec$::').log"
run_cmd "${timeprefix} catalyst -a -p -c ${CATALYST_CONFIG} -f ${i}" "${LOGFILE}" run_cmd "${LOGFILE}" "${timeprefix[@]}" catalyst -a -p -c "${CATALYST_CONFIG}" -f "${i}"
if [ $? != 0 ]; then if [ $? != 0 ]; then
build_failure=1 build_failure=1
send_email "Catalyst fatal build error - ${i}" "" "${LOGFILE}" send_email "Catalyst fatal build error - ${i}" "" "${LOGFILE}"
@ -330,7 +331,7 @@ for a in "" ${SETS}; do
for i in ${!optional_specs_var}; do for i in ${!optional_specs_var}; do
LOGFILE="${TMPDIR}/log/$(echo "${i}" | sed -e 's:/:_:' -e 's:\.spec$::').log" LOGFILE="${TMPDIR}/log/$(echo "${i}" | sed -e 's:/:_:' -e 's:\.spec$::').log"
run_cmd "${timeprefix} catalyst -a -p -c ${CATALYST_CONFIG} -f ${i}" "${LOGFILE}" run_cmd "${LOGFILE}" "${timeprefix[@]}" catalyst -a -p -c "${CATALYST_CONFIG}" -f "${i}"
if [ $? != 0 ]; then if [ $? != 0 ]; then
build_failure=1 build_failure=1
send_email "Catalyst non-fatal build error - ${i}" "" "${LOGFILE}" send_email "Catalyst non-fatal build error - ${i}" "" "${LOGFILE}"
@ -340,13 +341,13 @@ for a in "" ${SETS}; do
for i in ${!specs_var} ${!optional_specs_var}; do for i in ${!specs_var} ${!optional_specs_var}; do
LOGFILE="${TMPDIR}/log/$(echo "${i}" | sed -e 's:/:_:' -e 's:\.spec$::')_purge.log" LOGFILE="${TMPDIR}/log/$(echo "${i}" | sed -e 's:/:_:' -e 's:\.spec$::')_purge.log"
run_cmd "${timeprefix} catalyst -P -c ${CATALYST_CONFIG} -f ${i}" "${LOGFILE}" run_cmd "${LOGFILE}" "${timeprefix[@]}" catalyst -P -c "${CATALYST_CONFIG}" -f "${i}"
done done
update_symlinks update_symlinks
done done
if ! run_cmd "post_build" "${TMPDIR}/log/post_build.log"; then if ! run_cmd "${TMPDIR}/log/post_build.log" post_build; then
send_email "Catalyst build error - post_build" "The post_build function failed" "${TMPDIR}/log/post_build.log" send_email "Catalyst build error - post_build" "The post_build function failed" "${TMPDIR}/log/post_build.log"
exit 1 exit 1
fi fi