1
0

fmt 777 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env python3
  2. # Copyright 2022 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. # Run `rustfmt` on all Rust code contained in the crosvm workspace, including
  6. # all commmon/* crates as well.
  7. #
  8. # Usage:
  9. #
  10. # $ tools/fmt
  11. #
  12. # To print a diff and exit 1 if code is not formatted, but without changing any
  13. # files, use:
  14. #
  15. # $ tools/fmt --check
  16. #
  17. from pathlib import Path
  18. import sys
  19. from impl.common import (
  20. CROSVM_ROOT,
  21. run_main,
  22. cmd,
  23. chdir,
  24. )
  25. def main(check: bool = False):
  26. chdir(CROSVM_ROOT)
  27. cmd(
  28. Path(sys.executable),
  29. "./tools/presubmit format",
  30. "--fix" if not check else None,
  31. ).fg()
  32. if __name__ == "__main__":
  33. run_main(main)