From 59a18de777622bccd8be5afce1248cfbfd32f607 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 18 Nov 2024 15:47:15 -0500 Subject: [PATCH 1/3] ci: Set `-u` (error on unset) in all script files This is a pretty common flag to reduce errors. Make use of it here. --- ci/android-install-ndk.sh | 2 +- ci/android-install-sdk.sh | 2 +- ci/android-sysimage.sh | 2 +- ci/build.sh | 2 +- ci/docker/wasm32-unknown-emscripten/node-wrapper.sh | 2 +- ci/emscripten-entry.sh | 2 +- ci/emscripten.sh | 2 +- ci/install-musl.sh | 2 +- ci/install-rust.sh | 2 +- ci/linux-s390x.sh | 2 +- ci/linux-sparc64.sh | 2 +- ci/run-docker.sh | 2 +- ci/run.sh | 2 +- ci/style.sh | 2 +- ci/test-runner-linux | 2 +- ci/wasi.sh | 2 +- 16 files changed, 16 insertions(+), 16 deletions(-) diff --git a/ci/android-install-ndk.sh b/ci/android-install-ndk.sh index eb666e2db5da1..546917b5f8d53 100644 --- a/ci/android-install-ndk.sh +++ b/ci/android-install-ndk.sh @@ -1,6 +1,6 @@ #!/usr/bin/env sh -set -ex +set -eux ndk=android-ndk-r27 wget --tries=20 -q "https://dl.google.com/android/repository/${ndk}-linux.zip" diff --git a/ci/android-install-sdk.sh b/ci/android-install-sdk.sh index b7f2b8e1443fc..331e061357648 100644 --- a/ci/android-install-sdk.sh +++ b/ci/android-install-sdk.sh @@ -1,6 +1,6 @@ #!/usr/bin/env sh -set -ex +set -eux # Prep the SDK and emulator # diff --git a/ci/android-sysimage.sh b/ci/android-sysimage.sh index b49712035cf33..98484b3521f60 100644 --- a/ci/android-sysimage.sh +++ b/ci/android-sysimage.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -ex +set -eux URL=https://dl.google.com/android/repository/sys-img/android diff --git a/ci/build.sh b/ci/build.sh index ea549c30c9d0c..f2a56445c7690 100644 --- a/ci/build.sh +++ b/ci/build.sh @@ -5,7 +5,7 @@ # The FILTER environment variable can be used to select which target(s) to build. # For example: set FILTER to vxworks to select the targets that has vxworks in name -set -ex +set -eux : "${TOOLCHAIN?The TOOLCHAIN environment variable must be set.}" : "${OS?The OS environment variable must be set.}" diff --git a/ci/docker/wasm32-unknown-emscripten/node-wrapper.sh b/ci/docker/wasm32-unknown-emscripten/node-wrapper.sh index 369439269a683..0fd93dc49d9c8 100755 --- a/ci/docker/wasm32-unknown-emscripten/node-wrapper.sh +++ b/ci/docker/wasm32-unknown-emscripten/node-wrapper.sh @@ -1,6 +1,6 @@ #!/bin/sh -set -e +set -eux me="$1" shift diff --git a/ci/emscripten-entry.sh b/ci/emscripten-entry.sh index e950cbe33ab06..344c347b75a72 100755 --- a/ci/emscripten-entry.sh +++ b/ci/emscripten-entry.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -ex +set -eux # shellcheck disable=SC1091 source /emsdk-portable/emsdk_env.sh &> /dev/null diff --git a/ci/emscripten.sh b/ci/emscripten.sh index b17a40c1a287d..0a4112e7e205e 100644 --- a/ci/emscripten.sh +++ b/ci/emscripten.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -ex +set -eux # Note: keep in sync with: # https://github.com/rust-lang/rust/blob/master/src/ci/docker/scripts/emscripten.sh diff --git a/ci/install-musl.sh b/ci/install-musl.sh index fae46ee928c9f..5f8c681fa6678 100644 --- a/ci/install-musl.sh +++ b/ci/install-musl.sh @@ -3,7 +3,7 @@ # Install musl and musl-sanitized linux kernel headers # to musl-{$1} directory -set -ex +set -eux musl_version=1.1.24 musl="musl-${musl_version}" diff --git a/ci/install-rust.sh b/ci/install-rust.sh index a0b841807b106..0438ee4f9f6fe 100644 --- a/ci/install-rust.sh +++ b/ci/install-rust.sh @@ -1,7 +1,7 @@ #!/usr/bin/env sh # This is intended to be used in CI only. -set -ex +set -eux echo "Setup toolchain" toolchain= diff --git a/ci/linux-s390x.sh b/ci/linux-s390x.sh index 63d29b5beb597..5c89e90b11906 100644 --- a/ci/linux-s390x.sh +++ b/ci/linux-s390x.sh @@ -1,6 +1,6 @@ #!/usr/bin/env sh -set -ex +set -eux mkdir -m 777 /qemu cd /qemu diff --git a/ci/linux-sparc64.sh b/ci/linux-sparc64.sh index a42218a62ead0..d81ed104277a9 100644 --- a/ci/linux-sparc64.sh +++ b/ci/linux-sparc64.sh @@ -1,6 +1,6 @@ #!/usr/bin/env sh -set -ex +set -eux mkdir -m 777 /qemu cd /qemu diff --git a/ci/run-docker.sh b/ci/run-docker.sh index a812ee7ab183a..a4a34be6b4f4a 100755 --- a/ci/run-docker.sh +++ b/ci/run-docker.sh @@ -6,7 +6,7 @@ # Small script to run tests for a target (or all targets) inside all the # respective docker images. -set -ex +set -eux # Default to assuming the CARGO_HOME is one directory up (to account for a `bin` # subdir) from where the `cargo` binary in `$PATH` lives. diff --git a/ci/run.sh b/ci/run.sh index e01dd3c14a574..caf4eb4333281 100755 --- a/ci/run.sh +++ b/ci/run.sh @@ -3,7 +3,7 @@ # Builds and runs tests for a particular target passed as an argument to this # script. -set -ex +set -eux mirrors_url="https://ci-mirrors.rust-lang.org/libc" diff --git a/ci/style.sh b/ci/style.sh index 0684caafaad7d..1ed8e51e658b5 100755 --- a/ci/style.sh +++ b/ci/style.sh @@ -1,6 +1,6 @@ #!/bin/sh -set -ex +set -eux rustc ci/style.rs && ./style src diff --git a/ci/test-runner-linux b/ci/test-runner-linux index 9ab029b0a7df2..55f84da1700f7 100755 --- a/ci/test-runner-linux +++ b/ci/test-runner-linux @@ -1,6 +1,6 @@ #!/bin/sh -set -e +set -eux arch="$1" prog="$2" diff --git a/ci/wasi.sh b/ci/wasi.sh index 1b72d356fac06..e7896233ad7f3 100644 --- a/ci/wasi.sh +++ b/ci/wasi.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -ex +set -eux apt-get update apt-get install -y --no-install-recommends \ From f3bb382ba5344e4dd400b6875a42d769ab9af74f Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 18 Nov 2024 15:51:05 -0500 Subject: [PATCH 2/3] ci: Fix cases where unset variables cause errors --- ci/install-rust.sh | 21 +++++++++------------ ci/run.sh | 2 +- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/ci/install-rust.sh b/ci/install-rust.sh index 0438ee4f9f6fe..becb532d1469d 100644 --- a/ci/install-rust.sh +++ b/ci/install-rust.sh @@ -4,14 +4,11 @@ set -eux echo "Setup toolchain" -toolchain= -if [ -n "$TOOLCHAIN" ]; then - toolchain=$TOOLCHAIN -else - toolchain=nightly -fi -if [ "$OS" = "windows" ]; then +toolchain="${TOOLCHAIN:-nightly}" +os="${OS:-}" + +if [ "$os" = "windows" ]; then : "${TARGET?The TARGET environment variable must be set.}" rustup set profile minimal rustup update --force "$toolchain-$TARGET" @@ -22,18 +19,18 @@ else rustup default "$toolchain" fi -if [ -n "$TARGET" ]; then +if [ -n "${TARGET:-}" ]; then echo "Install target" rustup target add "$TARGET" fi -if [ -n "$INSTALL_RUST_SRC" ]; then +if [ -n "${INSTALL_RUST_SRC:-}" ]; then echo "Install rust-src" rustup component add rust-src fi -if [ "$OS" = "windows" ]; then - if [ "$ARCH_BITS" = "i686" ]; then +if [ "$os" = "windows" ]; then + if [ "${ARCH_BITS:-}" = "i686" ]; then echo "Install MinGW32" choco install mingw --x86 --force fi @@ -44,7 +41,7 @@ if [ "$OS" = "windows" ]; then /usr/bin/find "C:\ProgramData\Chocolatey" -name "dllcrt2*" /usr/bin/find "C:\ProgramData\Chocolatey" -name "libmsvcrt*" - if [ -n "$ARCH_BITS" ]; then + if [ -n "${ARCH_BITS:-}" ]; then echo "Fix MinGW" for i in crt2.o dllcrt2.o libmingwex.a libmsvcrt.a ; do cp -f "/C/ProgramData/Chocolatey/lib/mingw/tools/install/mingw$ARCH_BITS/$ARCH-w64-mingw32/lib/$i" "$(rustc --print sysroot)/lib/rustlib/$TARGET/lib" diff --git a/ci/run.sh b/ci/run.sh index caf4eb4333281..f4fef82fcdc2d 100755 --- a/ci/run.sh +++ b/ci/run.sh @@ -15,7 +15,7 @@ target="$1" # # It's assume that all images, when run with two disks, will run the `run.sh` # script from the second which we place inside. -if [ "$QEMU" != "" ]; then +if [ -n "${QEMU:-}" ]; then tmpdir=/tmp/qemu-img-creation mkdir -p "${tmpdir}" From 331dd50ef6976778ea73535a953d111fa438caee Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 18 Nov 2024 16:00:51 -0500 Subject: [PATCH 3/3] ci: fix indentation in one more place --- ci/run-docker.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ci/run-docker.sh b/ci/run-docker.sh index a4a34be6b4f4a..4cef3d45c504d 100755 --- a/ci/run-docker.sh +++ b/ci/run-docker.sh @@ -89,13 +89,13 @@ build_switch() { } if [ -z "${1}" ]; then - for d in ci/docker/*; do - run "${d}" - done + for d in ci/docker/*; do + run "${d}" + done else - if [ "${1}" != "switch" ]; then - run "${1}" - else - build_switch - fi + if [ "${1}" != "switch" ]; then + run "${1}" + else + build_switch + fi fi