2023-08-14 19:30:13 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
|
|
|
set -euo pipefail
|
|
|
|
IFS=$'\n\t'
|
|
|
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
|
|
|
|
|
|
: ${SHELL:="NO"} # or YES to launch a shell instead of running the test
|
2023-08-14 20:11:28 +00:00
|
|
|
: ${TRACE:="NO"} # or YES to send traces to jaeger
|
|
|
|
: ${BACKTRACE:="NO"} # or YES to print a rust backtrace when panicking
|
2023-08-25 08:25:39 +00:00
|
|
|
: ${NO_COLOR:=""} # Set to anything to disable color output
|
2023-09-20 03:25:49 +00:00
|
|
|
: ${PROFILE:="debug"}
|
2023-08-25 08:25:39 +00:00
|
|
|
|
2023-08-14 19:30:13 +00:00
|
|
|
REALPATH=$(command -v uu-realpath || command -v realpath)
|
|
|
|
MAKE=$(command -v gmake || command -v make)
|
|
|
|
|
2023-09-16 18:06:31 +00:00
|
|
|
############## Setup #########################
|
|
|
|
|
|
|
|
function die {
|
|
|
|
local status_code="$1"
|
|
|
|
shift
|
|
|
|
(>&2 echo "${@}")
|
|
|
|
exit "$status_code"
|
|
|
|
}
|
|
|
|
|
|
|
|
function log {
|
|
|
|
(>&2 echo "${@}")
|
|
|
|
}
|
|
|
|
|
|
|
|
############## Program #########################
|
|
|
|
|
2023-08-14 19:30:13 +00:00
|
|
|
function main {
|
|
|
|
build_container
|
2023-09-02 17:22:49 +00:00
|
|
|
launch_container "${@}"
|
2023-08-14 19:30:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function build_container {
|
|
|
|
$MAKE -C "$DIR/../docker/organic_test"
|
|
|
|
}
|
|
|
|
|
|
|
|
function launch_container {
|
|
|
|
local additional_flags=()
|
2023-08-28 05:18:10 +00:00
|
|
|
local features=(compare)
|
2023-08-14 19:30:13 +00:00
|
|
|
|
2023-08-25 08:25:39 +00:00
|
|
|
if [ "$NO_COLOR" != "" ]; then
|
|
|
|
additional_flags+=(--env "NO_COLOR=$NO_COLOR")
|
|
|
|
fi
|
|
|
|
|
2023-08-14 20:11:28 +00:00
|
|
|
if [ "$TRACE" = "YES" ]; then
|
|
|
|
# We use the host network so it can talk to jaeger hosted at 127.0.0.1
|
|
|
|
additional_flags+=(--network=host --env RUST_LOG=debug)
|
2023-08-28 05:18:10 +00:00
|
|
|
features+=(tracing)
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$SHELL" != "YES" ]; then
|
2023-09-01 01:23:51 +00:00
|
|
|
additional_flags+=(--read-only)
|
2023-08-28 05:18:10 +00:00
|
|
|
else
|
|
|
|
additional_flags+=(-t)
|
2023-08-14 20:11:28 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$BACKTRACE" = "YES" ]; then
|
|
|
|
additional_flags+=(--env RUST_BACKTRACE=full)
|
|
|
|
fi
|
2023-08-14 19:50:05 +00:00
|
|
|
|
2023-09-16 18:06:31 +00:00
|
|
|
if [ "$SHELL" = "YES" ]; then
|
|
|
|
exec docker run "${additional_flags[@]}" --init --rm -i --mount type=tmpfs,destination=/tmp -v "/:/input:ro" -v "$($REALPATH "$DIR/../"):/source:ro" --mount source=cargo-cache,target=/usr/local/cargo/registry --mount source=rust-cache,target=/target --env CARGO_TARGET_DIR=/target -w /source --entrypoint "" organic-test /bin/sh
|
|
|
|
fi
|
|
|
|
|
|
|
|
local features_joined
|
|
|
|
features_joined=$(IFS=","; echo "${features[*]}")
|
|
|
|
|
2023-09-16 18:15:19 +00:00
|
|
|
local build_flags=()
|
|
|
|
if [ "$PROFILE" = "dev" ] || [ "$PROFILE" = "debug" ]; then
|
|
|
|
PROFILE="debug"
|
|
|
|
else
|
|
|
|
build_flags+=(--profile "$PROFILE")
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2023-09-02 17:22:49 +00:00
|
|
|
if [ $# -gt 0 ]; then
|
|
|
|
# If we passed in args, we need to forward them along
|
|
|
|
for path in "${@}"; do
|
2023-09-16 16:51:14 +00:00
|
|
|
local full_path
|
|
|
|
full_path=$($REALPATH "$path")
|
2023-09-16 18:06:31 +00:00
|
|
|
init_script=$(cat <<EOF
|
|
|
|
set -euo pipefail
|
|
|
|
IFS=\$'\n\t'
|
|
|
|
|
2023-09-16 18:15:19 +00:00
|
|
|
cargo build --bin compare --no-default-features --features "$features_joined" ${build_flags[@]}
|
|
|
|
exec /target/${PROFILE}/compare "/input${full_path}"
|
2023-09-16 18:06:31 +00:00
|
|
|
EOF
|
|
|
|
)
|
|
|
|
docker run "${additional_flags[@]}" --init --rm -i --mount type=tmpfs,destination=/tmp -v "/:/input:ro" -v "$($REALPATH "$DIR/../"):/source:ro" --mount source=cargo-cache,target=/usr/local/cargo/registry --mount source=rust-cache,target=/target --env CARGO_TARGET_DIR=/target -w /source --entrypoint "" organic-test sh -c "$init_script"
|
2023-09-02 17:22:49 +00:00
|
|
|
done
|
|
|
|
else
|
2023-09-16 18:06:31 +00:00
|
|
|
local current_directory init_script
|
|
|
|
current_directory=$(pwd)
|
|
|
|
init_script=$(cat <<EOF
|
2023-09-16 17:34:33 +00:00
|
|
|
set -euo pipefail
|
|
|
|
IFS=\$'\n\t'
|
|
|
|
|
2023-09-16 18:15:19 +00:00
|
|
|
cargo build --bin compare --no-default-features --features "$features_joined" ${build_flags[@]}
|
2023-09-16 17:34:33 +00:00
|
|
|
cd /input${current_directory}
|
2023-09-16 18:15:19 +00:00
|
|
|
exec /target/${PROFILE}/compare
|
2023-09-16 17:34:33 +00:00
|
|
|
EOF
|
2023-09-16 18:06:31 +00:00
|
|
|
)
|
2023-09-16 17:34:33 +00:00
|
|
|
|
2023-09-16 18:06:31 +00:00
|
|
|
docker run "${additional_flags[@]}" --init --rm -i --mount type=tmpfs,destination=/tmp -v "/:/input:ro" -v "$($REALPATH "$DIR/../"):/source:ro" --mount source=cargo-cache,target=/usr/local/cargo/registry --mount source=rust-cache,target=/target --env CARGO_TARGET_DIR=/target -w /source --entrypoint "" organic-test sh -c "$init_script"
|
2023-09-02 17:22:49 +00:00
|
|
|
fi
|
2023-08-14 19:30:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
main "${@}"
|