• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
14
15clippy = cmd("cargo clippy").with_color_flag()
16
17
18def main(
19    fix: bool = False,
20    json: bool = False,
21    locked: bool = False,
22    platform: Optional[str] = None,
23):
24    try:
25        triple: Triple = Triple.from_shorthand(platform) if platform else Triple.host_default()
26    except Exception as e:
27        raise type(e)(str(e) + f"\nValid platforms are {', '.join(SHORTHANDS.keys())}")
28
29    chdir(CROSVM_ROOT)
30
31    # Note: Clippy checks are configured in .cargo/config.toml
32    common_args = [
33        "--message-format=json" if json else None,
34        "--locked" if locked else None,
35        "--all-targets",
36        "--",
37        "-Dwarnings",
38    ]
39    if fix:
40        common_args = [
41            "--fix",
42            "--allow-no-vcs",
43            "--allow-dirty",
44            "--allow-staged",
45            *common_args,
46        ]
47    print("Clippy crosvm workspace")
48    clippy(
49        "--workspace",
50        f"--features={triple.feature_flag}",
51        *common_args,
52    ).with_envs(triple.get_cargo_env()).fg()
53
54
55if __name__ == "__main__":
56    run_main(main)
57