crosvm/tools/clippy
Dennis Kempin ba4adc0efb Add python presubmit checks
This change adds python type and formatting checks and
consolidates code health checks in ./tools/health-check.

Dealing with relative imports in python is tricky, so
we are making ./tools/impl a proper package with no
directly executable files.

Some of the bash shorthands in ./tools had to be converted
to python for this.

To make the new checks pass, we run the formatter and fix
some mypy type checks.

TEST=./tools/health-check
BUG=b:218559722,b:219965702

Change-Id: Ie18d3d6dd2f5a033141e167a6e1aa762791941d6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3558592
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2022-04-15 19:22:53 +00:00

61 lines
1.6 KiB
Python
Executable file

#!/usr/bin/env python3
# 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.
# To check for violations:
# $ ./tools/clippy
#
# To fix violations where possible:
# $ ./tools/clippy --fix
import os
from impl.common import CROSVM_ROOT, cwd, run_main, cmd, chdir
from impl.test_runner import get_workspace_excludes
clippy = cmd("cargo clippy")
excluded_crates: list[str] = []
features: str = ""
if os.name == "posix":
features = "--features=all-linux"
elif os.name == "nt":
excluded_crates = list(get_workspace_excludes("win64"))
else:
raise Exception(f"Unsupported build target: {os.name}")
def is_crate_excluded(crate: str) -> bool:
return crate in excluded_crates
def main(fix: bool = False):
chdir(CROSVM_ROOT)
# Note: Clippy checks are configured in .cargo/config.toml
common_args = [
"--fix" if fix else None,
"--all-targets",
"--",
"-Dwarnings",
]
print("Clippy crosvm workspace")
clippy(
"--workspace",
features,
*[f"--exclude={crate}" for crate in excluded_crates],
*common_args,
).fg()
for crate in CROSVM_ROOT.glob("common/*/Cargo.toml"):
if not is_crate_excluded(crate.parent.name):
print("Clippy", crate.parent.relative_to(CROSVM_ROOT))
with cwd(crate.parent):
clippy("--all-features", *common_args).fg()
else:
print("Skipping crate", crate.parent.relative_to(CROSVM_ROOT))
if __name__ == "__main__":
run_main(main)