crosvm/tools/clippy
Dennis Kempin 33d5aa219a Enable clippy for android code
This change enables clippy builds of android specific code.

Doing so without adding the full Android SDK into our container
is a bit hacky. The CL https://crrev.com/c/5671653 adds env variables
to the minijail build.rs to allow us to skip building the library, and
generate bindings for linux instead of android.

This allow us to build all non-gpu related features of the
android build. It will not link, but it will run clippy.

This CL fixes various clippy issues that come up in this new
configuration

BUG=b:349907813
TEST=tools/clippy -p android
TEST=tools/presubmit clippy_android

Change-Id: I1f51d383051bbeeeff55d716feb7b56c3e24588b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5672567
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2024-07-09 20:43:44 +00:00

62 lines
1.7 KiB
Python
Executable file

#!/usr/bin/env python3
# Copyright 2019 The ChromiumOS Authors
# 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
from typing import Optional
from impl.common import CROSVM_ROOT, run_main, cmd, chdir, Triple, SHORTHANDS
from impl.test_config import DO_NOT_BUILD_RISCV64
clippy = cmd("cargo clippy").with_color_flag()
def main(
fix: bool = False,
json: bool = False,
locked: bool = False,
platform: Optional[str] = None,
):
try:
triple: Triple = Triple.from_shorthand(platform) if platform else Triple.host_default()
except Exception as e:
raise type(e)(str(e) + f"\nValid platforms are {', '.join(SHORTHANDS.keys())}")
chdir(CROSVM_ROOT)
# Note: Clippy checks are configured in .cargo/config.toml
args = [
"--message-format=json" if json else None,
"--locked" if locked else None,
"--all-targets",
"--",
"-Dwarnings",
]
if fix:
args = [
"--fix",
"--allow-no-vcs",
"--allow-dirty",
"--allow-staged",
*args,
]
# For experimental builds, don't clippy the whole workspace, just what's enabled by features.
if triple in (Triple.from_shorthand("riscv64"), Triple.from_shorthand("android")):
args = ["--no-default-features", *args]
else:
args = ["--workspace", *args]
print("Clippy crosvm workspace")
clippy(
f"--features={triple.feature_flag}",
*args,
).with_envs(triple.get_cargo_env()).fg()
if __name__ == "__main__":
run_main(main)