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:
parent
861a4b88fa
commit
02c93b9b1f
|
@ -32,7 +32,7 @@ export KCONFIG_OVERWRITECONFIG=1
|
|||
PAYLOAD=/dev/null
|
||||
|
||||
# path to coreboot XGCC
|
||||
XGCCPATH="`pwd`/util/crossgcc/xgcc/bin/"
|
||||
XGCCPATH="${TOP}/util/crossgcc/xgcc/bin/"
|
||||
|
||||
# Add XGCC to the path.
|
||||
if [ -d "$XGCCPATH" ] && [[ ":$PATH:" != *":$XGCCPATH:"* ]]; then
|
||||
|
@ -77,30 +77,25 @@ quiet=false
|
|||
# clang mode enabled by -sb option.
|
||||
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
|
||||
|
||||
function interrupt
|
||||
{
|
||||
printf "\n$0: execution interrupted manually.\n"
|
||||
printf "\n%s: execution interrupted manually.\n" "$0"
|
||||
if [ "$mode" == "junit" ]; then
|
||||
printf "$0: deleting incomplete xml output file.\n"
|
||||
printf "%s: deleting incomplete xml output file.\n" "$0"
|
||||
fi
|
||||
exit 1
|
||||
}
|
||||
|
||||
function debug
|
||||
{
|
||||
test "$verbose" == "true" && printf "$*\n"
|
||||
test "$verbose" == "true" && echo "$*"
|
||||
}
|
||||
|
||||
function junit
|
||||
{
|
||||
test "$mode" == "junit" && printf "$*\n" >> $XMLFILE
|
||||
test "$mode" == "junit" && echo "$*" >> "$XMLFILE"
|
||||
return 0
|
||||
}
|
||||
|
||||
|
@ -108,9 +103,9 @@ function junitfile
|
|||
{
|
||||
test "$mode" == "junit" && {
|
||||
printf '<![CDATA[\n'
|
||||
cat $1
|
||||
cat "$1"
|
||||
printf ']]>\n'
|
||||
} >> $XMLFILE
|
||||
} >> "$XMLFILE"
|
||||
}
|
||||
|
||||
# Return mainboard descriptors.
|
||||
|
@ -120,6 +115,7 @@ function junitfile
|
|||
function get_mainboards
|
||||
{
|
||||
local search_space=${1-*/*}
|
||||
# shellcheck disable=SC2086
|
||||
grep -h "^[[:space:]]*config\>[[:space:]]*\<BOARD_" \
|
||||
${ROOT}/src/mainboard/${search_space}/Kconfig.name 2>/dev/null | \
|
||||
sed "s,^.*\<BOARD_\([A-Z0-9_]*\)\>.*$,\1,"
|
||||
|
@ -130,6 +126,7 @@ function mainboard_directory
|
|||
{
|
||||
local MAINBOARD=$1
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
grep -l "^[[:space:]]*config\>[[:space:]]*\<BOARD_${MAINBOARD}\>" \
|
||||
${ROOT}/src/mainboard/*/*/Kconfig.name | \
|
||||
sed "s:^$ROOT/src/mainboard/\(.*\)/Kconfig.name$:\1:"
|
||||
|
@ -139,15 +136,17 @@ function mainboard_directory
|
|||
function mainboard_vendor
|
||||
{
|
||||
local MAINBOARD=$1
|
||||
local kconfig_file
|
||||
|
||||
local kconfig_file=$( \
|
||||
# shellcheck disable=SC2086
|
||||
kconfig_file=$( \
|
||||
grep -l "^[[:space:]]*config\>[[:space:]]*\<BOARD_${MAINBOARD}\>" \
|
||||
${ROOT}/src/mainboard/*/*/Kconfig.name | \
|
||||
sed "s:^\(${ROOT}/src/mainboard/.*\)/.*/\(Kconfig.name\)$:\1/\2:" )
|
||||
if [ ! -f "$kconfig_file" ]; then
|
||||
exit 1
|
||||
fi
|
||||
grep "^[[:space:]]*config\>[[:space:]]*\<VENDOR_" $kconfig_file | \
|
||||
grep "^[[:space:]]*config\>[[:space:]]*\<VENDOR_" "$kconfig_file" | \
|
||||
sed "s,^.*\<VENDOR_\([A-Z0-9_]*\)\>.*$,\1,"
|
||||
}
|
||||
|
||||
|
@ -157,16 +156,18 @@ function mainboard_vendor
|
|||
# If a directory contains multiple boards, returns them all.
|
||||
function normalize_target
|
||||
{
|
||||
local targets=$(get_mainboards $1)
|
||||
local targets
|
||||
|
||||
targets=$(get_mainboards "$1")
|
||||
if [ -n "$targets" ]; then
|
||||
echo $targets
|
||||
echo "$targets"
|
||||
return
|
||||
fi
|
||||
|
||||
local targets=$(echo $1 | tr ',' ' ')
|
||||
targets=$(echo "$1" | tr ',' ' ')
|
||||
for i in $targets; do
|
||||
if [ -n "$(mainboard_directory $i)" ]; then
|
||||
echo $i
|
||||
if [ -n "$(mainboard_directory "$i")" ]; then
|
||||
echo "$i"
|
||||
else
|
||||
echo "$i is not a valid target" >&2
|
||||
exit 1
|
||||
|
@ -174,34 +175,36 @@ function normalize_target
|
|||
done
|
||||
}
|
||||
|
||||
# shellcheck disable=SC2129
|
||||
function create_config
|
||||
{
|
||||
local BUILD_NAME=$1
|
||||
local build_dir=$2
|
||||
local board_srcdir
|
||||
|
||||
local config_file=${build_dir}/config.build
|
||||
local board_srcdir=$(mainboard_directory ${BUILD_NAME})
|
||||
local config_file="${build_dir}/config.build"
|
||||
board_srcdir="$(mainboard_directory "${BUILD_NAME}")"
|
||||
|
||||
mkdir -p ${build_dir}
|
||||
mkdir -p $TARGET/sharedutils
|
||||
mkdir -p "${build_dir}"
|
||||
mkdir -p "$TARGET/sharedutils"
|
||||
|
||||
if [ "$quiet" == "false" ]; then printf " Creating config file for $BUILD_NAME... \n"; fi
|
||||
printf "CONFIG_VENDOR_$(mainboard_vendor ${BUILD_NAME})=y\n" > ${config_file}
|
||||
printf "CONFIG_BOARD_${BUILD_NAME}=y\n" >> ${config_file}
|
||||
grep "select[\t ]*ARCH" ${ROOT}/src/mainboard/${board_srcdir}/Kconfig | \
|
||||
sed "s,^.*\(ARCH_.*\)[^A-Z0-9_]*,CONFIG_\1=y," >> ${config_file}
|
||||
printf "CONFIG_MAINBOARD_DIR=\"${board_srcdir}\"\n" >> ${config_file}
|
||||
if [ "$quiet" == "false" ]; then echo " Creating config file for $BUILD_NAME..."; fi
|
||||
echo "CONFIG_VENDOR_$(mainboard_vendor "${BUILD_NAME}")=y" > "${config_file}"
|
||||
echo "CONFIG_BOARD_${BUILD_NAME}=y" >> "${config_file}"
|
||||
grep "select[\t ]*ARCH" "${ROOT}/src/mainboard/${board_srcdir}/Kconfig" | \
|
||||
sed "s,^.*\(ARCH_.*\)[^A-Z0-9_]*,CONFIG_\1=y," >> "${config_file}"
|
||||
echo "CONFIG_MAINBOARD_DIR=\"${board_srcdir}\"" >> "${config_file}"
|
||||
|
||||
update_config "$BUILD_NAME" "$build_dir" "$config_file"
|
||||
|
||||
ret=$?
|
||||
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
|
||||
else
|
||||
# Does this ever happen?
|
||||
if [ "$quiet" == "false" ]; then printf "$BUILD_NAME config creation FAILED!\nLog excerpt:\n"; fi
|
||||
tail -n $CONTEXT $build_dir/config.log 2> /dev/null || tail -$CONTEXT $build_dir/config.log
|
||||
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"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
@ -212,6 +215,7 @@ function update_config
|
|||
local build_dir=$2
|
||||
local config_file=$3
|
||||
|
||||
local PAYLOAD
|
||||
local defconfig_file
|
||||
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.
|
||||
|
||||
if [ -f "$payloads/payload.sh" ]; then
|
||||
local PAYLOAD=$(sh "$payloads/payload.sh" "$BUILD_NAME")
|
||||
if [ $? -gt 0 ]; then
|
||||
PAYLOAD=$(sh "$payloads/payload.sh" "$BUILD_NAME")
|
||||
local PAYLOAD_OK=$?
|
||||
if [ $PAYLOAD_OK -gt 0 ]; then
|
||||
echo "problem with payload"
|
||||
exit 1
|
||||
fi
|
||||
if [ "$quiet" == "false" ]; then printf "Using payload %s\n" "$PAYLOAD"; fi
|
||||
elif [ "$payloads" = "none" ]; then
|
||||
local PAYLOAD=none
|
||||
PAYLOAD=none
|
||||
fi
|
||||
|
||||
if [ "$PAYLOAD" = "none" ]; then
|
||||
|
@ -257,9 +262,11 @@ function update_config
|
|||
if [ "$quiet" == "false" ]; then echo " $MAINBOARD ($customizing)"; fi
|
||||
echo "$configoptions" >> "${config_file}"
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
$MAKE olddefconfig $silent "DOTCONFIG=${config_file}" "obj=${build_dir}" "objutil=$TARGET/sharedutils" &> "${build_dir}/config.log"
|
||||
if [ $? -eq 0 ]; then
|
||||
# shellcheck disable=SC2086
|
||||
$MAKE olddefconfig $silent "DOTCONFIG=${config_file}" "obj=${build_dir}" "objutil=$TARGET/sharedutils" &> "${build_dir}/config.log" ; \
|
||||
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"
|
||||
return $?
|
||||
else
|
||||
|
@ -267,6 +274,7 @@ function update_config
|
|||
fi
|
||||
}
|
||||
|
||||
# shellcheck disable=SC2129
|
||||
function create_buildenv
|
||||
{
|
||||
local BUILD_NAME=$1
|
||||
|
@ -280,22 +288,22 @@ function create_buildenv
|
|||
cp "$config_file" "$new_config_file"
|
||||
update_config "$BUILD_NAME" "$build_dir" "$new_config_file"
|
||||
fi
|
||||
ret=$?
|
||||
local ret=$?
|
||||
|
||||
# Allow simple "make" in the target directory
|
||||
local MAKEFILE=$TARGET/${BUILD_NAME}/Makefile
|
||||
echo "# autogenerated" > $MAKEFILE
|
||||
echo "TOP=$ROOT" >> $MAKEFILE
|
||||
echo "BUILD=$TARGET" >> $MAKEFILE
|
||||
echo "OBJ=\$(BUILD)/${MAINBOARD}" >> $MAKEFILE
|
||||
echo "OBJUTIL=\$(BUILD)/sharedutils" >> $MAKEFILE
|
||||
echo "all:" >> $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 " @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 " @rm config.h.bak config.new config.old" >> $MAKEFILE
|
||||
echo " @cd \$(TOP); \$(MAKE) DOTCONFIG=\$(OBJ)/config.build objutil=\$(OBJUTIL) obj=\$(OBJ)" >> $MAKEFILE
|
||||
echo "# autogenerated" > "$MAKEFILE"
|
||||
echo "TOP=$ROOT" >> "$MAKEFILE"
|
||||
echo "BUILD=$TARGET" >> "$MAKEFILE"
|
||||
echo "OBJ=\$(BUILD)/${MAINBOARD}" >> "$MAKEFILE"
|
||||
echo "OBJUTIL=\$(BUILD)/sharedutils" >> "$MAKEFILE"
|
||||
echo "all:" >> "$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 " @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 " @rm config.h.bak config.new config.old" >> "$MAKEFILE"
|
||||
echo " @cd \$(TOP); \$(MAKE) DOTCONFIG=\$(OBJ)/config.build objutil=\$(OBJUTIL) obj=\$(OBJ)" >> "$MAKEFILE"
|
||||
|
||||
return $ret
|
||||
}
|
||||
|
@ -322,41 +330,41 @@ function compile_target
|
|||
{
|
||||
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 )
|
||||
#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 \
|
||||
&> ${build_dir}/make.log
|
||||
ret=$?
|
||||
cp .xcompile ${build_dir}/xcompile.build
|
||||
cd ${build_dir}
|
||||
# shellcheck disable=SC2086
|
||||
eval $BUILDPREFIX $MAKE $silent DOTCONFIG="${build_dir}/config.build" obj="${build_dir}" objutil="$TARGET/sharedutils" \
|
||||
&> "${build_dir}/make.log" ; \
|
||||
MAKE_FAILED=$?
|
||||
cp .xcompile "${build_dir}/xcompile.build"
|
||||
cd "${build_dir}" || return $?
|
||||
|
||||
etime=`perl -e 'print time();' 2>/dev/null || date +%s`
|
||||
duration=$(( $etime - $stime ))
|
||||
etime=$(perl -e 'print time();' 2>/dev/null || date +%s)
|
||||
duration=$(( etime - stime ))
|
||||
junit " <testcase classname='board${testclass/#/.}' name='$BUILD_NAME' time='$duration' >"
|
||||
|
||||
if [ $ret -eq 0 ]; then
|
||||
if [ $MAKE_FAILED -eq 0 ]; then
|
||||
junit "<system-out>"
|
||||
junitfile make.log
|
||||
junit "</system-out>"
|
||||
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
|
||||
ret=1
|
||||
junit "<failure type='BuildFailed'>"
|
||||
junitfile make.log
|
||||
junit "</failure>"
|
||||
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
|
||||
failed=1
|
||||
fi
|
||||
cd $CURR
|
||||
if [ $clean_work = "true" ]; then
|
||||
rm -rf ${build_dir}
|
||||
cd "$CURR" || return $?
|
||||
if [ "$clean_work" = "true" ]; then
|
||||
rm -rf "${build_dir}"
|
||||
fi
|
||||
return $ret
|
||||
return $MAKE_FAILED
|
||||
}
|
||||
|
||||
function build_config
|
||||
|
@ -365,11 +373,13 @@ function build_config
|
|||
local build_dir=$2
|
||||
local BUILD_NAME=$3
|
||||
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 \
|
||||
"$buildall" = "false" ]; then
|
||||
if [ "$(cat "${build_dir}/compile.status" 2>/dev/null)" = "ok" ] && \
|
||||
[ "$buildall" = "false" ]; then
|
||||
echo "Skipping $BUILD_NAME; (already successful)"
|
||||
return
|
||||
fi
|
||||
|
@ -389,7 +399,7 @@ function build_config
|
|||
|
||||
if [ "$quiet" == "false" ]; then echo "Building $BUILD_NAME"; fi
|
||||
mkdir -p "$TARGET/${BUILD_NAME}" "$TARGET/abuild"
|
||||
ABSPATH="$(cd "$TARGET/abuild"; pwd)"
|
||||
ABSPATH="$(cd "$TARGET/abuild" && pwd)"
|
||||
XMLFILE="$ABSPATH/${BUILD_NAME}.xml"
|
||||
rm -f "${XMLFILE}"
|
||||
|
||||
|
@ -409,7 +419,7 @@ function build_config
|
|||
junitfile "$build_dir/config.log"
|
||||
junit "</failure>"
|
||||
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"
|
||||
|
||||
junit "</testcase>"
|
||||
|
@ -417,25 +427,26 @@ function build_config
|
|||
fi
|
||||
|
||||
|
||||
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 '`
|
||||
missing_arches=`printf 'include .xcompile\nall: ; @echo $(foreach arch,'"$required_arches"',$(if $(filter $(arch),$(SUBARCH_SUPPORTED)),,$(arch)))' | make --no-print-directory -f -`
|
||||
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 ')
|
||||
# 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
|
||||
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
|
||||
fi
|
||||
|
||||
if [ $? -eq 0 -a $configureonly -eq 0 ]; then
|
||||
if [ $BUILDENV_CREATED -eq 0 ] && [ $configureonly -eq 0 ]; then
|
||||
BUILDPREFIX=
|
||||
if [ "$scanbuild" = "true" ]; then
|
||||
scanbuild_out=$TARGET/${BUILD_NAME}-scanbuild
|
||||
rm -rf ${scanbuild_out}
|
||||
rm -rf "${scanbuild_out}"
|
||||
BUILDPREFIX="scan-build -o ${scanbuild_out}tmp"
|
||||
fi
|
||||
compile_target ${BUILD_NAME}
|
||||
compile_target "${BUILD_NAME}"
|
||||
if [ "$scanbuild" = "true" ]; then
|
||||
mv ${scanbuild_out}tmp/* ${scanbuild_out}
|
||||
rmdir ${scanbuild_out}tmp
|
||||
mv "${scanbuild_out}"tmp/* "${scanbuild_out}"
|
||||
rmdir "${scanbuild_out}tmp"
|
||||
fi
|
||||
fi
|
||||
|
||||
|
@ -446,11 +457,12 @@ function build_config
|
|||
function build_target
|
||||
{
|
||||
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
|
||||
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="${BUILD_NAME##config.}"
|
||||
BUILD_NAME=$(echo "${BUILD_NAME}" | tr '[:lower:]' '[:upper:]')
|
||||
|
@ -485,7 +497,7 @@ function remove_target
|
|||
fi
|
||||
|
||||
echo "Removing build dir for $BUILD_NAME..."
|
||||
rm -rf "$TARGET/${BUILD_NAME}"
|
||||
rm -rf "${TARGET:?}/${BUILD_NAME}"
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -555,8 +567,8 @@ buildall=false
|
|||
verbose=false
|
||||
|
||||
test -f util/sconfig/sconfig.l && ROOT=$( pwd )
|
||||
test -f ../util/sconfig/sconfig.l && ROOT=$( cd ..; pwd )
|
||||
test "$ROOT" = "" && ROOT=$( cd ../..; pwd )
|
||||
test -f ../util/sconfig/sconfig.l && ROOT=$( cd .. && pwd )
|
||||
test "$ROOT" = "" && ROOT=$( cd ../.. && pwd )
|
||||
|
||||
# Look if we have getopt. If not, build it.
|
||||
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"
|
||||
|
||||
# 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
|
||||
# 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
|
||||
retval=$?
|
||||
else
|
||||
# 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
|
||||
retval=$?
|
||||
fi
|
||||
|
||||
if [ $? != 0 ]; then
|
||||
if [ $retval != 0 ]; then
|
||||
myhelp
|
||||
exit 1
|
||||
fi
|
||||
|
@ -590,7 +606,7 @@ configoptions=""
|
|||
unset testclass
|
||||
while true ; do
|
||||
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;;
|
||||
-a|--all) shift; buildall=true;;
|
||||
-d|--dir) shift; configdir="$1"; shift;;
|
||||
|
@ -605,7 +621,7 @@ while true ; do
|
|||
cpus=$1
|
||||
test "$MAKEFLAGS" == "-j max" && export MAKEFLAGS="-j" && cpuconfig=" in parallel"
|
||||
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;;
|
||||
-s|--silent) shift; silent="-s";;
|
||||
--scan-build) shift
|
||||
|
@ -653,7 +669,7 @@ while true ; do
|
|||
;;
|
||||
-X|--xmlfile) shift; XMLFILE=$1; REAL_XMLFILE=$1; shift;;
|
||||
-K|--kconfig) shift
|
||||
testclass=="$(basename $1 | tr '.' '_' )"
|
||||
testclass="$(basename "$1" | tr '.' '_' )"
|
||||
customizing="${customizing}, $1 config"
|
||||
configoptions="$(cat "$1")${configoptions}\n"
|
||||
shift;;
|
||||
|
@ -663,12 +679,12 @@ while true ; do
|
|||
esac
|
||||
done
|
||||
|
||||
if [ -z "$TARGET" -o "$TARGET" = "/" ]; then
|
||||
if [ -z "$TARGET" ] || [ "$TARGET" = "/" ]; then
|
||||
echo "Please specify a valid, non-root build directory."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
customizing=`echo $customizing |cut -c3-`
|
||||
customizing=$(echo "$customizing" | cut -c3-)
|
||||
if [ "$customizing" = "" ]; then
|
||||
customizing="default configuration"
|
||||
fi
|
||||
|
@ -692,44 +708,48 @@ build_targets()
|
|||
{
|
||||
local targets=${*-$(get_mainboards)}
|
||||
for MAINBOARD in $targets; do
|
||||
build_target ${MAINBOARD}
|
||||
build_target "${MAINBOARD}"
|
||||
done
|
||||
}
|
||||
else
|
||||
build_targets()
|
||||
{
|
||||
local ABSPATH
|
||||
local stime
|
||||
local etime
|
||||
|
||||
local targets=${*-$(get_mainboards)}
|
||||
# seed shared utils
|
||||
TMPCFG=`mktemp`
|
||||
printf "$configoptions" > $TMPCFG
|
||||
$MAKE -j $cpus DOTCONFIG=$TMPCFG obj=$TARGET/temp objutil=$TARGET/sharedutils allnoconfig
|
||||
printf "$configoptions" >> $TMPCFG
|
||||
yes "" 2>/dev/null | $MAKE -j $cpus DOTCONFIG=$TMPCFG obj=$TARGET/temp objutil=$TARGET/sharedutils oldconfig 2>/dev/null |head > /dev/null
|
||||
TMPCFG=$(mktemp)
|
||||
printf "%s" "$configoptions" > "$TMPCFG"
|
||||
$MAKE -j "$cpus" DOTCONFIG="$TMPCFG" obj="$TARGET/temp" objutil="$TARGET/sharedutils" allnoconfig
|
||||
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
|
||||
BUILDPREFIX=
|
||||
if [ "$scanbuild" = "true" ]; then
|
||||
scanbuild_out=$TARGET/sharedutils-scanbuild
|
||||
rm -rf ${scanbuild_out}
|
||||
rm -rf "${scanbuild_out}"
|
||||
BUILDPREFIX="scan-build -o ${scanbuild_out}tmp"
|
||||
fi
|
||||
mkdir -p $TARGET/abuild
|
||||
local ABSPATH=`cd $TARGET/abuild; pwd`
|
||||
local XMLFILE=$ABSPATH/__util.xml
|
||||
rm -f ${XMLFILE}
|
||||
local 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
|
||||
mkdir -p "$TARGET/abuild"
|
||||
ABSPATH="$(cd "$TARGET/abuild" && pwd)"
|
||||
local XMLFILE="$ABSPATH/__util.xml"
|
||||
rm -f "${XMLFILE}"
|
||||
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
|
||||
local ret=$?
|
||||
local etime=`perl -e 'print time();' 2>/dev/null || date +%s`
|
||||
local duration=$(( $etime - $stime ))
|
||||
etime=$(perl -e 'print time();' 2>/dev/null || date +%s)
|
||||
local duration=$(( etime - stime ))
|
||||
|
||||
junit " <testcase classname='util' name='all' time='$duration' >"
|
||||
if [ $ret -eq 0 ]; then
|
||||
junit "<system-out>"
|
||||
junitfile $TARGET/sharedutils/make.log
|
||||
junitfile "$TARGET/sharedutils/make.log"
|
||||
junit "</system-out>"
|
||||
junit "</testcase>"
|
||||
else
|
||||
junit "<failure type='BuildFailed'>"
|
||||
junitfile $TARGET/sharedutils/make.log
|
||||
junitfile "$TARGET/sharedutils/make.log"
|
||||
junit "</failure>"
|
||||
junit "</testcase>"
|
||||
return
|
||||
|
@ -739,11 +759,12 @@ build_targets()
|
|||
fi
|
||||
|
||||
if [ "$scanbuild" = "true" ]; then
|
||||
mv ${scanbuild_out}tmp/* ${scanbuild_out}
|
||||
rmdir ${scanbuild_out}tmp
|
||||
mv "${scanbuild_out}tmp/"* "${scanbuild_out}"
|
||||
rmdir "${scanbuild_out}tmp"
|
||||
fi
|
||||
rm -rf $TARGET/temp $TMPCFG
|
||||
echo $targets | xargs -P ${cpus:-0} -n 1 $0 $cmdline -t
|
||||
rm -rf "$TARGET/temp" "$TMPCFG"
|
||||
# shellcheck disable=SC2086
|
||||
echo $targets | xargs -P ${cpus:-0} -n 1 "$0" $cmdline -t
|
||||
}
|
||||
fi
|
||||
|
||||
|
@ -756,33 +777,33 @@ junit '<testsuite>'
|
|||
|
||||
if [ "$target" != "" ]; then
|
||||
# build a single board
|
||||
MAINBOARD=$(normalize_target ${target})
|
||||
MAINBOARD=$(normalize_target "${target}")
|
||||
if [ -z "${MAINBOARD}" ]; then
|
||||
printf "No such target: $target\n"
|
||||
printf "No such target: %s\n" "$target"
|
||||
exit 1
|
||||
fi
|
||||
build_srcdir=$(mainboard_directory ${MAINBOARD})
|
||||
if [ "$(echo ${MAINBOARD} | wc -w)" -gt 1 ]; then
|
||||
build_targets ${MAINBOARD}
|
||||
elif [ ! -r $ROOT/src/mainboard/${build_srcdir} ]; then
|
||||
printf "No such target: ${MAINBOARD}\n"
|
||||
build_srcdir="$(mainboard_directory "${MAINBOARD}")"
|
||||
if [ "$(echo "${MAINBOARD}" | wc -w)" -gt 1 ]; then
|
||||
build_targets "${MAINBOARD}"
|
||||
elif [ ! -r "$ROOT/src/mainboard/${build_srcdir}" ]; then
|
||||
echo "No such target: ${MAINBOARD}"
|
||||
exit 1
|
||||
else
|
||||
build_target ${MAINBOARD}
|
||||
build_target "${MAINBOARD}"
|
||||
test "$mode" != "text" && \
|
||||
test -f $TARGET/abuild/${MAINBOARD}.xml && \
|
||||
cat $TARGET/abuild/${MAINBOARD}.xml >> $REAL_XMLFILE
|
||||
test -f "$TARGET/abuild/${MAINBOARD}.xml" && \
|
||||
cat "$TARGET/abuild/${MAINBOARD}.xml" >> "$REAL_XMLFILE"
|
||||
XMLFILE=$REAL_XMLFILE
|
||||
fi
|
||||
else
|
||||
build_targets
|
||||
rm -f $REAL_XMLFILE
|
||||
XMLFILE=$REAL_XMLFILE
|
||||
rm -f "$REAL_XMLFILE"
|
||||
XMLFILE="$REAL_XMLFILE"
|
||||
junit '<?xml version="1.0" encoding="utf-8"?>'
|
||||
junit '<testsuite>'
|
||||
if [ "$mode" != "text" ]; then
|
||||
for xmlfile in $TARGET/abuild/*_*.xml; do
|
||||
cat $xmlfile >> $REAL_XMLFILE
|
||||
cat "$xmlfile" >> "$REAL_XMLFILE"
|
||||
done
|
||||
fi
|
||||
XMLFILE=$REAL_XMLFILE
|
||||
|
|
Loading…
Reference in New Issue