crosvm/tools/fmt
Dennis Kempin 27ecaad405 Pythonify clippy/fmt scripts and add common.py
We are replacing most of our bash tools with python versions so we
can support cross-platform development.

To facilitate writing shell-like scripts in Python, this CL adds
a common.py file to share common utilities. It curretly contains
tools to simplify shell-like command execution and argument parsing.

BUG=b:218559770
TEST=./tools/clippy && ./tools/fmt && ./tools/impl/common.py

Change-Id: I7f8b3523394973ed5c741b926fdc41e52133189f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3461240
Reviewed-by: Maciek Swiech <drmasquatch@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2022-02-15 22:01:58 +00:00

43 lines
1.1 KiB
Python
Executable file

#!/usr/bin/env python3
# Copyright 2022 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.
# Run `rustfmt` on all Rust code contained in the crosvm workspace, including
# all commmon/* crates as well.
#
# Usage:
#
# $ bin/fmt
#
# To print a diff and exit 1 if code is not formatted, but without changing any
# files, use:
#
# $ bin/fmt --check
#
from impl.common import CROSVM_ROOT, cwd, run_main, cmd, chdir
cargo = cmd("cargo")
mdformat = cmd("mdformat")
find = cmd("find")
def main(check: bool = False):
chdir(CROSVM_ROOT)
check_arg = "--check" if check else None
print("Format crosvm workspace")
cargo("fmt --all --", check_arg).fg()
for crate in CROSVM_ROOT.glob("common/*/Cargo.toml"):
print("Format", crate.parent.relative_to(CROSVM_ROOT))
with cwd(crate.parent):
cargo("fmt --", check_arg).fg()
print("Format markdown docs")
mdformat("--wrap 100", check_arg, find(".", "-name *.md -not -path ./third_party/*")).fg()
run_main(main)