Skip to content

Commit 68d2da5

Browse files
committed
ci: Extract repetitive code to a function
(backport <#4179>) (cherry picked from commit cde5e54)
1 parent 1645df8 commit 68d2da5

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

ci/verify-build.sh

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ fi
3030

3131
# Run the tests for a specific target
3232
test_target() {
33-
target="${1}"
34-
no_dist="${2:-0}"
33+
target="$1"
34+
no_dist="$2"
3535

3636
RUSTFLAGS="${RUSTFLAGS:-}"
3737

@@ -269,7 +269,13 @@ case "$rust" in
269269
*) supports_wasi_pn=0 ;;
270270
esac
271271

272-
for target in $targets; do
272+
some_tests_run=0
273+
274+
# Apply the `FILTER` variable, do OS-specific tasks, and run a target
275+
filter_and_run() {
276+
target="$1"
277+
no_dist="${2:-0}"
278+
273279
if echo "$target" | grep -q "$filter"; then
274280
if [ "$os" = "windows" ]; then
275281
TARGET="$target" ./ci/install-rust.sh
@@ -282,27 +288,24 @@ for target in $targets; do
282288

283289
# `wasm32-wasip2` only exists in recent versions of Rust
284290
if [ "$target" = "wasm32-wasip2" ] && [ "$supports_wasi_pn" = "0" ]; then
285-
continue
291+
return
286292
fi
287293

288-
test_target "$target"
289-
test_run=1
294+
test_target "$target" "$no_dist"
295+
some_tests_run=1
290296
fi
297+
}
298+
299+
for target in $targets; do
300+
filter_and_run "$target"
291301
done
292302

293303
for target in ${no_dist_targets:-}; do
294-
if echo "$target" | grep -q "$filter"; then
295-
if [ "$os" = "windows" ]; then
296-
TARGET="$target" ./ci/install-rust.sh
297-
fi
298-
299-
test_target "$target" 1
300-
test_run=1
301-
fi
304+
filter_and_run "$target" 1
302305
done
303306

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

0 commit comments

Comments
 (0)