clippy 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. # To check for violations:
  6. # $ ./tools/clippy
  7. #
  8. # To fix violations where possible:
  9. # $ ./tools/clippy --fix
  10. from typing import Optional
  11. from impl.common import CROSVM_ROOT, run_main, cmd, chdir, Triple, SHORTHANDS
  12. from impl.test_config import DO_NOT_BUILD_RISCV64
  13. clippy = cmd("cargo clippy").with_color_flag()
  14. def main(
  15. fix: bool = False,
  16. json: bool = False,
  17. locked: bool = False,
  18. platform: Optional[str] = None,
  19. ):
  20. try:
  21. triple: Triple = Triple.from_shorthand(platform) if platform else Triple.host_default()
  22. except Exception as e:
  23. raise type(e)(str(e) + f"\nValid platforms are {', '.join(SHORTHANDS.keys())}")
  24. chdir(CROSVM_ROOT)
  25. # Note: Clippy checks are configured in .cargo/config.toml
  26. args = [
  27. "--message-format=json" if json else None,
  28. "--locked" if locked else None,
  29. "--all-targets",
  30. "--",
  31. "-Dwarnings",
  32. ]
  33. if fix:
  34. args = [
  35. "--fix",
  36. "--allow-no-vcs",
  37. "--allow-dirty",
  38. "--allow-staged",
  39. *args,
  40. ]
  41. # For experimental builds, don't clippy the whole workspace, just what's enabled by features.
  42. if triple in (Triple.from_shorthand("riscv64"), Triple.from_shorthand("android")):
  43. args = ["--no-default-features", *args]
  44. else:
  45. args = ["--workspace", *args]
  46. print("Clippy crosvm workspace")
  47. clippy(
  48. f"--features={triple.feature_flag}",
  49. *args,
  50. ).with_envs(triple.get_cargo_env()).fg()
  51. if __name__ == "__main__":
  52. run_main(main)