• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# Copyright 2019 The Chromium OS Authors. All rights reserved.
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
12import os
13import sys
14
15sys.path.append(os.path.join(sys.path[0], "impl"))
16from impl.common import CROSVM_ROOT, cwd, run_main, cmd, chdir
17from impl.test_runner import get_workspace_excludes
18
19clippy = cmd("cargo clippy")
20
21
22if os.name == "posix":
23    EXCLUDED_CRATES: list[str] = []
24    EXCLUDED_CRATES_ARGS: list[str] = []
25    FEATURES: str = "--features=all-linux"
26
27elif os.name == "nt":
28    EXCLUDED_CRATES: list[str] = list(get_workspace_excludes("win64"))
29    EXCLUDED_CRATES_ARGS: list[str] = [f"--exclude={crate}" for crate in EXCLUDED_CRATES]
30    FEATURES: str = ""
31
32else:
33    raise Exception(f"Unsupported build target: {os.name}")
34
35
36def is_crate_excluded(crate: str) -> bool:
37    return crate in EXCLUDED_CRATES
38
39
40def main(fix: bool = False):
41    chdir(CROSVM_ROOT)
42
43    # Note: Clippy checks are configured in .cargo/config.toml
44    common_args = [
45        "--fix" if fix else None,
46        "--all-targets",
47        "--",
48        "-Dwarnings",
49    ]
50    print("Clippy crosvm workspace")
51    clippy("--workspace", FEATURES, *EXCLUDED_CRATES_ARGS, *common_args).fg()
52
53    for crate in CROSVM_ROOT.glob("common/*/Cargo.toml"):
54        if not is_crate_excluded(crate.parent.name):
55            print("Clippy", crate.parent.relative_to(CROSVM_ROOT))
56            with cwd(crate.parent):
57                clippy("--all-features", *common_args).fg()
58        else:
59            print("Skipping crate", crate.parent.relative_to(CROSVM_ROOT))
60
61
62run_main(main)
63