diff --git a/bin/clippy b/bin/clippy index ce9f015e05..a75dec34e5 100755 --- a/bin/clippy +++ b/bin/clippy @@ -9,6 +9,17 @@ set -euo pipefail +USE_CACHE=false +CLIPPY_ARGS=( "$@" ) + +# TODO: When we add more options, use a fancier parsing mechanism such as +# getopts. Also use the Rust convention of -- separating the arguments for this +# script itself from the ones for clippy. +if (( "$#" > 0 )) && [[ "$1" == "--use-cache" ]]; then + USE_CACHE=true + CLIPPY_ARGS=( "${CLIPPY_ARGS[@]:1}" ) +fi + # Change into directory of script, which is crosvm/bin. cd "$(dirname "${BASH_SOURCE[0]}")" @@ -69,7 +80,9 @@ SUPPRESS=( ) # Needed or else clippy won't re-run on code that has already compiled. -cargo clean +if [[ "${USE_CACHE}" == false ]]; then + cargo clean +fi # Need to set pass --sysroot for cargo-clippy manually. # cf. https://github.com/rust-lang/rust-clippy/issues/3523 @@ -77,5 +90,5 @@ RUST_SYSROOT=$(rustc --print sysroot) RUSTFLAGS="${RUSTFLAGS:-}" export RUSTFLAGS="$RUSTFLAGS --sysroot=$RUST_SYSROOT" -cargo clippy --all-features --all-targets -- ${SUPPRESS[@]/#/-Aclippy::} "$@" \ - -D warnings +cargo clippy --all-features --all-targets -- ${SUPPRESS[@]/#/-Aclippy::} \ + "${CLIPPY_ARGS[@]}" -D warnings