2019-04-12 22:45:32 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2019-06-05 22:43:43 +00:00
|
|
|
# Copyright 2019 The Chromium OS Authors. All rights reserved.
|
|
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
|
|
# found in the LICENSE file.
|
|
|
|
|
2019-04-12 22:45:32 +00:00
|
|
|
# Run `cargo clippy` on all Rust code in crosvm with a mindful set of lints
|
|
|
|
# suppressed.
|
|
|
|
|
2020-07-28 17:15:32 +00:00
|
|
|
set -eo pipefail
|
2019-04-12 22:45:32 +00:00
|
|
|
|
2020-07-14 12:50:02 +00:00
|
|
|
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
|
|
|
|
|
2019-04-12 22:45:32 +00:00
|
|
|
# Change into directory of script, which is crosvm/bin.
|
|
|
|
cd "$(dirname "${BASH_SOURCE[0]}")"
|
|
|
|
|
|
|
|
# Jump up to root directory of crosvm repo.
|
|
|
|
cd ..
|
|
|
|
|
|
|
|
SUPPRESS=(
|
2020-04-10 12:43:45 +00:00
|
|
|
# TODO(crbug/908640): To be resolved.
|
|
|
|
borrowed_box
|
|
|
|
char_lit_as_u8
|
|
|
|
clone_on_copy
|
|
|
|
collapsible_if
|
|
|
|
comparison_chain
|
|
|
|
extra_unused_lifetimes
|
|
|
|
for_kv_map
|
|
|
|
inefficient_to_string
|
|
|
|
into_iter_on_ref
|
2019-04-12 22:45:32 +00:00
|
|
|
let_unit_value
|
2020-04-10 12:43:45 +00:00
|
|
|
missing_safety_doc
|
|
|
|
needless_range_loop
|
|
|
|
needless_return
|
|
|
|
option_map_unit_fn
|
2019-04-12 22:45:32 +00:00
|
|
|
question_mark
|
|
|
|
range_plus_one
|
2020-04-10 12:43:45 +00:00
|
|
|
redundant_clone
|
|
|
|
redundant_closure
|
|
|
|
single_match
|
|
|
|
slow_vector_initialization
|
|
|
|
unnecessary_filter_map
|
|
|
|
unnecessary_mut_passed
|
|
|
|
unneeded_field_pattern
|
|
|
|
useless_format
|
|
|
|
wrong_self_convention
|
2019-04-12 22:45:32 +00:00
|
|
|
|
|
|
|
# We don't care about these lints. Okay to remain suppressed globally.
|
|
|
|
blacklisted_name
|
|
|
|
cast_lossless
|
2019-05-31 01:31:02 +00:00
|
|
|
cognitive_complexity
|
2019-04-12 22:45:32 +00:00
|
|
|
enum_variant_names
|
|
|
|
identity_op
|
|
|
|
len_without_is_empty
|
|
|
|
len_zero
|
|
|
|
match_bool
|
|
|
|
match_wild_err_arm
|
|
|
|
module_inception
|
|
|
|
needless_bool
|
|
|
|
new_without_default
|
|
|
|
or_fun_call
|
|
|
|
should_implement_trait
|
|
|
|
single_char_pattern
|
|
|
|
too_many_arguments
|
|
|
|
transmute_ptr_to_ptr
|
|
|
|
trivially_copy_pass_by_ref
|
|
|
|
type_complexity
|
|
|
|
unreadable_literal
|
|
|
|
useless_let_if_seq
|
|
|
|
useless_transmute
|
|
|
|
)
|
|
|
|
|
|
|
|
# Needed or else clippy won't re-run on code that has already compiled.
|
2020-07-14 12:50:02 +00:00
|
|
|
if [[ "${USE_CACHE}" == false ]]; then
|
|
|
|
cargo clean
|
|
|
|
fi
|
2019-04-12 22:45:32 +00:00
|
|
|
|
2020-04-15 18:41:50 +00:00
|
|
|
# Need to set pass --sysroot for cargo-clippy manually.
|
|
|
|
# cf. https://github.com/rust-lang/rust-clippy/issues/3523
|
|
|
|
RUST_SYSROOT=$(rustc --print sysroot)
|
|
|
|
RUSTFLAGS="${RUSTFLAGS:-}"
|
|
|
|
export RUSTFLAGS="$RUSTFLAGS --sysroot=$RUST_SYSROOT"
|
|
|
|
|
2020-07-14 12:50:02 +00:00
|
|
|
cargo clippy --all-features --all-targets -- ${SUPPRESS[@]/#/-Aclippy::} \
|
|
|
|
"${CLIPPY_ARGS[@]}" -D warnings
|