Martin Roth | 815c363 | 2022-10-28 21:30:31 -0600 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | set -e -o pipefail |
| 3 | |
| 4 | PROGNAME="$(basename "${0}")" |
| 5 | VERSION="1.00" |
| 6 | |
| 7 | ABUILD="./util/abuild/abuild" |
| 8 | OUTPUT="coreboot-builds" |
| 9 | MAINBOARDS=() |
| 10 | UNSORTED=() |
| 11 | CPUS=$(nproc || echo "4") |
| 12 | NO_CROS=0 |
| 13 | |
| 14 | # Text STYLE variables |
| 15 | BOLD="\033[1m" |
| 16 | RED='\033[38;5;9m' |
| 17 | GREEN='\033[38;5;2m' |
| 18 | NO_COLOR='\033[0m' |
| 19 | |
| 20 | usage() { |
| 21 | cat <<EOF |
| 22 | The ${PROGNAME} script helps select boards to run test builds on. It searches |
| 23 | through all of the mainboard Kconfig files for specified identifiers and then |
| 24 | runs abuild on the mainboards it finds. |
| 25 | |
| 26 | Usage: ${PROGNAME} [options] |
| 27 | |
| 28 | Options: |
| 29 | -C | --cpus <num> Specify number of CPUs to use (currently ${CPUS}) |
| 30 | -K | --kconfig <CONFIG> Search for Kconfig option |
| 31 | -n | --no_cros Don't run chromeos builds |
| 32 | -h | --help Print usage and exit |
| 33 | -D | --debug Print debug information. Use -DD to show all commands |
| 34 | -V | --version Print the version and exit |
| 35 | --nocolor Don't print color codes |
| 36 | EOF |
| 37 | } |
| 38 | |
| 39 | _echo_color() { |
| 40 | local color="$1" |
| 41 | local text="$2" |
| 42 | local newline="${3:-0}" |
| 43 | if [[ ${newline} == "0" ]]; then |
| 44 | printf "${color}%s${NO_COLOR}" "${text}" |
| 45 | else |
| 46 | printf "${color}%s${NO_COLOR}\n" "${text}" |
| 47 | fi |
| 48 | } |
| 49 | |
| 50 | _echo_error() { |
| 51 | _echo_color "${RED}" "$*" 1 >&2 |
| 52 | } |
| 53 | |
| 54 | show_version() { |
| 55 | echo |
| 56 | _echo_color "${BOLD}${GREEN}" "${PROGNAME} version ${VERSION}" |
| 57 | echo |
| 58 | } |
| 59 | |
| 60 | get_real_dir() ( |
| 61 | cd -- "$1" >/dev/null 2>&1 || exit 1 |
| 62 | pwd -P |
| 63 | ) |
| 64 | |
| 65 | get_args() { |
| 66 | local mblist |
| 67 | local mainboards=() |
| 68 | |
| 69 | if ! args="$(getopt -l version,help,debug,nocolor,kconfig:,cpus:,no_cros -o C:K:nDhV -- "$@")"; then |
| 70 | usage |
| 71 | exit 1 |
| 72 | fi |
| 73 | |
| 74 | eval set -- "${args}" |
| 75 | |
| 76 | while true; do |
| 77 | case "$1" in |
| 78 | -C | --cpus) |
| 79 | shift |
| 80 | CPUS=$1 |
| 81 | ;; |
| 82 | -K | --kconfig) |
| 83 | shift |
Fred Reitberger | abce429 | 2023-02-01 08:33:43 -0500 | [diff] [blame] | 84 | mblist=$(grep -r "$1" src/mainboard | grep Kconfig | sed 's|src/mainboard/||;s|/Kconfig.*||') |
Martin Roth | 815c363 | 2022-10-28 21:30:31 -0600 | [diff] [blame] | 85 | printf "Adding mainboard for %s\n%s\n" "$1" "${mblist}" |
| 86 | echo |
| 87 | mapfile -t mainboards <<<"$mblist" |
| 88 | UNSORTED+=(${mainboards[@]}) |
| 89 | ;; |
| 90 | -n | no_cros) |
| 91 | NO_CROS=1 |
| 92 | ;; |
| 93 | -D | --debug) |
| 94 | if [ -n "${VERBOSE}" ]; then |
| 95 | set -x |
| 96 | else |
| 97 | VERBOSE="V=1" |
| 98 | fi |
| 99 | ;; |
| 100 | -h | --help) |
| 101 | usage |
| 102 | exit 0 |
| 103 | ;; |
| 104 | --nocolor) |
| 105 | BOLD="" |
| 106 | RED="" |
| 107 | GREEN="" |
| 108 | NO_COLOR="" |
| 109 | ;; |
| 110 | -V | --version) exit 0 ;; |
| 111 | --) |
| 112 | shift |
| 113 | break |
| 114 | ;; |
| 115 | *) |
| 116 | _echo_error "Unknown argument '$1'" |
| 117 | usage |
| 118 | exit 1 |
| 119 | ;; |
| 120 | esac |
| 121 | shift |
| 122 | done |
| 123 | |
| 124 | if [[ -n $1 ]]; then |
| 125 | _echo_error "Unknown command '$1'" |
| 126 | echo |
| 127 | usage |
| 128 | exit 1 |
| 129 | fi |
| 130 | } |
| 131 | |
| 132 | main() { |
| 133 | show_version |
| 134 | get_args "$@" |
| 135 | |
| 136 | if [[ ! -f "MAINTAINERS" ]]; then |
| 137 | echo "${PWD}" |
| 138 | _echo_error "Error: This doesn't look like the coreboot directory." |
| 139 | exit 1 |
| 140 | fi |
| 141 | |
| 142 | # Sort and dedupe list |
| 143 | mapfile -t MAINBOARDS <<<"$(printf "%s\n" "${UNSORTED[@]}" | sort -u)" |
| 144 | |
| 145 | if [[ "${#MAINBOARDS[@]}" != "0" ]]; then |
| 146 | echo "Using ${CPUS} CPUs to build ${#MAINBOARDS[@]} boards:" |
| 147 | printf "%s\n" "${MAINBOARDS[@]}" |
| 148 | echo |
| 149 | else |
| 150 | _echo_error "Error: No mainboards found/specified." |
| 151 | exit 1 |
| 152 | fi |
| 153 | |
| 154 | for board in ${MAINBOARDS[*]}; do |
| 155 | rm -rf "./${OUTPUT}" |
| 156 | |
| 157 | # Non-CrOS build |
| 158 | if ! "${ABUILD}" --exitcode --cpus ${CPUS} --target "${board}"; then |
| 159 | _echo_error "Error: Non-cros build of ${board} failed." |
| 160 | exit 1 |
| 161 | fi |
| 162 | |
| 163 | # CrOS build |
| 164 | if [[ ${NO_CROS} -eq 0 ]]; then |
| 165 | rm -rf "./${OUTPUT}" |
| 166 | if ! "${ABUILD}" --exitcode --cpus ${CPUS} --target "${board}" --chromeos; then |
| 167 | _echo_error "Error: CrOS build of ${board} failed." |
| 168 | exit 1 |
| 169 | fi |
| 170 | fi |
| 171 | |
| 172 | done |
| 173 | |
| 174 | echo |
| 175 | echo "Successfully built all boards:" |
| 176 | printf "%s\n" "${MAINBOARDS[@]}" |
| 177 | |
| 178 | } |
| 179 | |
| 180 | main "$@" |