|
| 1 | +#!/bin/bash |
| 2 | +set -u |
| 3 | +PROG="${0##*/}" |
| 4 | + |
| 5 | +usage() { |
| 6 | + ec="${1:?Missing exit code}" |
| 7 | + shift |
| 8 | + msg="${*:-}" |
| 9 | + shift |
| 10 | + if (( ec != 0 )) |
| 11 | + then |
| 12 | + exec 1>&2 |
| 13 | + fi |
| 14 | + [[ -n "$msg" ]] && echo "$msg" |
| 15 | + echo "Usage: $PROG [options] [args]" |
| 16 | + echo ' -c # Continue to next app.toml on build errors' |
| 17 | + echo ' -h # Help (this message)' |
| 18 | + echo ' -n # No action, just list app.toml files to process.' |
| 19 | + echo ' -r # Remove previous log files (rebuild everything)' |
| 20 | + echo ' -u # Attempt to build including unsupported app.toml files' |
| 21 | + echo 'Run "cargo xtask $args app.toml" for every available app.toml' |
| 22 | + echo '$args defaults to "dist"' |
| 23 | + exit "${ec}" |
| 24 | +} |
| 25 | + |
| 26 | +fatal() { |
| 27 | + msg="${*:-error}" |
| 28 | + printf "Fatal: %s\n" "${msg}" 1>&2 |
| 29 | + exit 1 |
| 30 | +} |
| 31 | + |
| 32 | +[[ "$(head -n1 README.mkdn 2>/dev/null)" == "# Hubris" ]] || usage 1 "Not in a Hubris repo" |
| 33 | + |
| 34 | +STOP_ON_ERROR=true |
| 35 | +NOOP=false |
| 36 | +REMOVE_PREV_LOG=false |
| 37 | +SKIP_UNSUPPORTED=true |
| 38 | + |
| 39 | +while getopts "chnru" opt; do |
| 40 | + case $opt in |
| 41 | + c) STOP_ON_ERROR=false;; |
| 42 | + h) usage 0;; |
| 43 | + n) NOOP=true;; |
| 44 | + r) REMOVE_PREV_LOG=true;; |
| 45 | + u) SKIP_UNSUPPORTED=false;; |
| 46 | + ?) usage 1 "Invalid option";; |
| 47 | + esac |
| 48 | +done |
| 49 | +shift $((OPTIND-1)) |
| 50 | + |
| 51 | +if [[ $# -gt 0 ]] |
| 52 | +then |
| 53 | + xtask_args=( "$@" ) |
| 54 | +else |
| 55 | + xtask_args=( dist ) |
| 56 | +fi |
| 57 | + |
| 58 | +# Wall of shame: App.toml files in our repo that fail. |
| 59 | +declare -A -g SUPPORTED |
| 60 | +if $SKIP_UNSUPPORTED |
| 61 | +then |
| 62 | + SUPPORTED["app/oxcon2023g0/app.toml"]=false |
| 63 | + SUPPORTED["app/demo-stm32g0-nucleo/app-g031.toml"]=false |
| 64 | + SUPPORTED["app/gimletlet/app-mgmt.toml"]=false |
| 65 | +fi |
| 66 | + |
| 67 | +included() { |
| 68 | + path="${1:?Missing path to app.toml file}" |
| 69 | + case "${path}" in |
| 70 | + */base*.toml | */dev.toml | */lab.toml ) false;; |
| 71 | + *) "${SUPPORTED["${path}"]:-true}";; |
| 72 | + esac |
| 73 | +} |
| 74 | + |
| 75 | +# Create a list of all the app.toml type files with our preferred files at the front. |
| 76 | +# Don't mind the duplicates, they are weeded out with an associative array later. |
| 77 | +mapfile -t ORDERED < <( |
| 78 | +# Gimletlet and RoT carrier are first as the usual developer testbed. |
| 79 | +echo app/rot-carrier/app.toml |
| 80 | +echo app/gimletlet/app.toml |
| 81 | +# Next, the images used for the testbeds attached to lurch. |
| 82 | +echo app/oxide-rot-1/app-dev.toml |
| 83 | +echo app/gimlet/rev-c-lab.toml |
| 84 | +echo app/sidecar/rev-b-lab.toml |
| 85 | +echo app/psc/rev-b-dev.toml |
| 86 | +# Everything except 'Cargo.toml'. |
| 87 | +find "app" -name '*.toml' ! -name Cargo.toml | sort |
| 88 | +) |
| 89 | + |
| 90 | +declare -A -g SEEN |
| 91 | + |
| 92 | +for APP in "${ORDERED[@]}" |
| 93 | +do |
| 94 | + if [[ -z "${SEEN["${APP}"]:-}" ]] |
| 95 | + then |
| 96 | + SEEN["${APP}"]=1 |
| 97 | + included "${APP}" || continue |
| 98 | + LOG=xtask-"$(basename "$(dirname "${APP}")")_$(basename "${APP}" .toml).log" |
| 99 | + [[ -f "${LOG}.ok" ]] && ! $REMOVE_PREV_LOG && continue |
| 100 | + |
| 101 | + printf "Logging %s to %s\n" "${APP}" "${LOG}" |
| 102 | + $NOOP && continue |
| 103 | + $REMOVE_PREV_LOG && rm -f "${LOG}.ok" "${LOG}" |
| 104 | + { |
| 105 | + # shellcheck disable=SC2086 |
| 106 | + cargo xtask "${xtask_args[@]}" ${APP} |
| 107 | + echo APP="${APP}" |
| 108 | + } 2>&1 | tee -i "${LOG}" |
| 109 | + if ! grep --color=auto -s -w Error "${LOG}"; then |
| 110 | + # Green |
| 111 | + printf "\033[42m%s\033[m]\n" "${LOG}.ok" |
| 112 | + mv "${LOG}" "${LOG}.ok" |
| 113 | + else |
| 114 | + # Red |
| 115 | + printf "\033[41m%s\033[m %s\n" "${LOG}" "${APP}" |
| 116 | + $STOP_ON_ERROR && break |
| 117 | + fi |
| 118 | + fi |
| 119 | +done |
0 commit comments