util/superiotool/smsc.c: Add some register dumps
[coreboot.git] / util / abuild / abuild
blob3228d098c10e5ae2e9a5f5b37596e4e076932a5e
1 #!/usr/bin/env bash
3 # coreboot autobuild
5 # This script builds coreboot images for all available targets.
7 # (C) 2004 by Stefan Reinauer <stepan@openbios.org>
8 # (C) 2006-2010 by coresystems GmbH <info@coresystems.de>
9 # (C) 2013-2014 Sage Electronic Engineering, LLC
10 # (C) 2014 Patrick Georgi <patrick@georgi-clan.de>
12 # This file is subject to the terms and conditions of the GNU General
13 # Public License. See the file COPYING in the main directory of this
14 # archive for more details.
17 #set -x # Turn echo on....
19 ABUILD_DATE="Mar 28, 2017"
20 ABUILD_VERSION="0.10.03"
22 TOP=$PWD
24 # Where shall we place all the build trees?
25 TARGET=${COREBOOT_BUILD_DIR:-coreboot-builds}
26 XMLFILE=$TOP/abuild.xml
27 REAL_XMLFILE=$XMLFILE
29 export KCONFIG_OVERWRITECONFIG=1
31 # path to payload. Should be more generic
32 PAYLOAD=/dev/null
34 # get path to coreboot XGCC if it's not already set
35 if [ -z "$XGCCPATH" ]; then
36 XGCCPATH="${TOP}/util/crossgcc/xgcc/bin/"
39 # Add XGCC to the path.
40 if [ -d "$XGCCPATH" ] && [[ ":$PATH:" != *":$XGCCPATH:"* ]]; then
41 PATH="$XGCCPATH:$PATH"
44 # Lines of error context to be printed in FAILURE case
45 CONTEXT=12
47 # Configure-only mode
48 configureonly=0
50 # Did any board fail to build?
51 failed=0
53 # Exit with a non-zero errorlevel on failure
54 exitcode=0
56 # default: don't save checksums
57 checksum_file=""
59 # default: single CPU build
60 cpus=1
62 # change with -d <directory>
63 configdir="$TOP/configs"
65 # Timeless builds
66 TIMELESS=0
68 # One might want to adjust these in case of cross compiling
69 for i in make gmake gnumake nonexistant_make; do
70 $i --version 2>/dev/null |grep "GNU Make" >/dev/null && break
71 done
72 if [ "$i" = "nonexistant_make" ]; then
73 echo No GNU Make found.
74 exit 1
76 MAKE=$i
78 # this can be changed to junit by -J
79 mode=text
81 # quiet mode: only print pass, failure, and 'skipped' messages
82 quiet=false
84 # clang mode enabled by -sb option.
85 scanbuild=false
87 # Mark whether abuild was called recursively
88 recursive=false
90 trap interrupt INT
92 function interrupt
94 printf "\n%s: execution interrupted manually.\n" "$0"
95 if [ "$mode" == "junit" ]; then
96 printf "%s: deleting incomplete xml output file.\n" "$0"
98 exit 1
101 function debug
103 test "$verbose" == "true" && echo "$*"
106 function junit
108 test "$mode" == "junit" && echo "$*" >> "$XMLFILE"
109 return 0
112 function junitfile
114 test "$mode" == "junit" && {
115 printf '<![CDATA[\n'
116 cat "$1"
117 printf ']]>\n'
118 } >> "$XMLFILE"
121 # Return mainboard descriptors.
122 # By default all mainboards are listed, but when passing a two-level path
123 # below src/mainboard, such as emulation/qemu-i440fx, or emulation/*, it
124 # returns all board descriptors in that hierarchy.
125 function get_mainboards
127 local search_space=${1-*/*}
128 # shellcheck disable=SC2086
129 grep -h "^[[:space:]]*config\>[[:space:]]*\<BOARD_" \
130 ${ROOT}/src/mainboard/${search_space}/Kconfig.name 2>/dev/null | \
131 sed "s,^.*\<BOARD_\([A-Z0-9_]*\)\>.*$,\1,"
134 # Given a mainboard descriptor, return its directory below src/mainboard
135 function mainboard_directory
137 local MAINBOARD=$1
139 # shellcheck disable=SC2086
140 grep -l "^[[:space:]]*config\>[[:space:]]*\<BOARD_${MAINBOARD}\>" \
141 ${ROOT}/src/mainboard/*/*/Kconfig.name | \
142 sed "s:^$ROOT/src/mainboard/\(.*\)/Kconfig.name$:\1:"
145 # Given a mainboard descriptor, return its vendor (CONFIG_VENDOR_*)
146 function mainboard_vendor
148 local MAINBOARD=$1
149 local kconfig_file
151 # shellcheck disable=SC2086
152 kconfig_file=$( \
153 grep -l "^[[:space:]]*config\>[[:space:]]*\<BOARD_${MAINBOARD}\>" \
154 ${ROOT}/src/mainboard/*/*/Kconfig.name | \
155 sed "s:^\(${ROOT}/src/mainboard/.*\)/.*/\(Kconfig.name\)$:\1/\2:" )
156 if [ ! -f "$kconfig_file" ]; then
157 exit 1
159 grep "^[[:space:]]*config\>[[:space:]]*\<VENDOR_" "$kconfig_file" | \
160 sed "s,^.*\<VENDOR_\([A-Z0-9_]*\)\>.*$,\1,"
163 # Accepts directory names (eg. emulation/qemu-i440fx) and mainboard
164 # descriptors (eg. EMULATION_QEMU_X86_I440F} and returns the latter
165 # format.
166 # If a directory contains multiple boards, returns them all.
167 function normalize_target
169 # TODO: Change 'targets' variable to an array
170 local targets
171 local VARIANT_UC
173 VARIANT_UC=$(echo "${variant}" | tr '[:lower:]' '[:upper:]')
175 targets=$(get_mainboards "$1")
176 if [ -n "$targets" ]; then
177 # shellcheck disable=SC2086
178 targets="$(grep "${VARIANT_UC}\$" <<< ${targets})"
179 echo "$targets"
180 return
183 targets=$(echo "$1" | tr ',' ' ')
184 for i in $targets; do
185 if [ -n "$(mainboard_directory "$i")" ]; then
186 echo "$i"
187 else
188 echo "$i is not a valid target" >&2
189 exit 1
191 done
194 # shellcheck disable=SC2129
195 function create_config
197 local BUILD_NAME=$1
198 local build_dir=$2
199 local board_srcdir
201 local config_file="${build_dir}/config.build"
202 board_srcdir="$(mainboard_directory "${BUILD_NAME}")"
204 mkdir -p "${build_dir}"
205 mkdir -p "$TARGET/sharedutils"
207 if [ "$quiet" == "false" ]; then echo " Creating config file for $BUILD_NAME..."; fi
208 echo "CONFIG_VENDOR_$(mainboard_vendor "${BUILD_NAME}")=y" > "${config_file}"
209 echo "CONFIG_BOARD_${BUILD_NAME}=y" >> "${config_file}"
210 grep "select[\t ]*ARCH" "${ROOT}/src/mainboard/${board_srcdir}/Kconfig" | \
211 sed "s,^.*\(ARCH_.*\)[^A-Z0-9_]*,CONFIG_\1=y," >> "${config_file}"
212 echo "CONFIG_MAINBOARD_DIR=\"${board_srcdir}\"" >> "${config_file}"
214 update_config "$BUILD_NAME" "$build_dir" "$config_file"
216 ret=$?
217 if [ $ret -eq 0 ]; then
218 if [ "$quiet" == "false" ]; then echo " $BUILD_NAME config created."; fi
219 return 0
220 else
221 # Does this ever happen?
222 if [ "$quiet" == "false" ]; then printf "%s config creation FAILED!\nLog excerpt:\n" "$BUILD_NAME"; fi
223 tail -n $CONTEXT "$build_dir/config.log" 2> /dev/null || tail -$CONTEXT "$build_dir/config.log"
224 return 1
228 function update_config
230 local BUILD_NAME=$1
231 local build_dir=$2
232 local config_file=$3
234 local PAYLOAD
235 local defconfig_file
236 defconfig_file=${build_dir}/config.$(echo "${BUILD_NAME}" | tr '[:upper:]' '[:lower:]').default
238 # get a working payload for the board if we have one.
239 # the --payload option expects a directory containing
240 # a shell script payload.sh
241 # Usage: payload.sh [BOARD]
242 # the script returns an absolute path to the payload binary.
244 if [ -f "$payloads/payload.sh" ]; then
245 PAYLOAD=$(sh "$payloads/payload.sh" "$BUILD_NAME")
246 local PAYLOAD_OK=$?
247 if [ $PAYLOAD_OK -gt 0 ]; then
248 echo "problem with payload"
249 exit 1
251 if [ "$quiet" == "false" ]; then printf "Using payload %s\n" "$PAYLOAD"; fi
252 elif [ "$payloads" = "none" ]; then
253 PAYLOAD=none
256 if [ "$PAYLOAD" = "none" ]; then
258 echo "CONFIG_PAYLOAD_NONE=y"
259 echo "# CONFIG_PAYLOAD_ELF is not set"
260 } >> "${config_file}"
261 elif [ "$PAYLOAD" != "/dev/null" ]; then
263 echo "# CONFIG_PAYLOAD_NONE is not set"
264 echo "CONFIG_PAYLOAD_ELF=y"
265 echo "CONFIG_PAYLOAD_FILE=\"$PAYLOAD\""
266 } >> "${config_file}"
268 # Disable all other payload config options
270 echo "# CONFIG_PAYLOAD_SEABIOS is not set"
271 echo "# CONFIG_PAYLOAD_BAYOU is not set"
272 echo "# CONFIG_PAYLOAD_FILO is not set"
273 echo "# CONFIG_PAYLOAD_GRUB2 is not set"
274 echo "# CONFIG_PAYLOAD_OPENBIOS is not set"
275 echo "# CONFIG_PAYLOAD_DEPTHCHARGE is not set"
276 echo "# CONFIG_PAYLOAD_LINUXBOOT is not set"
277 echo "# CONFIG_PAYLOAD_UBOOT is not set"
278 echo "# CONFIG_PAYLOAD_TIANOCORE is not set"
279 echo "# CONFIG_PXE is not set"
280 echo "# CONFIG_BUILD_IPXE is not set"
281 echo "# CONFIG_MEMTEST_SECONDARY_PAYLOAD is not set"
282 echo "# CONFIG_COREINFO_SECONDARY_PAYLOAD is not set"
283 echo "# CONFIG_NVRAMCUI_SECONDARY_PAYLOAD is not set"
284 echo "# CONFIG_TINT_SECONDARY_PAYLOAD is not set"
285 } >> "${config_file}"
287 if [ "$quiet" == "false" ]; then echo " $MAINBOARD ($customizing)"; fi
288 # shellcheck disable=SC2059
289 printf "$configoptions" >> "${config_file}"
291 yes "" 2>/dev/null | $MAKE oldconfig "$verboseopt" "DOTCONFIG=${config_file}" "obj=${build_dir}" "objutil=$TARGET/sharedutils" &> "${build_dir}/config.log" ; \
292 CONFIG_OK=$?
293 if [ $CONFIG_OK -eq 0 ]; then
294 $MAKE savedefconfig "$verboseopt" DEFCONFIG="${defconfig_file}" DOTCONFIG="${config_file}" obj="${build_dir}" objutil="$TARGET/sharedutils" &>> "${build_dir}/config.log"
295 return $?
296 else
297 return 1
301 # shellcheck disable=SC2129
302 function create_buildenv
304 local BUILD_NAME=$1
305 local build_dir=$2
306 local config_file=$3
308 if [ -z "$config_file" ]; then
309 create_config "$BUILD_NAME" "$build_dir"
310 else
311 local new_config_file="${build_dir}/config.build"
312 cp "$config_file" "$new_config_file"
313 update_config "$BUILD_NAME" "$build_dir" "$new_config_file"
315 local ret=$?
317 # Allow simple "make" in the target directory
318 local MAKEFILE=$TARGET/${BUILD_NAME}/Makefile
319 echo "# autogenerated" > "$MAKEFILE"
320 echo "TOP=$ROOT" >> "$MAKEFILE"
321 echo "BUILD=$TARGET" >> "$MAKEFILE"
322 echo "OBJ=\$(BUILD)/${MAINBOARD}" >> "$MAKEFILE"
323 echo "OBJUTIL=\$(BUILD)/sharedutils" >> "$MAKEFILE"
324 echo "all:" >> "$MAKEFILE"
325 echo " @cp -a config.h config.h.bak" >> "$MAKEFILE"
326 echo " @cd \$(TOP); \$(MAKE) oldconfig DOTCONFIG=\$(OBJ)/config.build objutil=\$(OBJUTIL) obj=\$(OBJ)" >> "$MAKEFILE"
327 echo " @tail -n+6 config.h > config.new; tail -n+6 config.h.bak > config.old" >> "$MAKEFILE"
328 echo " @cmp -s config.new config.old && cp -a config.h.bak config.h || echo \"Config file changed\"" >> "$MAKEFILE"
329 echo " @rm config.h.bak config.new config.old" >> "$MAKEFILE"
330 echo " @cd \$(TOP); \$(MAKE) DOTCONFIG=\$(OBJ)/config.build objutil=\$(OBJUTIL) obj=\$(OBJ)" >> "$MAKEFILE"
332 return $ret
335 function check_config
337 local BUILD_DIR="$1"
338 local TEST_TYPE="$2"
339 local TEST_STRING="$3"
341 local CONFIG_FILE="$BUILD_DIR/config.build"
342 local CONFIG_LOG="$BUILD_DIR/config.log"
344 if ! grep -q "$TEST_STRING" "$CONFIG_FILE"; then
345 echo "config file: $CONFIG_FILE has incorrect $TEST_TYPE"
346 echo "Error: Expected '$TEST_STRING' in config file." >> "$CONFIG_LOG"
347 return 1
350 return 0
353 function compile_target
355 local BUILD_NAME=$1
357 if [ "$quiet" == "false" ]; then echo " Compiling $MAINBOARD image$cpuconfig..."; fi
359 CURR=$( pwd )
360 #stime=`perl -e 'print time();' 2>/dev/null || date +%s`
361 eval "$BUILDPREFIX" "$MAKE" "$verboseopt" DOTCONFIG="${build_dir}/config.build" obj="${build_dir}" objutil="$TARGET/sharedutils" BUILD_TIMELESS=$TIMELESS \
362 &> "${build_dir}/make.log" ; \
363 MAKE_FAILED=$?
364 cp "${ROOT}/.xcompile" "${build_dir}/xcompile.build"
365 cd "${build_dir}" || return $?
367 etime=$(perl -e 'print time();' 2>/dev/null || date +%s)
368 duration=$(( etime - stime ))
369 junit " <testcase classname='board${testclass/#/.}' name='$BUILD_NAME' time='$duration' >"
371 if [ $MAKE_FAILED -eq 0 ]; then
372 junit "<system-out>"
373 junitfile make.log
374 junit "</system-out>"
375 printf "ok\n" > compile.status
376 printf "%s built successfully. (took %ss)\n" "$BUILD_NAME" "${duration}"
377 echo "$BUILD_NAME" >> "$PASSED_BOARDS"
378 else
379 junit "<failure type='BuildFailed'>"
380 junitfile make.log
381 junit "</failure>"
382 printf "failed\n" > compile.status
383 printf "%s build FAILED after %ss!\nLog excerpt:\n" "$BUILD_NAME" "${duration}"
384 tail -n $CONTEXT make.log 2> /dev/null || tail -$CONTEXT make.log
385 if [ "$clean_work" = "true" ]; then
386 echo "$BUILD_NAME" >> "$FAILED_BOARDS"
387 else
388 echo "$BUILD_NAME - Log: ${build_dir}/make.log" >> "$FAILED_BOARDS"
390 failed=1
392 cd "$CURR" || return $?
393 if [ -n "$checksum_file" ]; then
394 sha256sum "${build_dir}/coreboot.rom" >> "${checksum_file}_platform"
395 sort "${build_dir}/config.h" | grep CONFIG_ > "${build_dir}/config.h.sorted"
396 sha256sum "${build_dir}/config.h.sorted" >> "${checksum_file}_config"
398 if [ "$clean_work" = "true" ]; then
399 rm -rf "${build_dir}"
401 return $MAKE_FAILED
404 function build_config
406 local MAINBOARD=$1
407 local build_dir=$2
408 local BUILD_NAME=$3
409 local config_file=$4
410 local board_srcdir
411 local ret
413 board_srcdir=$(mainboard_directory "${MAINBOARD}")
415 if [ "$(cat "${build_dir}/compile.status" 2>/dev/null)" = "ok" ] && \
416 [ "$buildall" = "false" ]; then
417 echo "Skipping $BUILD_NAME; (already successful)"
418 return
421 export HOSTCC='gcc'
423 if [ "$chromeos" = true ] && [ "$(grep -c "^[[:space:]]*select[[:space:]]*MAINBOARD_HAS_CHROMEOS\>" "${ROOT}/src/mainboard/${board_srcdir}/Kconfig")" -eq 0 ]; then
424 echo "${BUILD_NAME} doesn't support Chrome OS, skipping."
425 return
428 if [ -f "src/mainboard/${board_srcdir}/abuild.disabled" ]; then
429 echo "${BUILD_NAME} disabled:"
430 cat "src/mainboard/${board_srcdir}/abuild.disabled"
431 return
434 if [ "$quiet" == "false" ]; then echo "Building $BUILD_NAME"; fi
435 mkdir -p "$TARGET/${BUILD_NAME}" "$TARGET/abuild"
436 ABSPATH="$(cd "$TARGET/abuild" && pwd)"
437 XMLFILE="$ABSPATH/${BUILD_NAME}.xml"
438 rm -f "${XMLFILE}"
440 stime=$(perl -e 'print time();' 2>/dev/null || date +%s)
441 create_buildenv "$BUILD_NAME" "$build_dir" "$config_file"
442 local BUILDENV_CREATED=$?
444 check_config "$build_dir" "mainboard" "CONFIG_BOARD_${MAINBOARD}=y"
445 local MAINBOARD_OK=$?
447 check_config "$build_dir" "vendor" "CONFIG_VENDOR_$(mainboard_vendor "${MAINBOARD}")=y"
448 local VENDOR_OK=$?
450 if [ $BUILDENV_CREATED -ne 0 ] || [ $MAINBOARD_OK -ne 0 ] || [ $VENDOR_OK -ne 0 ]; then
451 junit " <testcase classname='board${testclass/#/.}' name='$BUILD_NAME' >"
453 junit "<failure type='BuildFailed'>"
454 junitfile "$build_dir/config.log"
455 junit "</failure>"
456 printf "failed\n" > compile.status
457 printf "%s build configuration FAILED!\nLog excerpt:\n" "$BUILD_NAME"
458 tail -n $CONTEXT "$build_dir/config.log" 2> /dev/null || tail -$CONTEXT "$build_dir/config.log"
460 junit "</testcase>"
461 echo "$BUILD_NAME - Log: ${TOP}/$build_dir/config.log" >> "$FAILED_BOARDS"
462 return
465 required_arches=$(grep -E "^CONFIG_ARCH_(BOOTBLOCK|R.MSTAGE|VERSTAGE)" "$TARGET/${BUILD_NAME}/config.build" | \
466 sed "s,^CONFIG_ARCH_[^_]*_\([^=]*\)=.*$,\1," |sort -u |tr 'A-Z\n\r' 'a-z ')
467 # shellcheck disable=SC2016,SC2059
468 missing_arches=$(printf 'include .xcompile\nall: ; @echo $(foreach arch,'"$required_arches"',$(if $(filter $(arch),$(SUBARCH_SUPPORTED)),,$(arch)))' | $MAKE --no-print-directory -f -)
469 if [ -n "$missing_arches" ]; then
470 printf "skipping %s because we're missing compilers for (%s)\n" "$BUILD_NAME" "$missing_arches"
471 return
474 if [ $BUILDENV_CREATED -eq 0 ] && [ $configureonly -eq 0 ]; then
475 BUILDPREFIX=
476 if [ "$scanbuild" = "true" ]; then
477 scanbuild_out=$TARGET/${BUILD_NAME}-scanbuild
478 rm -rf "${scanbuild_out}"
479 BUILDPREFIX="scan-build ${SCANBUILD_ARGS} -o ${scanbuild_out}tmp"
481 compile_target "${BUILD_NAME}"
482 if [ "$scanbuild" = "true" ]; then
483 mv "${scanbuild_out}"tmp/* "${scanbuild_out}"
484 rmdir "${scanbuild_out}tmp"
488 junit "</testcase>"
491 # One target may build several configs
492 function build_target
494 local MAINBOARD=$1
495 local MAINBOARD_LC
496 MAINBOARD_LC=$(echo "$MAINBOARD" | tr '[:upper:]' '[:lower:]')
498 # look for config files in the config directory that match the boardname
499 if [ -n "$( find "$configdir" -maxdepth 1 -name "config.${MAINBOARD_LC}*" -print -quit )" ]; then
500 for config in "$configdir/config.${MAINBOARD_LC}"*; do
501 BUILD_NAME="${config##*/}"
502 BUILD_NAME="${BUILD_NAME##config.}"
503 BUILD_NAME=$(echo "${BUILD_NAME}" | tr '[:lower:]' '[:upper:]')
504 echo "Building config $BUILD_NAME"
505 build_dir=$TARGET/${BUILD_NAME}
506 build_config "$MAINBOARD" "$build_dir" "$BUILD_NAME" "$config"
507 remove_target "$BUILD_NAME"
509 done
510 else
511 echo "Building board $MAINBOARD (using default config)"
512 build_dir=$TARGET/${MAINBOARD}
514 build_config "$MAINBOARD" "$build_dir" "$MAINBOARD"
515 remove_target "$MAINBOARD"
520 function remove_target
522 if [ "$remove" != "true" ]; then
523 return
526 local BUILD_NAME=$1
528 # Save the generated coreboot.rom file of each board.
529 if [ -r "$TARGET/${BUILD_NAME}/coreboot.rom" ]; then
530 cp "$TARGET/${BUILD_NAME}/coreboot.rom" \
531 "${BUILD_NAME}_coreboot.rom"
534 echo "Removing build dir for $BUILD_NAME..."
535 rm -rf "${TARGET:?}/${BUILD_NAME}"
537 return
540 function myhelp
542 cat << __END_OF_HELP
543 Usage: $0 [options]
544 $0 [-V|--version]
545 $0 [-h|--help]
547 Options:\n"
548 [-a|--all] Build previously succeeded ports as well
549 [-A|--any-toolchain] Use any toolchain
550 [-b|--board-variant <name>] Build specific board variant under the
551 given target.
552 [-B|--blobs] Allow using binary files
553 [--checksum <path/basefile>] Store checksums at path/basefile
554 [-c|--cpus <numcpus>] Build on <numcpus> at the same time
555 [-C|--config] Configure-only mode
556 [-d|--dir <dir>] Directory containing config files
557 [-e|--exitcode] Exit with a non-zero errorlevel on failure
558 [-J|--junit] Write JUnit formatted xml log file
559 [-K|--kconfig <name>] Prepend file to generated Kconfig
560 [-l|--loglevel <num>] Set loglevel
561 [-L|--clang] Use clang
562 [-o|--outdir <path>] Store build results in path
563 (defaults to $TARGET)
564 [-p|--payloads <dir>] Use payloads in <dir> to build images
565 [-P|--prefix <name>] File name prefix in CBFS
566 [-q|--quiet] Print fewer messages
567 [-r|--remove] Remove output dir after build
568 [-R|--root <path>] Absolute path to coreboot sources
569 (defaults to $ROOT)
570 [--scan-build] Use clang's static analyzer
571 [--timeless] Generate timeless builds
572 [-t|--target <vendor/board>] Attempt to build target vendor/board only
573 [-T|--test] Submit image(s) to automated test system
574 [-u|--update] Update existing image
575 [-v|--verbose] Print more messages
576 [-x|--chromeos] Build with CHROMEOS enabled
577 Skip boards without Chrome OS support
578 [-X|--xmlfile <name>] Set JUnit XML log file filename
579 (defaults to $XMLFILE)
580 [-y|--ccache] Use ccache
581 [-z|--clean] Remove build results when finished
583 [-V|--version] Print version number and exit
584 [-h|--help] Print this help and exit
586 [-s|--silent] obsolete
587 __END_OF_HELP
590 function myversion
592 cat << EOF
594 coreboot autobuild v$ABUILD_VERSION ($ABUILD_DATE)
596 Copyright (C) 2004 by Stefan Reinauer <stepan@openbios.org>
597 Copyright (C) 2006-2010 by coresystems GmbH <info@coresystems.de>
599 This program is free software; you may redistribute it under the terms
600 of the GNU General Public License. This program has absolutely no
601 warranty.
606 # default options
607 target=""
608 buildall=false
609 verbose=false
611 test -f util/sconfig/sconfig.l && ROOT=$( pwd )
612 test -f ../util/sconfig/sconfig.l && ROOT=$( cd .. && pwd )
613 test "$ROOT" = "" && ROOT=$( cd ../.. && pwd )
615 # Look if we have getopt. If not, build it.
616 export PATH=$PATH:util/abuild
617 getopt - > /dev/null 2>/dev/null || gcc -o util/abuild/getopt util/abuild/getopt.c
619 # Save command line for xargs parallelization.
620 cmdline=("$@")
622 # parse parameters.. try to find out whether we're running GNU getopt
623 getoptbrand="$(getopt -V)"
625 # shellcheck disable=SC2086
626 if [ "${getoptbrand:0:6}" == "getopt" ]; then
627 # Detected GNU getopt that supports long options.
628 args=$(getopt -l version,verbose,quiet,help,all,target:,board-variant:,payloads:,cpus:,silent,junit,config,loglevel:,remove,prefix:,update,scan-build,ccache,blobs,clang,any-toolchain,clean,outdir:,chromeos,xmlfile:,kconfig:,dir:,root:,recursive,checksum:,timeless,exitcode -o Vvqhat:b:p:c:sJCl:rP:uyBLAzo:xX:K:d:R:Ie -- "$@") || exit 1
629 eval set -- $args
630 retval=$?
631 else
632 # Detected non-GNU getopt
633 args=$(getopt Vvqhat:b:p:c:sJCl:rP:uyBLAzo:xX:K:d:R:Ie "$@")
634 set -- $args
635 retval=$?
638 if [ $retval != 0 ]; then
639 myhelp
640 exit 1
643 chromeos=false
644 clean_work=false
645 verboseopt='V=0'
646 customizing=""
647 configoptions=""
648 # testclass needs to be undefined if not used for variable expansion to work
649 unset testclass
650 while true ; do
651 case "$1" in
652 -J|--junit) shift; mode=junit; rm -f "$XMLFILE" ;;
653 -t|--target) shift; target="$1"; shift;;
654 -b|--board-variant) shift; variant="$1"; shift;;
655 -a|--all) shift; buildall=true;;
656 -d|--dir) shift; configdir="$1"; shift;;
657 -e|--exitcode) shift; exitcode=1;;
658 -r|--remove) shift; remove=true;;
659 -v|--verbose) shift; verbose=true; verboseopt='V=1';;
660 -q|--quiet) shift; quiet=true;;
661 -V|--version) shift; myversion; exit 0;;
662 -h|--help) shift; myversion; myhelp; exit 0;;
663 -p|--payloads) shift; payloads="$1"; shift;;
664 -R|--root) shift; ROOT="$1"; MAKE="$MAKE -C $1"; shift;;
665 -c|--cpus) shift
666 export MAKEFLAGS="-j $1"
667 cpus=$1
668 test "$MAKEFLAGS" == "-j max" && export MAKEFLAGS="-j" && cpuconfig=" in parallel"
669 test "$1" == "1" && cpuconfig=" on 1 cpu"
670 expr "$1" : '-\?[0-9]\+$' > /dev/null && test "0$1" -gt 1 && cpuconfig=" on $1 cpus in parallel"
671 shift;;
672 # obsolete option
673 -s|--silent) shift;;
674 --scan-build) shift
675 scanbuild=true
676 customizing="${customizing}, scan-build"
677 SCANBUILD_ARGS=${SCANBUILD_ARGS:-'-k'}
679 -y|--ccache) shift
680 customizing="${customizing}, ccache"
681 configoptions="${configoptions}CONFIG_CCACHE=y\n"
683 -C|--config) shift; configureonly=1;;
684 -l|--loglevel) shift
685 customizing="${customizing}, loglevel $1"
686 configoptions="${configoptions}CONFIG_DEFAULT_CONSOLE_LOGLEVEL_$1=y\n"
687 configoptions="${configoptions}CONFIG_DEFAULT_CONSOLE_LOGLEVEL=$1\n"
688 shift;;
689 -u|--update) shift
690 customizing="${customizing}, update"
691 configoptions="${configoptions}CONFIG_UPDATE_IMAGE=y\n"
693 -P|--prefix) shift
694 customizing="${customizing}, cbfs prefix $1"
695 configoptions="${configoptions}CONFIG_CBFS_PREFIX=\"$1\""
696 shift;;
697 -B|--blobs) shift
698 customizing="${customizing}, blobs"
699 configoptions="${configoptions}CONFIG_USE_BLOBS=y\n"
701 -A|--any-toolchain) shift
702 customizing="${customizing}, any-toolchain"
703 configoptions="${configoptions}CONFIG_ANY_TOOLCHAIN=y\n"
705 -L|--clang) shift
706 customizing="${customizing}, clang"
707 configoptions="${configoptions}CONFIG_COMPILER_LLVM_CLANG=y\n# CONFIG_COMPILER_GCC is not set\n"
709 -z|--clean) shift
710 customizing="${customizing}, clean"
711 clean_work=true
713 -o|--outdir) shift
714 TARGET=$1; shift
716 -x|--chromeos) shift
717 chromeos=true
718 testclass=chromeos
719 customizing="${customizing}, chrome os"
720 configoptions="${configoptions}CONFIG_CHROMEOS=y\n"
722 -X|--xmlfile) shift; XMLFILE=$1; REAL_XMLFILE=$1; shift;;
723 -I|--recursive) shift; recursive=true;;
724 -K|--kconfig) shift
725 testclass="$(basename "$1" | tr '.' '_' )"
726 customizing="${customizing}, $1 config"
727 configoptions="$(cat "$1")${configoptions}\n"
728 shift;;
729 --checksum) shift; checksum_file="$1"; shift;;
730 --timeless) shift; TIMELESS=1;;
731 --) shift; break;;
732 -*) printf "Invalid option '%s'\n\n" "$1"; myhelp; exit 1;;
733 *) break;;
734 esac
735 done
736 if [ -n "$1" ]; then
737 printf "Invalid option '%s'\n\n" "$1"; myhelp; exit 1;
740 if [ -z "$TARGET" ] || [ "$TARGET" = "/" ]; then
741 echo "Please specify a valid, non-root build directory."
742 exit 1
745 customizing=$(echo "$customizing" | cut -c3-)
746 if [ "$customizing" = "" ]; then
747 customizing="default configuration"
750 FAILED_BOARDS="${TARGET}/failed_boards"
751 PASSED_BOARDS="${TARGET}/passing_boards"
753 if [ "$recursive" = "false" ]; then
754 rm -f "$FAILED_BOARDS" "$PASSED_BOARDS"
757 USE_XARGS=0
758 if [ "$cpus" != "1" ]; then
759 # Limit to 32 parallel builds for now.
760 # Thrashing all caches because we run
761 # 160 abuilds in parallel is no fun.
762 if [ "$cpus" = "max" ]; then
763 cpus=32
765 # Test if xargs supports the non-standard -P flag
766 # FIXME: disabled until we managed to eliminate all the make(1) quirks
767 echo | xargs -P ${cpus:-0} -n 1 echo 2>/dev/null >/dev/null && USE_XARGS=1
770 if [ "$USE_XARGS" = "0" ]; then
771 test "$MAKEFLAGS" == "" && test "$cpus" != "" && export MAKEFLAGS="-j $cpus"
772 build_targets()
774 local targets=${*-$(get_mainboards)}
775 for MAINBOARD in $targets; do
776 build_target "${MAINBOARD}"
777 done
779 else
780 build_targets()
782 local ABSPATH
783 local stime
784 local etime
785 local num_targets
786 local cpus_per_target
788 local targets=${*-$(get_mainboards)}
789 # seed shared utils
790 TMPCFG=$(mktemp)
791 printf "%s" "$configoptions" > "$TMPCFG"
792 $MAKE -j "$cpus" DOTCONFIG="$TMPCFG" obj="$TARGET/temp" objutil="$TARGET/sharedutils" allnoconfig
793 printf "%s" "$configoptions" >> "$TMPCFG"
794 yes "" 2>/dev/null | $MAKE -j "$cpus" DOTCONFIG="$TMPCFG" obj="$TARGET/temp" objutil="$TARGET/sharedutils" oldconfig 2>/dev/null |head > /dev/null
795 BUILDPREFIX=
796 if [ "$scanbuild" = "true" ]; then
797 scanbuild_out=$TARGET/sharedutils-scanbuild
798 rm -rf "${scanbuild_out}"
799 BUILDPREFIX="scan-build -o ${scanbuild_out}tmp"
801 mkdir -p "$TARGET/abuild"
802 ABSPATH="$(cd "$TARGET/abuild" && pwd)"
803 local XMLFILE="$ABSPATH/__util.xml"
804 rm -f "${XMLFILE}"
805 stime=$(perl -e 'print time();' 2>/dev/null || date +%s)
806 $BUILDPREFIX "$MAKE" -j "$cpus" DOTCONFIG="$TMPCFG" obj="$TARGET/temp" objutil="$TARGET/sharedutils" tools > "$TARGET/sharedutils/make.log" 2>&1
807 local ret=$?
808 etime=$(perl -e 'print time();' 2>/dev/null || date +%s)
809 local duration=$(( etime - stime ))
811 junit " <testcase classname='util' name='all' time='$duration' >"
812 if [ $ret -eq 0 ]; then
813 junit "<system-out>"
814 junitfile "$TARGET/sharedutils/make.log"
815 junit "</system-out>"
816 junit "</testcase>"
817 else
818 junit "<failure type='BuildFailed'>"
819 junitfile "$TARGET/sharedutils/make.log"
820 junit "</failure>"
821 junit "</testcase>"
822 echo "Shared Utilities - Log: $TARGET/sharedutils/make.log" >> "$FAILED_BOARDS"
823 return
826 if [ "$scanbuild" = "true" ]; then
827 mv "${scanbuild_out}tmp/"* "${scanbuild_out}"
828 rmdir "${scanbuild_out}tmp"
830 rm -rf "$TARGET/temp" "$TMPCFG"
831 num_targets=$(wc -w <<<"$targets")
832 cpus_per_target=$(((${cpus:-1} + num_targets - 1) / num_targets))
833 echo "$targets" | xargs -P ${cpus:-0} -n 1 "$0" "${cmdline[@]}" -I -c "$cpus_per_target" -t
837 junit '<?xml version="1.0" encoding="utf-8"?>'
838 junit '<testsuite>'
840 if [ "$target" != "" ]; then
841 # build a single board
842 MAINBOARD=$(normalize_target "${target}")
843 if [ -z "${MAINBOARD}" ]; then
844 printf "No such target: %s" "${target}"
845 if [ -n "${variant}" ]; then
846 printf ", variant: %s" "${variant}"
848 printf "\n"
849 exit 1
851 build_srcdir="$(mainboard_directory "${MAINBOARD}")"
852 if [ "$(echo "${MAINBOARD}" | wc -w)" -gt 1 ]; then
853 build_targets "${MAINBOARD}"
854 elif [ ! -r "$ROOT/src/mainboard/${build_srcdir}" ]; then
855 echo "No such target: ${MAINBOARD}"
856 exit 1
857 else
858 build_target "${MAINBOARD}"
859 test "$mode" != "text" && \
860 test -f "$TARGET/abuild/${MAINBOARD}.xml" && \
861 cat "$TARGET/abuild/${MAINBOARD}.xml" >> "$REAL_XMLFILE"
862 XMLFILE=$REAL_XMLFILE
864 else
865 build_targets
866 rm -f "$REAL_XMLFILE"
867 XMLFILE="$REAL_XMLFILE"
868 junit '<?xml version="1.0" encoding="utf-8"?>'
869 junit '<testsuite>'
870 if [ "$mode" != "text" ]; then
871 for xmlfile in $TARGET/abuild/*_*.xml; do
872 cat "$xmlfile" >> "$REAL_XMLFILE"
873 done
875 XMLFILE=$REAL_XMLFILE
877 junit '</testsuite>'
879 if [ "$recursive" = "false" ]; then
881 # Print the list of failed configurations
882 if [ -f "$FAILED_BOARDS" ]; then
883 printf "%s configuration(s) failed:\n" "$( wc -l < "$FAILED_BOARDS" )"
884 cat "$FAILED_BOARDS"
885 echo
886 if [ "$exitcode" != "0" ]; then
887 failed=1
889 else
890 printf "All %s tested configurations passed.\n" "$( wc -l < "$PASSED_BOARDS" )"
894 exit $failed