Skip to content

Commit

Permalink
tools: Retry on rustup failure
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Sep 22, 2024
1 parent 47f6fba commit 85b92f0
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 12 deletions.
16 changes: 13 additions & 3 deletions tools/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions tools/no-std.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion tools/no_atomic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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=()
Expand Down
18 changes: 14 additions & 4 deletions tools/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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 ;;
Expand Down Expand Up @@ -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}"
Expand Down
16 changes: 14 additions & 2 deletions tools/tidy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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' "$*"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 85b92f0

Please sign in to comment.