1#!/bin/bash 2 3# Copyright 2019 The Chromium OS Authors. All rights reserved. 4# Use of this source code is governed by a BSD-style license that can be 5# found in the LICENSE file. 6 7# Run `cargo clippy` on all Rust code in crosvm with a mindful set of lints 8# suppressed. 9 10set -eo pipefail 11 12USE_CACHE=false 13CLIPPY_ARGS=("$@") 14 15# TODO: When we add more options, use a fancier parsing mechanism such as 16# getopts. Also use the Rust convention of -- separating the arguments for this 17# script itself from the ones for clippy. 18if (("$#" > 0)) && [[ "$1" == "--use-cache" ]]; then 19 USE_CACHE=true 20 CLIPPY_ARGS=("${CLIPPY_ARGS[@]:1}") 21fi 22 23# Change into directory of script, which is crosvm/bin. 24cd "$(dirname "${BASH_SOURCE[0]}")" 25 26# Jump up to root directory of crosvm repo. 27cd .. 28 29SUPPRESS=( 30 # TODO(crbug/908640): To be resolved. 31 borrowed_box 32 char_lit_as_u8 33 clone_on_copy 34 collapsible_if 35 comparison_chain 36 extra_unused_lifetimes 37 for_kv_map 38 inefficient_to_string 39 into_iter_on_ref 40 let_unit_value 41 missing_safety_doc 42 needless_range_loop 43 needless_return 44 option_map_unit_fn 45 question_mark 46 range_plus_one 47 redundant_clone 48 redundant_closure 49 single_match 50 slow_vector_initialization 51 unnecessary_filter_map 52 unnecessary_mut_passed 53 unneeded_field_pattern 54 useless_format 55 wrong_self_convention 56 57 # False positives affecting WlVfd @ `devices/src/virtio/wl.rs`. 58 # Bug: https://github.com/rust-lang/rust-clippy/issues/6312 59 field_reassign_with_default 60 61 # We don't care about these lints. Okay to remain suppressed globally. 62 blacklisted_name 63 cast_lossless 64 cognitive_complexity 65 enum_variant_names 66 identity_op 67 len_without_is_empty 68 len_zero 69 match_bool 70 match_wild_err_arm 71 module_inception 72 needless_bool 73 new_without_default 74 or_fun_call 75 should_implement_trait 76 single_char_pattern 77 too_many_arguments 78 transmute_ptr_to_ptr 79 trivially_copy_pass_by_ref 80 type_complexity 81 unreadable_literal 82 useless_let_if_seq 83 useless_transmute 84 new-ret-no-self 85) 86 87# Needed or else clippy won't re-run on code that has already compiled. 88if [[ "${USE_CACHE}" == false ]]; then 89 cargo clean 90fi 91 92# Need to set pass --sysroot for cargo-clippy manually. 93# cf. https://github.com/rust-lang/rust-clippy/issues/3523 94RUST_SYSROOT=$(rustc --print sysroot) 95RUSTFLAGS="${RUSTFLAGS:-}" 96export RUSTFLAGS="$RUSTFLAGS --sysroot=$RUST_SYSROOT" 97 98cargo clippy --all-features --all-targets -- ${SUPPRESS[@]/#/-Aclippy::} \ 99 "${CLIPPY_ARGS[@]}" -D warnings 100