util/abuild: Fix or disable shellcheck warnings

This cleans up the shellcheck warnings in abuild.

Warning count:
1 Unexpected ==.
1 Use "${var:?}" to ensure this never expands to / .
1 VARIABLE appears unused. Verify it or export it.
1 Use "$@" (with quotes) to prevent whitespace problems.
2 Consider using { cmd1; cmd2; } >> file instead of individual redirects.
2 Expressions don't expand in single quotes, use double quotes for that.
3 Prefer [ p ] || [ q ] as [ p -o q ] is not well defined.
4 $/${} is unnecessary on arithmetic variables.
5 Check exit code directly with 'if mycmd;', not indirectly with $?.
5 Use cd ... || exit in case cd fails.
11 Declare and assign separately to avoid masking return values.
13 Use $(..) instead of legacy `..`.
20 Don't use variables in the printf format string.
104 Double quote to prevent globbing.

Change-Id: I9c77e122435ba87ce3a4aee76b5022f7265f9ef2
Signed-off-by: Martin Roth <martinroth@google.com>
Reviewed-on: https://review.coreboot.org/17722
Tested-by: build bot (Jenkins)
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
This commit is contained in:
Martin Roth 2016-11-30 16:32:20 -07:00
parent 861a4b88fa
commit 02c93b9b1f
1 changed files with 150 additions and 129 deletions

View File

@ -32,7 +32,7 @@ export KCONFIG_OVERWRITECONFIG=1
PAYLOAD=/dev/null PAYLOAD=/dev/null
# path to coreboot XGCC # path to coreboot XGCC
XGCCPATH="`pwd`/util/crossgcc/xgcc/bin/" XGCCPATH="${TOP}/util/crossgcc/xgcc/bin/"
# Add XGCC to the path. # Add XGCC to the path.
if [ -d "$XGCCPATH" ] && [[ ":$PATH:" != *":$XGCCPATH:"* ]]; then if [ -d "$XGCCPATH" ] && [[ ":$PATH:" != *":$XGCCPATH:"* ]]; then
@ -77,30 +77,25 @@ quiet=false
# clang mode enabled by -sb option. # clang mode enabled by -sb option.
scanbuild=false scanbuild=false
ARCH=`uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
-e s/i86pc/i386/ \
-e s/arm.*/arm/ -e s/sa110/arm/ -e s/x86_64/amd64/ \
-e "s/Power Macintosh/ppc/"`
trap interrupt INT trap interrupt INT
function interrupt function interrupt
{ {
printf "\n$0: execution interrupted manually.\n" printf "\n%s: execution interrupted manually.\n" "$0"
if [ "$mode" == "junit" ]; then if [ "$mode" == "junit" ]; then
printf "$0: deleting incomplete xml output file.\n" printf "%s: deleting incomplete xml output file.\n" "$0"
fi fi
exit 1 exit 1
} }
function debug function debug
{ {
test "$verbose" == "true" && printf "$*\n" test "$verbose" == "true" && echo "$*"
} }
function junit function junit
{ {
test "$mode" == "junit" && printf "$*\n" >> $XMLFILE test "$mode" == "junit" && echo "$*" >> "$XMLFILE"
return 0 return 0
} }
@ -108,9 +103,9 @@ function junitfile
{ {
test "$mode" == "junit" && { test "$mode" == "junit" && {
printf '<![CDATA[\n' printf '<![CDATA[\n'
cat $1 cat "$1"
printf ']]>\n' printf ']]>\n'
} >> $XMLFILE } >> "$XMLFILE"
} }
# Return mainboard descriptors. # Return mainboard descriptors.
@ -120,6 +115,7 @@ function junitfile
function get_mainboards function get_mainboards
{ {
local search_space=${1-*/*} local search_space=${1-*/*}
# shellcheck disable=SC2086
grep -h "^[[:space:]]*config\>[[:space:]]*\<BOARD_" \ grep -h "^[[:space:]]*config\>[[:space:]]*\<BOARD_" \
${ROOT}/src/mainboard/${search_space}/Kconfig.name 2>/dev/null | \ ${ROOT}/src/mainboard/${search_space}/Kconfig.name 2>/dev/null | \
sed "s,^.*\<BOARD_\([A-Z0-9_]*\)\>.*$,\1," sed "s,^.*\<BOARD_\([A-Z0-9_]*\)\>.*$,\1,"
@ -130,6 +126,7 @@ function mainboard_directory
{ {
local MAINBOARD=$1 local MAINBOARD=$1
# shellcheck disable=SC2086
grep -l "^[[:space:]]*config\>[[:space:]]*\<BOARD_${MAINBOARD}\>" \ grep -l "^[[:space:]]*config\>[[:space:]]*\<BOARD_${MAINBOARD}\>" \
${ROOT}/src/mainboard/*/*/Kconfig.name | \ ${ROOT}/src/mainboard/*/*/Kconfig.name | \
sed "s:^$ROOT/src/mainboard/\(.*\)/Kconfig.name$:\1:" sed "s:^$ROOT/src/mainboard/\(.*\)/Kconfig.name$:\1:"
@ -139,15 +136,17 @@ function mainboard_directory
function mainboard_vendor function mainboard_vendor
{ {
local MAINBOARD=$1 local MAINBOARD=$1
local kconfig_file
local kconfig_file=$( \ # shellcheck disable=SC2086
kconfig_file=$( \
grep -l "^[[:space:]]*config\>[[:space:]]*\<BOARD_${MAINBOARD}\>" \ grep -l "^[[:space:]]*config\>[[:space:]]*\<BOARD_${MAINBOARD}\>" \
${ROOT}/src/mainboard/*/*/Kconfig.name | \ ${ROOT}/src/mainboard/*/*/Kconfig.name | \
sed "s:^\(${ROOT}/src/mainboard/.*\)/.*/\(Kconfig.name\)$:\1/\2:" ) sed "s:^\(${ROOT}/src/mainboard/.*\)/.*/\(Kconfig.name\)$:\1/\2:" )
if [ ! -f "$kconfig_file" ]; then if [ ! -f "$kconfig_file" ]; then
exit 1 exit 1
fi fi
grep "^[[:space:]]*config\>[[:space:]]*\<VENDOR_" $kconfig_file | \ grep "^[[:space:]]*config\>[[:space:]]*\<VENDOR_" "$kconfig_file" | \
sed "s,^.*\<VENDOR_\([A-Z0-9_]*\)\>.*$,\1," sed "s,^.*\<VENDOR_\([A-Z0-9_]*\)\>.*$,\1,"
} }
@ -157,16 +156,18 @@ function mainboard_vendor
# If a directory contains multiple boards, returns them all. # If a directory contains multiple boards, returns them all.
function normalize_target function normalize_target
{ {
local targets=$(get_mainboards $1) local targets
targets=$(get_mainboards "$1")
if [ -n "$targets" ]; then if [ -n "$targets" ]; then
echo $targets echo "$targets"
return return
fi fi
local targets=$(echo $1 | tr ',' ' ') targets=$(echo "$1" | tr ',' ' ')
for i in $targets; do for i in $targets; do
if [ -n "$(mainboard_directory $i)" ]; then if [ -n "$(mainboard_directory "$i")" ]; then
echo $i echo "$i"
else else
echo "$i is not a valid target" >&2 echo "$i is not a valid target" >&2
exit 1 exit 1
@ -174,34 +175,36 @@ function normalize_target
done done
} }
# shellcheck disable=SC2129
function create_config function create_config
{ {
local BUILD_NAME=$1 local BUILD_NAME=$1
local build_dir=$2 local build_dir=$2
local board_srcdir
local config_file=${build_dir}/config.build local config_file="${build_dir}/config.build"
local board_srcdir=$(mainboard_directory ${BUILD_NAME}) board_srcdir="$(mainboard_directory "${BUILD_NAME}")"
mkdir -p ${build_dir} mkdir -p "${build_dir}"
mkdir -p $TARGET/sharedutils mkdir -p "$TARGET/sharedutils"
if [ "$quiet" == "false" ]; then printf " Creating config file for $BUILD_NAME... \n"; fi if [ "$quiet" == "false" ]; then echo " Creating config file for $BUILD_NAME..."; fi
printf "CONFIG_VENDOR_$(mainboard_vendor ${BUILD_NAME})=y\n" > ${config_file} echo "CONFIG_VENDOR_$(mainboard_vendor "${BUILD_NAME}")=y" > "${config_file}"
printf "CONFIG_BOARD_${BUILD_NAME}=y\n" >> ${config_file} echo "CONFIG_BOARD_${BUILD_NAME}=y" >> "${config_file}"
grep "select[\t ]*ARCH" ${ROOT}/src/mainboard/${board_srcdir}/Kconfig | \ grep "select[\t ]*ARCH" "${ROOT}/src/mainboard/${board_srcdir}/Kconfig" | \
sed "s,^.*\(ARCH_.*\)[^A-Z0-9_]*,CONFIG_\1=y," >> ${config_file} sed "s,^.*\(ARCH_.*\)[^A-Z0-9_]*,CONFIG_\1=y," >> "${config_file}"
printf "CONFIG_MAINBOARD_DIR=\"${board_srcdir}\"\n" >> ${config_file} echo "CONFIG_MAINBOARD_DIR=\"${board_srcdir}\"" >> "${config_file}"
update_config "$BUILD_NAME" "$build_dir" "$config_file" update_config "$BUILD_NAME" "$build_dir" "$config_file"
ret=$? ret=$?
if [ $ret -eq 0 ]; then if [ $ret -eq 0 ]; then
if [ "$quiet" == "false" ]; then printf " $BUILD_NAME config created.\n"; fi if [ "$quiet" == "false" ]; then echo " $BUILD_NAME config created."; fi
return 0 return 0
else else
# Does this ever happen? # Does this ever happen?
if [ "$quiet" == "false" ]; then printf "$BUILD_NAME config creation FAILED!\nLog excerpt:\n"; fi if [ "$quiet" == "false" ]; then printf "%s config creation FAILED!\nLog excerpt:\n" "$BUILD_NAME"; fi
tail -n $CONTEXT $build_dir/config.log 2> /dev/null || tail -$CONTEXT $build_dir/config.log tail -n $CONTEXT "$build_dir/config.log" 2> /dev/null || tail -$CONTEXT "$build_dir/config.log"
return 1 return 1
fi fi
} }
@ -212,6 +215,7 @@ function update_config
local build_dir=$2 local build_dir=$2
local config_file=$3 local config_file=$3
local PAYLOAD
local defconfig_file local defconfig_file
defconfig_file=${build_dir}/config.$(echo "${BUILD_NAME}" | tr '[:upper:]' '[:lower:]').default defconfig_file=${build_dir}/config.$(echo "${BUILD_NAME}" | tr '[:upper:]' '[:lower:]').default
@ -222,14 +226,15 @@ function update_config
# the script returns an absolute path to the payload binary. # the script returns an absolute path to the payload binary.
if [ -f "$payloads/payload.sh" ]; then if [ -f "$payloads/payload.sh" ]; then
local PAYLOAD=$(sh "$payloads/payload.sh" "$BUILD_NAME") PAYLOAD=$(sh "$payloads/payload.sh" "$BUILD_NAME")
if [ $? -gt 0 ]; then local PAYLOAD_OK=$?
if [ $PAYLOAD_OK -gt 0 ]; then
echo "problem with payload" echo "problem with payload"
exit 1 exit 1
fi fi
if [ "$quiet" == "false" ]; then printf "Using payload %s\n" "$PAYLOAD"; fi if [ "$quiet" == "false" ]; then printf "Using payload %s\n" "$PAYLOAD"; fi
elif [ "$payloads" = "none" ]; then elif [ "$payloads" = "none" ]; then
local PAYLOAD=none PAYLOAD=none
fi fi
if [ "$PAYLOAD" = "none" ]; then if [ "$PAYLOAD" = "none" ]; then
@ -258,8 +263,10 @@ function update_config
echo "$configoptions" >> "${config_file}" echo "$configoptions" >> "${config_file}"
# shellcheck disable=SC2086 # shellcheck disable=SC2086
$MAKE olddefconfig $silent "DOTCONFIG=${config_file}" "obj=${build_dir}" "objutil=$TARGET/sharedutils" &> "${build_dir}/config.log" $MAKE olddefconfig $silent "DOTCONFIG=${config_file}" "obj=${build_dir}" "objutil=$TARGET/sharedutils" &> "${build_dir}/config.log" ; \
if [ $? -eq 0 ]; then CONFIG_OK=$?
if [ $CONFIG_OK -eq 0 ]; then
# shellcheck disable=SC2086
$MAKE savedefconfig $silent DEFCONFIG="${defconfig_file}" DOTCONFIG="${config_file}" obj="${build_dir}" objutil="$TARGET/sharedutils" &> "${build_dir}/config.log" $MAKE savedefconfig $silent DEFCONFIG="${defconfig_file}" DOTCONFIG="${config_file}" obj="${build_dir}" objutil="$TARGET/sharedutils" &> "${build_dir}/config.log"
return $? return $?
else else
@ -267,6 +274,7 @@ function update_config
fi fi
} }
# shellcheck disable=SC2129
function create_buildenv function create_buildenv
{ {
local BUILD_NAME=$1 local BUILD_NAME=$1
@ -280,22 +288,22 @@ function create_buildenv
cp "$config_file" "$new_config_file" cp "$config_file" "$new_config_file"
update_config "$BUILD_NAME" "$build_dir" "$new_config_file" update_config "$BUILD_NAME" "$build_dir" "$new_config_file"
fi fi
ret=$? local ret=$?
# Allow simple "make" in the target directory # Allow simple "make" in the target directory
local MAKEFILE=$TARGET/${BUILD_NAME}/Makefile local MAKEFILE=$TARGET/${BUILD_NAME}/Makefile
echo "# autogenerated" > $MAKEFILE echo "# autogenerated" > "$MAKEFILE"
echo "TOP=$ROOT" >> $MAKEFILE echo "TOP=$ROOT" >> "$MAKEFILE"
echo "BUILD=$TARGET" >> $MAKEFILE echo "BUILD=$TARGET" >> "$MAKEFILE"
echo "OBJ=\$(BUILD)/${MAINBOARD}" >> $MAKEFILE echo "OBJ=\$(BUILD)/${MAINBOARD}" >> "$MAKEFILE"
echo "OBJUTIL=\$(BUILD)/sharedutils" >> $MAKEFILE echo "OBJUTIL=\$(BUILD)/sharedutils" >> "$MAKEFILE"
echo "all:" >> $MAKEFILE echo "all:" >> "$MAKEFILE"
echo " @cp -a config.h config.h.bak" >> $MAKEFILE echo " @cp -a config.h config.h.bak" >> "$MAKEFILE"
echo " @cd \$(TOP); \$(MAKE) oldconfig DOTCONFIG=\$(OBJ)/config.build objutil=\$(OBJUTIL) obj=\$(OBJ)" >> $MAKEFILE echo " @cd \$(TOP); \$(MAKE) oldconfig DOTCONFIG=\$(OBJ)/config.build objutil=\$(OBJUTIL) obj=\$(OBJ)" >> "$MAKEFILE"
echo " @tail -n+6 config.h > config.new; tail -n+6 config.h.bak > config.old" >> $MAKEFILE echo " @tail -n+6 config.h > config.new; tail -n+6 config.h.bak > config.old" >> "$MAKEFILE"
echo " @cmp -s config.new config.old && cp -a config.h.bak config.h || echo \"Config file changed\"" >> $MAKEFILE echo " @cmp -s config.new config.old && cp -a config.h.bak config.h || echo \"Config file changed\"" >> "$MAKEFILE"
echo " @rm config.h.bak config.new config.old" >> $MAKEFILE echo " @rm config.h.bak config.new config.old" >> "$MAKEFILE"
echo " @cd \$(TOP); \$(MAKE) DOTCONFIG=\$(OBJ)/config.build objutil=\$(OBJUTIL) obj=\$(OBJ)" >> $MAKEFILE echo " @cd \$(TOP); \$(MAKE) DOTCONFIG=\$(OBJ)/config.build objutil=\$(OBJUTIL) obj=\$(OBJ)" >> "$MAKEFILE"
return $ret return $ret
} }
@ -322,41 +330,41 @@ function compile_target
{ {
local BUILD_NAME=$1 local BUILD_NAME=$1
if [ "$quiet" == "false" ]; then printf " Compiling $MAINBOARD image$cpuconfig...\n"; fi if [ "$quiet" == "false" ]; then echo " Compiling $MAINBOARD image$cpuconfig..."; fi
CURR=$( pwd ) CURR=$( pwd )
#stime=`perl -e 'print time();' 2>/dev/null || date +%s` #stime=`perl -e 'print time();' 2>/dev/null || date +%s`
eval $BUILDPREFIX $MAKE $silent DOTCONFIG=${build_dir}/config.build obj=${build_dir} objutil=$TARGET/sharedutils \ # shellcheck disable=SC2086
&> ${build_dir}/make.log eval $BUILDPREFIX $MAKE $silent DOTCONFIG="${build_dir}/config.build" obj="${build_dir}" objutil="$TARGET/sharedutils" \
ret=$? &> "${build_dir}/make.log" ; \
cp .xcompile ${build_dir}/xcompile.build MAKE_FAILED=$?
cd ${build_dir} cp .xcompile "${build_dir}/xcompile.build"
cd "${build_dir}" || return $?
etime=`perl -e 'print time();' 2>/dev/null || date +%s` etime=$(perl -e 'print time();' 2>/dev/null || date +%s)
duration=$(( $etime - $stime )) duration=$(( etime - stime ))
junit " <testcase classname='board${testclass/#/.}' name='$BUILD_NAME' time='$duration' >" junit " <testcase classname='board${testclass/#/.}' name='$BUILD_NAME' time='$duration' >"
if [ $ret -eq 0 ]; then if [ $MAKE_FAILED -eq 0 ]; then
junit "<system-out>" junit "<system-out>"
junitfile make.log junitfile make.log
junit "</system-out>" junit "</system-out>"
printf "ok\n" > compile.status printf "ok\n" > compile.status
printf "$BUILD_NAME built successfully. (took ${duration}s)\n" printf "%s built successfully. (took %ss)\n" "$BUILD_NAME" "${duration}"
else else
ret=1
junit "<failure type='BuildFailed'>" junit "<failure type='BuildFailed'>"
junitfile make.log junitfile make.log
junit "</failure>" junit "</failure>"
printf "failed\n" > compile.status printf "failed\n" > compile.status
printf "$BUILD_NAME build FAILED after ${duration}s!\nLog excerpt:\n" printf "%s build FAILED after %ss!\nLog excerpt:\n" "$BUILD_NAME" "${duration}"
tail -n $CONTEXT make.log 2> /dev/null || tail -$CONTEXT make.log tail -n $CONTEXT make.log 2> /dev/null || tail -$CONTEXT make.log
failed=1 failed=1
fi fi
cd $CURR cd "$CURR" || return $?
if [ $clean_work = "true" ]; then if [ "$clean_work" = "true" ]; then
rm -rf ${build_dir} rm -rf "${build_dir}"
fi fi
return $ret return $MAKE_FAILED
} }
function build_config function build_config
@ -365,11 +373,13 @@ function build_config
local build_dir=$2 local build_dir=$2
local BUILD_NAME=$3 local BUILD_NAME=$3
local config_file=$4 local config_file=$4
local board_srcdir
local ret
local board_srcdir=$(mainboard_directory "${MAINBOARD}") board_srcdir=$(mainboard_directory "${MAINBOARD}")
if [ "$(cat "${build_dir}/compile.status" 2>/dev/null)" = "ok" -a \ if [ "$(cat "${build_dir}/compile.status" 2>/dev/null)" = "ok" ] && \
"$buildall" = "false" ]; then [ "$buildall" = "false" ]; then
echo "Skipping $BUILD_NAME; (already successful)" echo "Skipping $BUILD_NAME; (already successful)"
return return
fi fi
@ -389,7 +399,7 @@ function build_config
if [ "$quiet" == "false" ]; then echo "Building $BUILD_NAME"; fi if [ "$quiet" == "false" ]; then echo "Building $BUILD_NAME"; fi
mkdir -p "$TARGET/${BUILD_NAME}" "$TARGET/abuild" mkdir -p "$TARGET/${BUILD_NAME}" "$TARGET/abuild"
ABSPATH="$(cd "$TARGET/abuild"; pwd)" ABSPATH="$(cd "$TARGET/abuild" && pwd)"
XMLFILE="$ABSPATH/${BUILD_NAME}.xml" XMLFILE="$ABSPATH/${BUILD_NAME}.xml"
rm -f "${XMLFILE}" rm -f "${XMLFILE}"
@ -409,7 +419,7 @@ function build_config
junitfile "$build_dir/config.log" junitfile "$build_dir/config.log"
junit "</failure>" junit "</failure>"
printf "failed\n" > compile.status printf "failed\n" > compile.status
printf "$BUILD_NAME build configuration FAILED!\nLog excerpt:\n" printf "%s build configuration FAILED!\nLog excerpt:\n" "$BUILD_NAME"
tail -n $CONTEXT "$build_dir/config.log" 2> /dev/null || tail -$CONTEXT "$build_dir/config.log" tail -n $CONTEXT "$build_dir/config.log" 2> /dev/null || tail -$CONTEXT "$build_dir/config.log"
junit "</testcase>" junit "</testcase>"
@ -417,25 +427,26 @@ function build_config
fi fi
required_arches=`egrep "^CONFIG_ARCH_(BOOTBLOCK|R.MSTAGE|VERSTAGE)" $TARGET/${BUILD_NAME}/config.build | \ required_arches=$(egrep "^CONFIG_ARCH_(BOOTBLOCK|R.MSTAGE|VERSTAGE)" "$TARGET/${BUILD_NAME}/config.build" | \
sed "s,^CONFIG_ARCH_[^_]*_\([^=]*\)=.*$,\1," |sort -u |tr 'A-Z\n\r' 'a-z '` sed "s,^CONFIG_ARCH_[^_]*_\([^=]*\)=.*$,\1," |sort -u |tr 'A-Z\n\r' 'a-z ')
missing_arches=`printf 'include .xcompile\nall: ; @echo $(foreach arch,'"$required_arches"',$(if $(filter $(arch),$(SUBARCH_SUPPORTED)),,$(arch)))' | make --no-print-directory -f -` # shellcheck disable=SC2016,SC2059
missing_arches=$(printf 'include .xcompile\nall: ; @echo $(foreach arch,'"$required_arches"',$(if $(filter $(arch),$(SUBARCH_SUPPORTED)),,$(arch)))' | make --no-print-directory -f -)
if [ -n "$missing_arches" ]; then if [ -n "$missing_arches" ]; then
printf "skipping $BUILD_NAME because we're missing compilers for ($missing_arches)\n" printf "skipping %s because we're missing compilers for (%s)\n" "$BUILD_NAME" "$missing_arches"
return return
fi fi
if [ $? -eq 0 -a $configureonly -eq 0 ]; then if [ $BUILDENV_CREATED -eq 0 ] && [ $configureonly -eq 0 ]; then
BUILDPREFIX= BUILDPREFIX=
if [ "$scanbuild" = "true" ]; then if [ "$scanbuild" = "true" ]; then
scanbuild_out=$TARGET/${BUILD_NAME}-scanbuild scanbuild_out=$TARGET/${BUILD_NAME}-scanbuild
rm -rf ${scanbuild_out} rm -rf "${scanbuild_out}"
BUILDPREFIX="scan-build -o ${scanbuild_out}tmp" BUILDPREFIX="scan-build -o ${scanbuild_out}tmp"
fi fi
compile_target ${BUILD_NAME} compile_target "${BUILD_NAME}"
if [ "$scanbuild" = "true" ]; then if [ "$scanbuild" = "true" ]; then
mv ${scanbuild_out}tmp/* ${scanbuild_out} mv "${scanbuild_out}"tmp/* "${scanbuild_out}"
rmdir ${scanbuild_out}tmp rmdir "${scanbuild_out}tmp"
fi fi
fi fi
@ -446,11 +457,12 @@ function build_config
function build_target function build_target
{ {
local MAINBOARD=$1 local MAINBOARD=$1
local MAINBOARD_LC=$(echo "$MAINBOARD" | tr '[:upper:]' '[:lower:]') local MAINBOARD_LC
MAINBOARD_LC=$(echo "$MAINBOARD" | tr '[:upper:]' '[:lower:]')
# look for config files in the config directory that match the boardname # look for config files in the config directory that match the boardname
if [ -n "$( find "$configdir" -maxdepth 1 -name "config.${MAINBOARD_LC}*" -print -quit )" ]; then if [ -n "$( find "$configdir" -maxdepth 1 -name "config.${MAINBOARD_LC}*" -print -quit )" ]; then
for config in "$configdir"/config."${MAINBOARD_LC}"*; do for config in "$configdir/config.${MAINBOARD_LC}"*; do
BUILD_NAME="${config##*/}" BUILD_NAME="${config##*/}"
BUILD_NAME="${BUILD_NAME##config.}" BUILD_NAME="${BUILD_NAME##config.}"
BUILD_NAME=$(echo "${BUILD_NAME}" | tr '[:lower:]' '[:upper:]') BUILD_NAME=$(echo "${BUILD_NAME}" | tr '[:lower:]' '[:upper:]')
@ -485,7 +497,7 @@ function remove_target
fi fi
echo "Removing build dir for $BUILD_NAME..." echo "Removing build dir for $BUILD_NAME..."
rm -rf "$TARGET/${BUILD_NAME}" rm -rf "${TARGET:?}/${BUILD_NAME}"
return return
} }
@ -555,8 +567,8 @@ buildall=false
verbose=false verbose=false
test -f util/sconfig/sconfig.l && ROOT=$( pwd ) test -f util/sconfig/sconfig.l && ROOT=$( pwd )
test -f ../util/sconfig/sconfig.l && ROOT=$( cd ..; pwd ) test -f ../util/sconfig/sconfig.l && ROOT=$( cd .. && pwd )
test "$ROOT" = "" && ROOT=$( cd ../..; pwd ) test "$ROOT" = "" && ROOT=$( cd ../.. && pwd )
# Look if we have getopt. If not, build it. # Look if we have getopt. If not, build it.
export PATH=$PATH:util/abuild export PATH=$PATH:util/abuild
@ -566,18 +578,22 @@ getopt - > /dev/null 2>/dev/null || gcc -o util/abuild/getopt util/abuild/getopt
cmdline="$* -c 1" cmdline="$* -c 1"
# parse parameters.. try to find out whether we're running GNU getopt # parse parameters.. try to find out whether we're running GNU getopt
getoptbrand="`getopt -V`" getoptbrand="$(getopt -V)"
# shellcheck disable=SC2086
if [ "${getoptbrand:0:6}" == "getopt" ]; then if [ "${getoptbrand:0:6}" == "getopt" ]; then
# Detected GNU getopt that supports long options. # Detected GNU getopt that supports long options.
args=`getopt -l version,verbose,quiet,help,all,target:,payloads:,cpus:,silent,junit,config,loglevel:,remove,prefix:,update,scan-build,ccache,blobs,clang,clean,outdir:,chromeos,xmlfile:,kconfig:,dir: -o Vvqhat:p:c:sJCl:rP:uyBLzo:xX:K:d: -- "$@"` || exit 1 args=$(getopt -l version,verbose,quiet,help,all,target:,payloads:,cpus:,silent,junit,config,loglevel:,remove,prefix:,update,scan-build,ccache,blobs,clang,clean,outdir:,chromeos,xmlfile:,kconfig:,dir: -o Vvqhat:p:c:sJCl:rP:uyBLzo:xX:K:d: -- "$@") || exit 1
eval set -- $args eval set -- $args
retval=$?
else else
# Detected non-GNU getopt # Detected non-GNU getopt
args=`getopt Vvqhat:p:c:sJCl:rP:uyBLzo:xX:K:d: $*` args=$(getopt Vvqhat:p:c:sJCl:rP:uyBLzo:xX:K:d: "$@")
set -- $args set -- $args
retval=$?
fi fi
if [ $? != 0 ]; then if [ $retval != 0 ]; then
myhelp myhelp
exit 1 exit 1
fi fi
@ -590,7 +606,7 @@ configoptions=""
unset testclass unset testclass
while true ; do while true ; do
case "$1" in case "$1" in
-J|--junit) shift; mode=junit; rm -f $XMLFILE ;; -J|--junit) shift; mode=junit; rm -f "$XMLFILE" ;;
-t|--target) shift; target="$1"; shift;; -t|--target) shift; target="$1"; shift;;
-a|--all) shift; buildall=true;; -a|--all) shift; buildall=true;;
-d|--dir) shift; configdir="$1"; shift;; -d|--dir) shift; configdir="$1"; shift;;
@ -605,7 +621,7 @@ while true ; do
cpus=$1 cpus=$1
test "$MAKEFLAGS" == "-j max" && export MAKEFLAGS="-j" && cpuconfig=" in parallel" test "$MAKEFLAGS" == "-j max" && export MAKEFLAGS="-j" && cpuconfig=" in parallel"
test "$1" == "1" && cpuconfig=" on 1 cpu" test "$1" == "1" && cpuconfig=" on 1 cpu"
expr "$1" : '-\?[0-9]\+$' > /dev/null && test 0$1 -gt 1 && cpuconfig=" on $1 cpus in parallel" expr "$1" : '-\?[0-9]\+$' > /dev/null && test "0$1" -gt 1 && cpuconfig=" on $1 cpus in parallel"
shift;; shift;;
-s|--silent) shift; silent="-s";; -s|--silent) shift; silent="-s";;
--scan-build) shift --scan-build) shift
@ -653,7 +669,7 @@ while true ; do
;; ;;
-X|--xmlfile) shift; XMLFILE=$1; REAL_XMLFILE=$1; shift;; -X|--xmlfile) shift; XMLFILE=$1; REAL_XMLFILE=$1; shift;;
-K|--kconfig) shift -K|--kconfig) shift
testclass=="$(basename $1 | tr '.' '_' )" testclass="$(basename "$1" | tr '.' '_' )"
customizing="${customizing}, $1 config" customizing="${customizing}, $1 config"
configoptions="$(cat "$1")${configoptions}\n" configoptions="$(cat "$1")${configoptions}\n"
shift;; shift;;
@ -663,12 +679,12 @@ while true ; do
esac esac
done done
if [ -z "$TARGET" -o "$TARGET" = "/" ]; then if [ -z "$TARGET" ] || [ "$TARGET" = "/" ]; then
echo "Please specify a valid, non-root build directory." echo "Please specify a valid, non-root build directory."
exit 1 exit 1
fi fi
customizing=`echo $customizing |cut -c3-` customizing=$(echo "$customizing" | cut -c3-)
if [ "$customizing" = "" ]; then if [ "$customizing" = "" ]; then
customizing="default configuration" customizing="default configuration"
fi fi
@ -692,44 +708,48 @@ build_targets()
{ {
local targets=${*-$(get_mainboards)} local targets=${*-$(get_mainboards)}
for MAINBOARD in $targets; do for MAINBOARD in $targets; do
build_target ${MAINBOARD} build_target "${MAINBOARD}"
done done
} }
else else
build_targets() build_targets()
{ {
local ABSPATH
local stime
local etime
local targets=${*-$(get_mainboards)} local targets=${*-$(get_mainboards)}
# seed shared utils # seed shared utils
TMPCFG=`mktemp` TMPCFG=$(mktemp)
printf "$configoptions" > $TMPCFG printf "%s" "$configoptions" > "$TMPCFG"
$MAKE -j $cpus DOTCONFIG=$TMPCFG obj=$TARGET/temp objutil=$TARGET/sharedutils allnoconfig $MAKE -j "$cpus" DOTCONFIG="$TMPCFG" obj="$TARGET/temp" objutil="$TARGET/sharedutils" allnoconfig
printf "$configoptions" >> $TMPCFG printf "%s" "$configoptions" >> "$TMPCFG"
yes "" 2>/dev/null | $MAKE -j $cpus DOTCONFIG=$TMPCFG obj=$TARGET/temp objutil=$TARGET/sharedutils oldconfig 2>/dev/null |head > /dev/null yes "" 2>/dev/null | $MAKE -j "$cpus" DOTCONFIG="$TMPCFG" obj="$TARGET/temp" objutil="$TARGET/sharedutils" oldconfig 2>/dev/null |head > /dev/null
BUILDPREFIX= BUILDPREFIX=
if [ "$scanbuild" = "true" ]; then if [ "$scanbuild" = "true" ]; then
scanbuild_out=$TARGET/sharedutils-scanbuild scanbuild_out=$TARGET/sharedutils-scanbuild
rm -rf ${scanbuild_out} rm -rf "${scanbuild_out}"
BUILDPREFIX="scan-build -o ${scanbuild_out}tmp" BUILDPREFIX="scan-build -o ${scanbuild_out}tmp"
fi fi
mkdir -p $TARGET/abuild mkdir -p "$TARGET/abuild"
local ABSPATH=`cd $TARGET/abuild; pwd` ABSPATH="$(cd "$TARGET/abuild" && pwd)"
local XMLFILE=$ABSPATH/__util.xml local XMLFILE="$ABSPATH/__util.xml"
rm -f ${XMLFILE} rm -f "${XMLFILE}"
local stime=`perl -e 'print time();' 2>/dev/null || date +%s` stime=$(perl -e 'print time();' 2>/dev/null || date +%s)
$BUILDPREFIX $MAKE -j $cpus DOTCONFIG=$TMPCFG obj=$TARGET/temp objutil=$TARGET/sharedutils tools > $TARGET/sharedutils/make.log 2>&1 $BUILDPREFIX $MAKE -j "$cpus" DOTCONFIG="$TMPCFG" obj="$TARGET/temp" objutil="$TARGET/sharedutils" tools > "$TARGET/sharedutils/make.log" 2>&1
local ret=$? local ret=$?
local etime=`perl -e 'print time();' 2>/dev/null || date +%s` etime=$(perl -e 'print time();' 2>/dev/null || date +%s)
local duration=$(( $etime - $stime )) local duration=$(( etime - stime ))
junit " <testcase classname='util' name='all' time='$duration' >" junit " <testcase classname='util' name='all' time='$duration' >"
if [ $ret -eq 0 ]; then if [ $ret -eq 0 ]; then
junit "<system-out>" junit "<system-out>"
junitfile $TARGET/sharedutils/make.log junitfile "$TARGET/sharedutils/make.log"
junit "</system-out>" junit "</system-out>"
junit "</testcase>" junit "</testcase>"
else else
junit "<failure type='BuildFailed'>" junit "<failure type='BuildFailed'>"
junitfile $TARGET/sharedutils/make.log junitfile "$TARGET/sharedutils/make.log"
junit "</failure>" junit "</failure>"
junit "</testcase>" junit "</testcase>"
return return
@ -739,11 +759,12 @@ build_targets()
fi fi
if [ "$scanbuild" = "true" ]; then if [ "$scanbuild" = "true" ]; then
mv ${scanbuild_out}tmp/* ${scanbuild_out} mv "${scanbuild_out}tmp/"* "${scanbuild_out}"
rmdir ${scanbuild_out}tmp rmdir "${scanbuild_out}tmp"
fi fi
rm -rf $TARGET/temp $TMPCFG rm -rf "$TARGET/temp" "$TMPCFG"
echo $targets | xargs -P ${cpus:-0} -n 1 $0 $cmdline -t # shellcheck disable=SC2086
echo $targets | xargs -P ${cpus:-0} -n 1 "$0" $cmdline -t
} }
fi fi
@ -756,33 +777,33 @@ junit '<testsuite>'
if [ "$target" != "" ]; then if [ "$target" != "" ]; then
# build a single board # build a single board
MAINBOARD=$(normalize_target ${target}) MAINBOARD=$(normalize_target "${target}")
if [ -z "${MAINBOARD}" ]; then if [ -z "${MAINBOARD}" ]; then
printf "No such target: $target\n" printf "No such target: %s\n" "$target"
exit 1 exit 1
fi fi
build_srcdir=$(mainboard_directory ${MAINBOARD}) build_srcdir="$(mainboard_directory "${MAINBOARD}")"
if [ "$(echo ${MAINBOARD} | wc -w)" -gt 1 ]; then if [ "$(echo "${MAINBOARD}" | wc -w)" -gt 1 ]; then
build_targets ${MAINBOARD} build_targets "${MAINBOARD}"
elif [ ! -r $ROOT/src/mainboard/${build_srcdir} ]; then elif [ ! -r "$ROOT/src/mainboard/${build_srcdir}" ]; then
printf "No such target: ${MAINBOARD}\n" echo "No such target: ${MAINBOARD}"
exit 1 exit 1
else else
build_target ${MAINBOARD} build_target "${MAINBOARD}"
test "$mode" != "text" && \ test "$mode" != "text" && \
test -f $TARGET/abuild/${MAINBOARD}.xml && \ test -f "$TARGET/abuild/${MAINBOARD}.xml" && \
cat $TARGET/abuild/${MAINBOARD}.xml >> $REAL_XMLFILE cat "$TARGET/abuild/${MAINBOARD}.xml" >> "$REAL_XMLFILE"
XMLFILE=$REAL_XMLFILE XMLFILE=$REAL_XMLFILE
fi fi
else else
build_targets build_targets
rm -f $REAL_XMLFILE rm -f "$REAL_XMLFILE"
XMLFILE=$REAL_XMLFILE XMLFILE="$REAL_XMLFILE"
junit '<?xml version="1.0" encoding="utf-8"?>' junit '<?xml version="1.0" encoding="utf-8"?>'
junit '<testsuite>' junit '<testsuite>'
if [ "$mode" != "text" ]; then if [ "$mode" != "text" ]; then
for xmlfile in $TARGET/abuild/*_*.xml; do for xmlfile in $TARGET/abuild/*_*.xml; do
cat $xmlfile >> $REAL_XMLFILE cat "$xmlfile" >> "$REAL_XMLFILE"
done done
fi fi
XMLFILE=$REAL_XMLFILE XMLFILE=$REAL_XMLFILE