From 2b74990741bf0882200a7083c590ee067217f646 Mon Sep 17 00:00:00 2001 From: Ben Stoltz Date: Mon, 4 Mar 2024 13:31:18 -0800 Subject: [PATCH 1/2] Add a scripts directory and add the "build-all" script. --- scripts/README.md | 20 ++++++++ scripts/build-all | 119 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+) create mode 100644 scripts/README.md create mode 100755 scripts/build-all diff --git a/scripts/README.md b/scripts/README.md new file mode 100644 index 000000000..523c67e5c --- /dev/null +++ b/scripts/README.md @@ -0,0 +1,20 @@ +# Scripts + +Scripts to aid in Hubris development. + +## build-all + +Build using all supported app.toml files. +The "unsupported" app.toml files are those that are broken and should be +fixed but do not currently impact our production work. + +``` + Usage: build-all [options] [args] + -c # Continue to next app.toml on build errors + -h # Help (this message) + -n # No action, just list app.toml files to process. + -r # Remove previous log files (rebuild everything) + -u # Attempt to build including unsupported app.toml files + Run "cargo xtask $args app.toml" for every available app.toml + $args defaults to "dist" +``` diff --git a/scripts/build-all b/scripts/build-all new file mode 100755 index 000000000..4ed50c41f --- /dev/null +++ b/scripts/build-all @@ -0,0 +1,119 @@ +#!/bin/bash +set -u +PROG="${0##*/}" + +usage() { + ec="${1:?Missing exit code}" + shift + msg="${*:-}" + shift + if (( ec != 0 )) + then + exec 1>&2 + fi + [[ -n "$msg" ]] && echo "$msg" + echo "Usage: $PROG [options] [args]" + echo ' -c # Continue to next app.toml on build errors' + echo ' -h # Help (this message)' + echo ' -n # No action, just list app.toml files to process.' + echo ' -r # Remove previous log files (rebuild everything)' + echo ' -u # Attempt to build including unsupported app.toml files' + echo 'Run "cargo xtask $args app.toml" for every available app.toml' + echo '$args defaults to "dist"' + exit "${ec}" +} + +fatal() { + msg="${*:-error}" + printf "Fatal: %s\n" "${msg}" 1>&2 + exit 1 +} + +[[ "$(head -n1 README.mkdn 2>/dev/null)" == "# Hubris" ]] || usage 1 "Not in a Hubris repo" + +STOP_ON_ERROR=true +NOOP=false +REMOVE_PREV_LOG=false +SKIP_UNSUPPORTED=true + +while getopts "chnru" opt; do + case $opt in + c) STOP_ON_ERROR=false;; + h) usage 0;; + n) NOOP=true;; + r) REMOVE_PREV_LOG=true;; + u) SKIP_UNSUPPORTED=false;; + ?) usage 1 "Invalid option";; + esac +done +shift $((OPTIND-1)) + +if [[ $# -gt 0 ]] +then + xtask_args=( "$@" ) +else + xtask_args=( dist ) +fi + +# Wall of shame: App.toml files in our repo that fail. +declare -A -g SUPPORTED +if $SKIP_UNSUPPORTED +then + SUPPORTED["app/oxcon2023g0/app.toml"]=false + SUPPORTED["app/demo-stm32g0-nucleo/app-g031.toml"]=false + SUPPORTED["app/gimletlet/app-mgmt.toml"]=false +fi + +included() { + path="${1:?Missing path to app.toml file}" + case "${path}" in + */base*.toml | */dev.toml | */lab.toml ) false;; + *) "${SUPPORTED["${path}"]:-true}";; + esac +} + +# Create a list of all the app.toml type files with our preferred files at the front. +# Don't mind the duplicates, they are weeded out with an associative array later. +mapfile -t ORDERED < <( +# Gimletlet and RoT carrier are first as the usual developer testbed. +echo app/rot-carrier/app.toml +echo app/gimletlet/app.toml +# Next, the images used for the testbeds attached to lurch. +echo app/oxide-rot-1/app-dev.toml +echo app/gimlet/rev-c-lab.toml +echo app/sidecar/rev-b-lab.toml +echo app/psc/rev-b-dev.toml +# Everything except 'Cargo.toml'. +find "app" -name '*.toml' ! -name Cargo.toml | sort +) + +declare -A -g SEEN + +for APP in "${ORDERED[@]}" +do + if [[ -z "${SEEN["${APP}"]:-}" ]] + then + SEEN["${APP}"]=1 + included "${APP}" || continue + LOG=xtask-"$(basename "$(dirname "${APP}")")_$(basename "${APP}" .toml).log" + [[ -f "${LOG}.ok" ]] && ! $REMOVE_PREV_LOG && continue + + printf "Logging %s to %s\n" "${APP}" "${LOG}" + $NOOP && continue + $REMOVE_PREV_LOG && rm -f "${LOG}.ok" "${LOG}" + { + # shellcheck disable=SC2086 + cargo xtask "${xtask_args[@]}" ${APP} + echo APP="${APP}" + } 2>&1 | tee -i "${LOG}" + if ! grep --color=auto -s -w Error "${LOG}"; then + # Green + printf "\033[42m%s\033[m]\n" "${LOG}.ok" + mv "${LOG}" "${LOG}.ok" + else + # Red + printf "\033[41m%s\033[m %s\n" "${LOG}" "${APP}" + $STOP_ON_ERROR && break + fi + fi +done From 4b100591e2142a4e9c09b728d33c1b4ff191980b Mon Sep 17 00:00:00 2001 From: Ben Stoltz Date: Wed, 27 Mar 2024 14:00:03 -0700 Subject: [PATCH 2/2] Add -e flag to build images essential for testing on local gimletlet and lurch-attached systems. --- scripts/build-all | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/scripts/build-all b/scripts/build-all index 4ed50c41f..c3c1d1f39 100755 --- a/scripts/build-all +++ b/scripts/build-all @@ -14,6 +14,7 @@ usage() { [[ -n "$msg" ]] && echo "$msg" echo "Usage: $PROG [options] [args]" echo ' -c # Continue to next app.toml on build errors' + echo ' -e # Just build the app.toml files that are essential for testing' echo ' -h # Help (this message)' echo ' -n # No action, just list app.toml files to process.' echo ' -r # Remove previous log files (rebuild everything)' @@ -35,10 +36,12 @@ STOP_ON_ERROR=true NOOP=false REMOVE_PREV_LOG=false SKIP_UNSUPPORTED=true +ESSENTIAL=false -while getopts "chnru" opt; do +while getopts "chenru" opt; do case $opt in c) STOP_ON_ERROR=false;; + e) ESSENTIAL=true;; h) usage 0;; n) NOOP=true;; r) REMOVE_PREV_LOG=true;; @@ -84,7 +87,10 @@ echo app/gimlet/rev-c-lab.toml echo app/sidecar/rev-b-lab.toml echo app/psc/rev-b-dev.toml # Everything except 'Cargo.toml'. -find "app" -name '*.toml' ! -name Cargo.toml | sort +if ! $ESSENTIAL +then + find "app" -name '*.toml' ! -name Cargo.toml | sort +fi ) declare -A -g SEEN