2022-02-14 20:47:01 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# Copyright 2022 The Chromium OS Authors. All rights reserved.
|
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-11 23:14:38 +00:00
|
|
|
# Run `rustfmt` on all Rust code contained in the crosvm workspace, including
|
|
|
|
# all commmon/* crates as well.
|
2021-10-15 01:56:44 +00:00
|
|
|
#
|
|
|
|
# Usage:
|
|
|
|
#
|
|
|
|
# $ bin/fmt
|
|
|
|
#
|
|
|
|
# To print a diff and exit 1 if code is not formatted, but without changing any
|
|
|
|
# files, use:
|
|
|
|
#
|
|
|
|
# $ bin/fmt --check
|
|
|
|
#
|
|
|
|
|
2022-02-14 20:47:01 +00:00
|
|
|
from impl.common import CROSVM_ROOT, cwd, run_main, cmd, chdir
|
2021-10-15 01:56:44 +00:00
|
|
|
|
2022-02-14 20:47:01 +00:00
|
|
|
cargo = cmd("cargo")
|
|
|
|
mdformat = cmd("mdformat")
|
|
|
|
find = cmd("find")
|
2021-10-15 01:56:44 +00:00
|
|
|
|
2022-01-25 23:14:43 +00:00
|
|
|
|
2022-02-14 20:47:01 +00:00
|
|
|
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)
|