mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-06 02:25:23 +00:00
ba4adc0efb
This change adds python type and formatting checks and consolidates code health checks in ./tools/health-check. Dealing with relative imports in python is tricky, so we are making ./tools/impl a proper package with no directly executable files. Some of the bash shorthands in ./tools had to be converted to python for this. To make the new checks pass, we run the formatter and fix some mypy type checks. TEST=./tools/health-check BUG=b:218559722,b:219965702 Change-Id: Ie18d3d6dd2f5a033141e167a6e1aa762791941d6 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3558592 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Dennis Kempin <denniskempin@google.com>
57 lines
1.4 KiB
Python
Executable file
57 lines
1.4 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,
|
|
find_scripts,
|
|
parallel,
|
|
run_main,
|
|
cmd,
|
|
chdir,
|
|
find_source_files,
|
|
)
|
|
from pathlib import Path
|
|
|
|
mdformat = cmd("mdformat")
|
|
rustfmt = cmd(cmd("rustup which rustfmt"))
|
|
black = cmd("black", "--line-length 100")
|
|
|
|
# How many files to check at once in each thread.
|
|
BATCH_SIZE = 8
|
|
|
|
|
|
def main(check: bool = False):
|
|
chdir(CROSVM_ROOT)
|
|
check_arg = "--check" if check else None
|
|
|
|
print(f"{'Checking format' if check else 'Formatting'}: Rust, Markdown")
|
|
parallel(
|
|
*rustfmt(check_arg).foreach(find_source_files("rs"), batch_size=BATCH_SIZE),
|
|
*mdformat("--wrap 100", check_arg).foreach(find_source_files("md"), batch_size=BATCH_SIZE),
|
|
*black(check_arg).foreach(
|
|
(
|
|
*find_source_files("py"),
|
|
*find_scripts(Path("tools"), "/usr/bin/env python3"),
|
|
),
|
|
batch_size=BATCH_SIZE,
|
|
),
|
|
).fg()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
run_main(main)
|