# Sourced by the dev-*.sh scripts that build before they run. # # These scripts run the tests first because a dev loop should not start a # server that does not work. That is the wrong trade when the point is to have # something up now — a demo, a screenshot, a second stack alongside one already # proven — and on a busy machine the test run is most of the wait. # # `--no-test` builds and starts without it. Nothing is skipped silently: the # banner says which of the two happened. # Reads the build flags out of a script's arguments. # # Sets DIDBOT_TESTS and DIDBOT_ARGV rather than returning them, because a # function cannot rewrite its caller's positional arguments. Callers do: # # read_build_flags "$@" # set -- "${DIDBOT_ARGV[@]}" # # before anything else reads them, so the flag reaches neither the watch loop # nor the binary at the end. read_build_flags() { DIDBOT_TESTS=1 DIDBOT_ARGV=() local arg for arg in "$@"; do case "$arg" in --no-test) DIDBOT_TESTS=0 ;; *) DIDBOT_ARGV+=("$arg") ;; esac done } # Builds what is about to run, testing it first unless told not to. # # Takes the cargo selection to build, such as `-p didbot-swarm`. The build is # not left to `cargo run`: these scripts print a banner saying the thing is up, # and a banner that prints before a cold compile is a lie for as long as the # compile takes. build_before_running() { if [ "${DIDBOT_TESTS:-1}" = 1 ]; then printf '\033[1m%s\033[0m\n' "building" cargo test --quiet "$@" else printf '\033[1m%s\033[0m\n' "building (--no-test, so nothing is checked)" cargo build --quiet "$@" fi }