From d8106ab5520a7c4f2ffc92295c0ff1daaf583260 Mon Sep 17 00:00:00 2001 From: Ryo Onodera Date: Fri, 3 Jul 2020 18:08:12 +0900 Subject: [PATCH] Make test-checks.sh helpful and cargo-for-all-lock-files.sh useful (#10906) --- ci/test-checks.sh | 5 +++-- scripts/cargo-for-all-lock-files.sh | 21 ++++++++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/ci/test-checks.sh b/ci/test-checks.sh index 5403e42e2c..9ba43ecd48 100755 --- a/ci/test-checks.sh +++ b/ci/test-checks.sh @@ -36,8 +36,9 @@ if [[ $CI_BASE_BRANCH = "$EDGE_CHANNEL" ]]; then true else check_status=$? - echo "Some Cargo.lock might be outdated; update them (or just be a compilation error?)" - echo "protip: you can use ./scripts/cargo-for-all-lock-files.sh [check|update] ..." + echo "$0: Some Cargo.lock might be outdated; sync them (or just be a compilation error?)" >&2 + echo "$0: protip: $ ./scripts/cargo-for-all-lock-files.sh [--ignore-exit-code] ... \\" >&2 + echo "$0: [tree (for outdated Cargo.lock sync)|check (for compilation error)|update -p foo --precise x.y.z (for your Cargo.toml update)] ..." >&2 exit "$check_status" fi else diff --git a/scripts/cargo-for-all-lock-files.sh b/scripts/cargo-for-all-lock-files.sh index 8de7bccb86..52aa5c5bbf 100755 --- a/scripts/cargo-for-all-lock-files.sh +++ b/scripts/cargo-for-all-lock-files.sh @@ -8,6 +8,9 @@ while [[ -n $1 ]]; do escape_marker=found shift break + elif [[ $1 = "--ignore-exit-code" ]]; then + ignore=1 + shift else shifted_args+=("$1") shift @@ -33,9 +36,17 @@ for lock_file in $files; do if [[ -n $CI ]]; then echo "--- [$lock_file]: cargo " "${shifted_args[@]}" "$@" fi - ( - set -x - cd "$(dirname "$lock_file")" - cargo "${shifted_args[@]}" "$@" - ) + + if (set -x && cd "$(dirname "$lock_file")" && cargo "${shifted_args[@]}" "$@"); then + # noop + true + else + failed_exit_code=$? + if [[ -n $ignore ]]; then + echo "$0: WARN: ignoring last cargo command failed exit code as requested:" $failed_exit_code + true + else + exit $failed_exit_code + fi + fi done