diff --git a/tools/build.sh b/tools/build.sh index 71c57ac5..9716ecc0 100755 --- a/tools/build.sh +++ b/tools/build.sh @@ -142,6 +142,16 @@ x_cargo() { x cargo ${pre_args[@]+"${pre_args[@]}"} "$@" printf '\n' } +retry() { + for i in {1..10}; do + if "$@"; then + return 0 + else + sleep "${i}" + fi + done + "$@" +} bail() { printf >&2 'error: %s\n' "$*" exit 1 @@ -227,12 +237,12 @@ nightly='' if [[ "${rustc_version}" =~ nightly|dev ]]; then nightly=1 if [[ -z "${is_custom_toolchain}" ]]; then - rustup ${pre_args[@]+"${pre_args[@]}"} component add rust-src &>/dev/null + retry rustup ${pre_args[@]+"${pre_args[@]}"} component add rust-src &>/dev/null fi # We only run clippy on the recent nightly to avoid old clippy bugs. if [[ "${rustc_minor_version}" -ge 80 ]] && [[ -n "${TESTS:-}" ]] && [[ -z "${TARGET_GROUP:-}" ]]; then subcmd=clippy - rustup ${pre_args[@]+"${pre_args[@]}"} component add clippy &>/dev/null + retry rustup ${pre_args[@]+"${pre_args[@]}"} component add clippy &>/dev/null base_args=(hack "${subcmd}") fi fi @@ -268,7 +278,7 @@ build() { local cfgs if grep -Eq "^${target}$" <<<"${rustup_target_list}"; then cfgs=$(RUSTC_BOOTSTRAP=1 rustc ${pre_args[@]+"${pre_args[@]}"} --print cfg "${target_flags[@]}") - rustup ${pre_args[@]+"${pre_args[@]}"} target add "${target}" &>/dev/null + retry rustup ${pre_args[@]+"${pre_args[@]}"} target add "${target}" &>/dev/null elif [[ -n "${nightly}" ]]; then # -Z build-std requires 1.39.0-nightly: https://github.com/rust-lang/cargo/pull/7216 if [[ "${rustc_minor_version}" -lt 39 ]]; then diff --git a/tools/no-std.sh b/tools/no-std.sh index ff5e3154..4d2d8ee1 100755 --- a/tools/no-std.sh +++ b/tools/no-std.sh @@ -56,6 +56,16 @@ x_cargo() { x cargo "$@" printf '\n' } +retry() { + for i in {1..10}; do + if "$@"; then + return 0 + else + sleep "${i}" + fi + done + "$@" +} bail() { printf >&2 'error: %s\n' "$*" exit 1 @@ -93,7 +103,7 @@ nightly='' if [[ "${rustc_version}" =~ nightly|dev ]]; then nightly=1 if [[ -z "${is_custom_toolchain}" ]]; then - rustup ${pre_args[@]+"${pre_args[@]}"} component add rust-src &>/dev/null + retry rustup ${pre_args[@]+"${pre_args[@]}"} component add rust-src &>/dev/null fi fi export QEMU_AUDIO_DRV=none @@ -144,7 +154,7 @@ run() { esac args+=("${subcmd}" "${target_flags[@]}") if grep -Eq "^${target}$" <<<"${rustup_target_list}"; then - rustup ${pre_args[@]+"${pre_args[@]}"} target add "${target}" &>/dev/null + retry rustup ${pre_args[@]+"${pre_args[@]}"} target add "${target}" &>/dev/null elif [[ -n "${nightly}" ]]; then args+=(-Z build-std="core") else diff --git a/tools/no_atomic.sh b/tools/no_atomic.sh index ac2278fd..f7a4c80d 100755 --- a/tools/no_atomic.sh +++ b/tools/no_atomic.sh @@ -11,6 +11,16 @@ cd -- "$(dirname -- "$0")"/.. # USAGE: # ./tools/no_atomic.sh +retry() { + for i in {1..10}; do + if "$@"; then + return 0 + else + sleep "${i}" + fi + done + "$@" +} bail() { printf >&2 'error: %s\n' "$*" exit 1 @@ -21,7 +31,7 @@ file=no_atomic.rs # We don't refer to NO_ATOMIC_CAS and NO_ATOMIC_64 in nightly-2022-02-11+ # because feature(cfg_target_has_atomic) stabilized. So, we get the list # as of nightly-2022-02-10. -rustup toolchain add nightly-2022-02-10 --profile minimal --no-self-update &>/dev/null +retry rustup toolchain add nightly-2022-02-10 --profile minimal --no-self-update &>/dev/null no_atomic_cas=() no_atomic_64=() diff --git a/tools/test.sh b/tools/test.sh index 3b4cdbed..a7b52369 100755 --- a/tools/test.sh +++ b/tools/test.sh @@ -53,6 +53,16 @@ x_cargo() { fi printf '\n' } +retry() { + for i in {1..10}; do + if "$@"; then + return 0 + else + sleep "${i}" + fi + done + "$@" +} bail() { printf >&2 'error: %s\n' "$*" exit 1 @@ -135,7 +145,7 @@ nightly='' if [[ "${rustc_version}" =~ nightly|dev ]]; then nightly=1 if type -P rustup >/dev/null; then - rustup ${pre_args[@]+"${pre_args[@]}"} component add rust-src &>/dev/null + retry rustup ${pre_args[@]+"${pre_args[@]}"} component add rust-src &>/dev/null fi fi export RUST_TEST_THREADS=1 @@ -164,7 +174,7 @@ if [[ -n "${target}" ]]; then args+=("${target_flags[@]}") if type -P rustup >/dev/null; then if grep -Eq "^${target}$" <<<"${rustup_target_list}"; then - rustup ${pre_args[@]+"${pre_args[@]}"} target add "${target}" &>/dev/null + retry rustup ${pre_args[@]+"${pre_args[@]}"} target add "${target}" &>/dev/null elif [[ -n "${nightly}" ]]; then if [[ ${#build_std[@]} -eq 0 ]]; then build_std=(-Z build-std) @@ -191,7 +201,7 @@ randomize_layout=' -Z randomize-layout' cranelift='' if [[ "${RUSTFLAGS:-}" =~ -Z( )?codegen-backend=cranelift ]]; then cranelift=1 - rustup ${pre_args[@]+"${pre_args[@]}"} component add rustc-codegen-cranelift-preview &>/dev/null + retry rustup ${pre_args[@]+"${pre_args[@]}"} component add rustc-codegen-cranelift-preview &>/dev/null else case "$(basename -- "${cargo%.exe}")" in cargo-clif) cranelift=1 ;; @@ -219,7 +229,7 @@ case "${cmd}" in exit 0 ;; miri) - rustup ${pre_args[@]+"${pre_args[@]}"} component add miri &>/dev/null + retry rustup ${pre_args[@]+"${pre_args[@]}"} component add miri &>/dev/null export MIRIFLAGS="${MIRIFLAGS:-} -Zmiri-strict-provenance -Zmiri-symbolic-alignment-check -Zmiri-disable-isolation" export RUSTFLAGS="${RUSTFLAGS:-}${randomize_layout}" export RUSTDOCFLAGS="${RUSTDOCFLAGS:-}${randomize_layout}" diff --git a/tools/tidy.sh b/tools/tidy.sh index 87bf5f9f..a3f77c49 100755 --- a/tools/tidy.sh +++ b/tools/tidy.sh @@ -53,6 +53,16 @@ check_install() { fi done } +retry() { + for i in {1..10}; do + if "$@"; then + return 0 + else + sleep "${i}" + fi + done + "$@" +} error() { if [[ -n "${GITHUB_ACTIONS:-}" ]]; then printf '::error::%s\n' "$*" @@ -191,12 +201,14 @@ if [[ -n "$(ls_files '*.rs')" ]]; then rustc_version=$(rustc -vV | grep -E '^release:' | cut -d' ' -f2) if [[ "${rustc_version}" =~ nightly|dev ]] || ! type -P rustup >/dev/null; then if type -P rustup >/dev/null; then - rustup component add rustfmt &>/dev/null + retry rustup component add rustfmt &>/dev/null fi info "running \`rustfmt \$(git ls-files '*.rs')\`" rustfmt $(ls_files '*.rs') else - rustup component add rustfmt --toolchain nightly &>/dev/null || true + if type -P rustup >/dev/null; then + retry rustup component add rustfmt --toolchain nightly &>/dev/null + fi info "running \`rustfmt +nightly \$(git ls-files '*.rs')\`" rustfmt +nightly $(ls_files '*.rs') fi