mb/dell/snb_ivb_latitude/*/hda_verb.c: Use AZALIA_PIN_DESC macro
[coreboot.git] / util / scripts / testsoc
blobc093042301b0d102d1386fa663fac53bec037de9
1 #!/bin/bash
2 set -e -o pipefail
4 PROGNAME="$(basename "${0}")"
5 VERSION="1.00"
7 ABUILD="./util/abuild/abuild"
8 OUTPUT="coreboot-builds"
9 MAINBOARDS=()
10 UNSORTED=()
11 CPUS=$(nproc || echo "4")
12 NO_CROS=0
14 # Extra arguments to pass to abuild
15 ABUILD_ARGS=""
17 # Text STYLE variables
18 BOLD="\033[1m"
19 RED='\033[38;5;9m'
20 GREEN='\033[38;5;2m'
21 NO_COLOR='\033[0m'
23 usage() {
24 cat <<EOF
25 The ${PROGNAME} script helps select boards to run test builds on. It searches
26 through all of the mainboard Kconfig files for specified identifiers and then
27 runs abuild on the mainboards it finds.
29 Usage: ${PROGNAME} [options]
31 Options:
32 -a | --abuild "<text>" Specify options to pass to abuild
33 -C | --cpus <num> Specify number of CPUs to use (currently ${CPUS})
34 -K | --kconfig <CONFIG> Search for Kconfig option
35 -n | --no_cros Don't run chromeos builds
36 -h | --help Print usage and exit
37 -D | --debug Print debug information. Use -DD to show all commands
38 -V | --version Print the version and exit
39 --nocolor Don't print color codes
40 EOF
43 _echo_color() {
44 local color="$1"
45 local text="$2"
46 local newline="${3:-0}"
47 if [[ ${newline} == "0" ]]; then
48 printf "${color}%s${NO_COLOR}" "${text}"
49 else
50 printf "${color}%s${NO_COLOR}\n" "${text}"
54 _echo_error() {
55 _echo_color "${RED}" "$*" 1 >&2
58 show_version() {
59 echo
60 _echo_color "${BOLD}${GREEN}" "${PROGNAME} version ${VERSION}"
61 echo
64 get_real_dir() (
65 cd -- "$1" >/dev/null 2>&1 || exit 1
66 pwd -P
69 get_args() {
70 local mblist
71 local mainboards=()
73 if ! args="$(getopt -l version,help,debug,nocolor,kconfig:,cpus:,no_cros,abuild: -o a:C:K:nDhV -- "$@")"; then
74 usage
75 exit 1
78 eval set -- "${args}"
80 while true; do
81 case "$1" in
82 -a | --abuild)
83 shift
84 ABUILD_ARGS=$1
86 -C | --cpus)
87 shift
88 CPUS=$1
90 -K | --kconfig)
91 shift
92 mblist=$(grep -r "$1" src/mainboard | grep Kconfig | sed 's|src/mainboard/||;s|/Kconfig.*||')
93 printf "Adding mainboard for %s\n%s\n" "$1" "${mblist}"
94 echo
95 mapfile -t mainboards <<<"$mblist"
96 UNSORTED+=(${mainboards[@]})
98 -n | no_cros)
99 NO_CROS=1
101 -D | --debug)
102 if [ -n "${VERBOSE}" ]; then
103 set -x
104 else
105 VERBOSE="V=1"
108 -h | --help)
109 usage
110 exit 0
112 --nocolor)
113 BOLD=""
114 RED=""
115 GREEN=""
116 NO_COLOR=""
118 -V | --version) exit 0 ;;
120 shift
121 break
124 _echo_error "Unknown argument '$1'"
125 usage
126 exit 1
128 esac
129 shift
130 done
132 if [[ -n $1 ]]; then
133 _echo_error "Unknown command '$1'"
134 echo
135 usage
136 exit 1
140 main() {
141 show_version
142 get_args "$@"
144 if [[ ! -f "MAINTAINERS" ]]; then
145 echo "${PWD}"
146 _echo_error "Error: This doesn't look like the coreboot directory."
147 exit 1
150 # Sort and dedupe list
151 mapfile -t MAINBOARDS <<<"$(printf "%s\n" "${UNSORTED[@]}" | sort -u)"
153 if [[ "${#MAINBOARDS[@]}" != "0" ]]; then
154 echo "Using ${CPUS} CPUs to build ${#MAINBOARDS[@]} boards:"
155 printf "%s\n" "${MAINBOARDS[@]}"
156 echo
157 else
158 _echo_error "Error: No mainboards found/specified."
159 exit 1
162 for board in ${MAINBOARDS[*]}; do
163 rm -rf "./${OUTPUT}"
165 # Non-CrOS build
166 if ! "${ABUILD}" --exitcode --cpus ${CPUS} --target "${board}" ${ABUILD_ARGS}; then
167 _echo_error "Error: Non-cros build of ${board} failed."
168 exit 1
171 # CrOS build
172 if [[ ${NO_CROS} -eq 0 ]]; then
173 rm -rf "./${OUTPUT}"
174 if ! "${ABUILD}" --exitcode --cpus ${CPUS} --target "${board}" --chromeos ${ABUILD_ARGS}; then
175 _echo_error "Error: CrOS build of ${board} failed."
176 exit 1
180 done
182 echo
183 echo "Successfully built all boards:"
184 printf "%s\n" "${MAINBOARDS[@]}"
188 main "$@"