2022-02-14 20:47:01 +00:00
|
|
|
#!/usr/bin/env python3
|
2022-09-13 17:55:17 +00:00
|
|
|
# Copyright 2019 The ChromiumOS Authors
|
2021-10-15 01:56:44 +00:00
|
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
|
|
# found in the LICENSE file.
|
|
|
|
|
2021-11-12 17:35:42 +00:00
|
|
|
# To check for violations:
|
|
|
|
# $ ./tools/clippy
|
|
|
|
#
|
|
|
|
# To fix violations where possible:
|
|
|
|
# $ ./tools/clippy --fix
|
|
|
|
|
2022-03-25 20:44:28 +00:00
|
|
|
import os
|
2022-02-14 20:47:01 +00:00
|
|
|
from impl.common import CROSVM_ROOT, cwd, run_main, cmd, chdir
|
2022-03-25 20:44:28 +00:00
|
|
|
from impl.test_runner import get_workspace_excludes
|
2022-06-30 00:56:04 +00:00
|
|
|
from impl.test_target import Triple
|
2022-02-14 20:47:01 +00:00
|
|
|
|
2022-09-07 17:52:15 +00:00
|
|
|
clippy = cmd("cargo clippy").with_color_flag()
|
2022-02-14 20:47:01 +00:00
|
|
|
|
2022-08-22 07:12:58 +00:00
|
|
|
excluded_crates: list[str] = list(get_workspace_excludes(Triple.host_default()))
|
2022-03-22 20:04:31 +00:00
|
|
|
features: str = ""
|
2022-02-14 20:47:01 +00:00
|
|
|
|
2022-03-25 20:44:28 +00:00
|
|
|
if os.name == "posix":
|
2022-03-22 20:04:31 +00:00
|
|
|
features = "--features=all-linux"
|
2022-08-22 07:12:58 +00:00
|
|
|
elif os.name != "nt":
|
2022-03-25 20:44:28 +00:00
|
|
|
raise Exception(f"Unsupported build target: {os.name}")
|
|
|
|
|
|
|
|
|
|
|
|
def is_crate_excluded(crate: str) -> bool:
|
2022-03-22 20:04:31 +00:00
|
|
|
return crate in excluded_crates
|
2022-03-25 20:44:28 +00:00
|
|
|
|
|
|
|
|
2022-08-04 18:09:31 +00:00
|
|
|
def main(fix: bool = False, json: bool = False, locked: bool = False):
|
2022-02-14 20:47:01 +00:00
|
|
|
chdir(CROSVM_ROOT)
|
|
|
|
|
|
|
|
# Note: Clippy checks are configured in .cargo/config.toml
|
2022-03-25 20:44:28 +00:00
|
|
|
common_args = [
|
2022-02-14 20:47:01 +00:00
|
|
|
"--fix" if fix else None,
|
2022-05-05 16:56:47 +00:00
|
|
|
"--message-format=json" if json else None,
|
2022-08-04 18:09:31 +00:00
|
|
|
"--locked" if locked else None,
|
2022-02-14 20:47:01 +00:00
|
|
|
"--all-targets",
|
|
|
|
"--",
|
|
|
|
"-Dwarnings",
|
|
|
|
]
|
|
|
|
print("Clippy crosvm workspace")
|
2022-03-22 20:04:31 +00:00
|
|
|
clippy(
|
|
|
|
"--workspace",
|
|
|
|
features,
|
|
|
|
*[f"--exclude={crate}" for crate in excluded_crates],
|
|
|
|
*common_args,
|
|
|
|
).fg()
|
2022-02-14 20:47:01 +00:00
|
|
|
|
|
|
|
for crate in CROSVM_ROOT.glob("common/*/Cargo.toml"):
|
2022-04-15 18:14:40 +00:00
|
|
|
# TODO(b/213147081): remove the cros_async exclude this once
|
|
|
|
# common/cros_async is gone.
|
|
|
|
if is_crate_excluded(crate.parent.name) or (
|
|
|
|
os.name == "nt" and crate.parent.name == "cros_async"
|
|
|
|
):
|
|
|
|
print("Skipping crate", crate.parent.relative_to(CROSVM_ROOT))
|
|
|
|
else:
|
2022-03-25 20:44:28 +00:00
|
|
|
print("Clippy", crate.parent.relative_to(CROSVM_ROOT))
|
|
|
|
with cwd(crate.parent):
|
|
|
|
clippy("--all-features", *common_args).fg()
|
2022-02-14 20:47:01 +00:00
|
|
|
|
|
|
|
|
2022-03-22 20:04:31 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
run_main(main)
|