1#!/usr/bin/env python3 2# Copyright 2019 The ChromiumOS Authors 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6# To check for violations: 7# $ ./tools/clippy 8# 9# To fix violations where possible: 10# $ ./tools/clippy --fix 11 12from typing import Optional 13from impl.common import CROSVM_ROOT, run_main, cmd, chdir, Triple, SHORTHANDS 14from impl.test_config import DO_NOT_BUILD_RISCV64 15 16clippy = cmd("cargo clippy").with_color_flag() 17 18 19def main( 20 fix: bool = False, 21 json: bool = False, 22 locked: bool = False, 23 platform: Optional[str] = None, 24): 25 try: 26 triple: Triple = Triple.from_shorthand(platform) if platform else Triple.host_default() 27 except Exception as e: 28 raise type(e)(str(e) + f"\nValid platforms are {', '.join(SHORTHANDS.keys())}") 29 30 chdir(CROSVM_ROOT) 31 32 # Note: Clippy checks are configured in .cargo/config.toml 33 common_args = [ 34 "--message-format=json" if json else None, 35 "--locked" if locked else None, 36 "--all-targets", 37 "--", 38 "-Dwarnings", 39 ] 40 if fix: 41 common_args = [ 42 "--fix", 43 "--allow-no-vcs", 44 "--allow-dirty", 45 "--allow-staged", 46 *common_args, 47 ] 48 print("Clippy crosvm workspace") 49 exclude_args = [] 50 if triple == Triple.from_shorthand("riscv64"): 51 exclude_args = ["--exclude=" + s for s in DO_NOT_BUILD_RISCV64] 52 clippy( 53 "--workspace", 54 f"--features={triple.feature_flag}", 55 *exclude_args, 56 *common_args, 57 ).with_envs(triple.get_cargo_env()).fg() 58 59 60if __name__ == "__main__": 61 run_main(main) 62