| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | set -e -o pipefail |
| 3 | |
| 4 | PROGNAME="$(basenamescip-shell system . . basename. "${0}")" |
| 5 | VERSION="1.00" |
| 6 | |
| 7 | ABUILD="./util/abuild/abuild" |
| 8 | OUTPUT="coreboot-builds" |
| 9 | MAINBOARDS=() |
| 10 | UNSORTED=() |
| 11 | CPUS=$(nprocscip-shell system . . nproc. || echoscip-shell system . . echo. "4") |
| 12 | NO_CROS=0 |
| 13 | |
| 14 | # Extra arguments to pass to abuild |
| 15 | ABUILD_ARGS="" |
| 16 | |
| 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' |
| 22 | |
| 23 | usagescip-shell shell coreboot 25.09+dfsg-1 usage().() { |
| 24 | catscip-shell system . . 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. |
| 28 | |
| 29 | Usage: ${PROGNAME} [options] |
| 30 | |
| 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 |
| 41 | } |
| 42 | |
| 43 | _echo_colorscip-shell shell coreboot 25.09+dfsg-1 _echo_color().() { |
| 44 | local color="$1" |
| 45 | local text="$2" |
| 46 | local newline="${3:-0}" |
| 47 | if [[ ${newline} == "0" ]]; then |
| 48 | printfscip-shell system . . printf. "${color}%s${NO_COLOR}" "${text}" |
| 49 | else |
| 50 | printfscip-shell system . . printf. "${color}%s${NO_COLOR}\n" "${text}" |
| 51 | fi |
| 52 | } |
| 53 | |
| 54 | _echo_errorscip-shell shell coreboot 25.09+dfsg-1 _echo_error().() { |
| 55 | _echo_colorscip-shell shell coreboot 25.09+dfsg-1 _echo_color(). "${RED}" "$*" 1 >&2 |
| 56 | } |
| 57 | |
| 58 | show_versionscip-shell shell coreboot 25.09+dfsg-1 show_version().() { |
| 59 | echoscip-shell system . . echo. |
| 60 | _echo_colorscip-shell shell coreboot 25.09+dfsg-1 _echo_color(). "${BOLD}${GREEN}" "${PROGNAME} version ${VERSION}" |
| 61 | echoscip-shell system . . echo. |
| 62 | } |
| 63 | |
| 64 | get_real_dirscip-shell shell coreboot 25.09+dfsg-1 get_real_dir().() ( |
| 65 | cd -- "$1" >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 || exit 1 |
| 66 | pwdscip-shell system . . pwd. -P |
| 67 | ) |
| 68 | |
| 69 | get_argsscip-shell shell coreboot 25.09+dfsg-1 get_args().() { |
| 70 | local mblist |
| 71 | local mainboards=() |
| 72 | |
| 73 | if ! args="$(getoptscip-shell system . . getopt. -l version,help,debug,nocolor,kconfig:,cpus:,no_cros,abuild: -o a:C:K:nDhV -- "$@")"; then |
| 74 | usagescip-shell shell coreboot 25.09+dfsg-1 usage(). |
| 75 | exit 1 |
| 76 | fi |
| 77 | |
| 78 | eval set -- "${args}" |
| 79 | |
| 80 | while truescip-shell system . . true.; do |
| 81 | case "$1" in |
| 82 | -a | --abuild) |
| 83 | shift |
| 84 | ABUILD_ARGS=$1 |
| 85 | ;; |
| 86 | -C | --cpus) |
| 87 | shift |
| 88 | CPUS=$1 |
| 89 | ;; |
| 90 | -K | --kconfig) |
| 91 | shift |
| 92 | mblist=$(grepscip-shell system . . grep. -r "$1" src/mainboard | grepscip-shell system . . grep. Kconfig | sedscip-shell system . . sed. 's|src/mainboard/||;s|/Kconfig.*||') |
| 93 | printfscip-shell system . . printf. "Adding mainboard for %s\n%s\n" "$1" "${mblist}" |
| 94 | echoscip-shell system . . echo. |
| 95 | mapfile -t mainboards <<<"$mblist" |
| 96 | UNSORTED+=(${mainboards[@]}) |
| 97 | ;; |
| 98 | -n | no_cros) |
| 99 | NO_CROS=1 |
| 100 | ;; |
| 101 | -D | --debug) |
| 102 | if [scip-shell system . . `[`. -n "${VERBOSE}" ]; then |
| 103 | set -x |
| 104 | else |
| 105 | VERBOSE="V=1" |
| 106 | fi |
| 107 | ;; |
| 108 | -h | --help) |
| 109 | usagescip-shell shell coreboot 25.09+dfsg-1 usage(). |
| 110 | exit 0 |
| 111 | ;; |
| 112 | --nocolor) |
| 113 | BOLD="" |
| 114 | RED="" |
| 115 | GREEN="" |
| 116 | NO_COLOR="" |
| 117 | ;; |
| 118 | -V | --version) exit 0 ;; |
| 119 | --) |
| 120 | shift |
| 121 | break |
| 122 | ;; |
| 123 | *) |
| 124 | _echo_errorscip-shell shell coreboot 25.09+dfsg-1 _echo_error(). "Unknown argument '$1'" |
| 125 | usagescip-shell shell coreboot 25.09+dfsg-1 usage(). |
| 126 | exit 1 |
| 127 | ;; |
| 128 | esac |
| 129 | shift |
| 130 | done |
| 131 | |
| 132 | if [[ -n $1 ]]; then |
| 133 | _echo_errorscip-shell shell coreboot 25.09+dfsg-1 _echo_error(). "Unknown command '$1'" |
| 134 | echoscip-shell system . . echo. |
| 135 | usagescip-shell shell coreboot 25.09+dfsg-1 usage(). |
| 136 | exit 1 |
| 137 | fi |
| 138 | } |
| 139 | |
| 140 | mainscip-shell shell coreboot 25.09+dfsg-1 main().() { |
| 141 | show_versionscip-shell shell coreboot 25.09+dfsg-1 show_version(). |
| 142 | get_argsscip-shell shell coreboot 25.09+dfsg-1 get_args(). "$@" |
| 143 | |
| 144 | if [[ ! -f "MAINTAINERS" ]]; then |
| 145 | echoscip-shell system . . echo. "${PWD}" |
| 146 | _echo_errorscip-shell shell coreboot 25.09+dfsg-1 _echo_error(). "Error: This doesn't look like the coreboot directory." |
| 147 | exit 1 |
| 148 | fi |
| 149 | |
| 150 | # Sort and dedupe list |
| 151 | mapfile -t MAINBOARDS <<<"$(printfscip-shell system . . printf. "%s\n" "${UNSORTED[@]}" | sortscip-shell system . . sort. -u)" |
| 152 | |
| 153 | if [[ "${#MAINBOARDS[@]}" != "0" ]]; then |
| 154 | echoscip-shell system . . echo. "Using ${CPUS} CPUs to build ${#MAINBOARDS[@]} boards:" |
| 155 | printfscip-shell system . . printf. "%s\n" "${MAINBOARDS[@]}" |
| 156 | echoscip-shell system . . echo. |
| 157 | else |
| 158 | _echo_errorscip-shell shell coreboot 25.09+dfsg-1 _echo_error(). "Error: No mainboards found/specified." |
| 159 | exit 1 |
| 160 | fi |
| 161 | |
| 162 | for board in ${MAINBOARDS[*]}; do |
| 163 | rmscip-shell system . . rm. -rf "./${OUTPUT}" |
| 164 | |
| 165 | # Non-CrOS build |
| 166 | if ! "${ABUILD}" --exitcode --cpus ${CPUS} --target "${board}" ${ABUILD_ARGS}; then |
| 167 | _echo_errorscip-shell shell coreboot 25.09+dfsg-1 _echo_error(). "Error: Non-cros build of ${board} failed." |
| 168 | exit 1 |
| 169 | fi |
| 170 | |
| 171 | # CrOS build |
| 172 | if [[ ${NO_CROS} -eq 0 ]]; then |
| 173 | rmscip-shell system . . rm. -rf "./${OUTPUT}" |
| 174 | if ! "${ABUILD}" --exitcode --cpus ${CPUS} --target "${board}" --chromeos ${ABUILD_ARGS}; then |
| 175 | _echo_errorscip-shell shell coreboot 25.09+dfsg-1 _echo_error(). "Error: CrOS build of ${board} failed." |
| 176 | exit 1 |
| 177 | fi |
| 178 | fi |
| 179 | |
| 180 | done |
| 181 | |
| 182 | echoscip-shell system . . echo. |
| 183 | echoscip-shell system . . echo. "Successfully built all boards:" |
| 184 | printfscip-shell system . . printf. "%s\n" "${MAINBOARDS[@]}" |
| 185 | |
| 186 | } |
| 187 | |
| 188 | mainscip-shell shell coreboot 25.09+dfsg-1 main(). "$@" |