Skip to content

Commit

Permalink
ci: Extract repetitive code to a function
Browse files Browse the repository at this point in the history
(backport <rust-lang#4179>)
(cherry picked from commit cde5e54)
  • Loading branch information
tgross35 committed Dec 9, 2024
1 parent 1645df8 commit 68d2da5
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions ci/verify-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ fi

# Run the tests for a specific target
test_target() {
target="${1}"
no_dist="${2:-0}"
target="$1"
no_dist="$2"

RUSTFLAGS="${RUSTFLAGS:-}"

Expand Down Expand Up @@ -269,7 +269,13 @@ case "$rust" in
*) supports_wasi_pn=0 ;;
esac

for target in $targets; do
some_tests_run=0

# Apply the `FILTER` variable, do OS-specific tasks, and run a target
filter_and_run() {
target="$1"
no_dist="${2:-0}"

if echo "$target" | grep -q "$filter"; then
if [ "$os" = "windows" ]; then
TARGET="$target" ./ci/install-rust.sh
Expand All @@ -282,27 +288,24 @@ for target in $targets; do

# `wasm32-wasip2` only exists in recent versions of Rust
if [ "$target" = "wasm32-wasip2" ] && [ "$supports_wasi_pn" = "0" ]; then
continue
return
fi

test_target "$target"
test_run=1
test_target "$target" "$no_dist"
some_tests_run=1
fi
}

for target in $targets; do
filter_and_run "$target"
done

for target in ${no_dist_targets:-}; do
if echo "$target" | grep -q "$filter"; then
if [ "$os" = "windows" ]; then
TARGET="$target" ./ci/install-rust.sh
fi

test_target "$target" 1
test_run=1
fi
filter_and_run "$target" 1
done

# Make sure we didn't accidentally filter everything
if [ "${test_run:-}" != 1 ]; then
if [ "$some_tests_run" != 1 ]; then
echo "No tests were run"
exit 1
fi

0 comments on commit 68d2da5

Please sign in to comment.