crosvm/tools/health-check
Dennis Kempin 784ab4b469 health-check: Add option to run only some checks
The default is still to run all of them, but this will allow us to run
checks in separate luci steps to provide an easier to read result.

BUG=b:233913455
TEST=./tools/health-check python fmt

Change-Id: Iddc803f8f423db36ece53a13acfe564560b789a6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3668812
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-05-26 01:03:59 +00:00

60 lines
1.7 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.
import doctest
import importlib
import argh # type: ignore
import sys
from pathlib import Path
from impl.common import CROSVM_ROOT, run_main, cmd, chdir, parallel, find_scripts
from impl.check_code_hygiene import has_crlf_line_endings
mypy = cmd("mypy --pretty --color-output").env("MYPY_FORCE_COLOR", "1").env("MYPYPATH", "tools")
def check_python():
print("Running python doctests")
for source in Path("tools/impl").glob("*.py"):
lib = importlib.import_module(f"impl.{source.stem}")
result = doctest.testmod(lib, optionflags=doctest.ELLIPSIS)
if result.failed:
sys.exit(1)
print("Type-checking python")
parallel(
mypy("tools/impl"),
*mypy.foreach(find_scripts(Path("tools"), "/usr/bin/env python3")),
).fg()
def check_crlf_line_endings():
crlf_endings = has_crlf_line_endings()
if crlf_endings:
print("Error: Following files have crlf(dos) line encodings")
print(*crlf_endings)
sys.exit(-1)
@argh.arg("checks", choices=["python", "misc", "fmt", "clippy", "all", []])
def main(*checks: str):
chdir(CROSVM_ROOT)
if not checks:
checks = ("all",)
def should_check(name: str):
return "all" in checks or name in checks
if should_check("python"):
check_python()
if should_check("misc"):
check_crlf_line_endings()
if should_check("fmt"):
cmd("./tools/fmt --check").fg()
if should_check("clippy"):
cmd("./tools/clippy").fg()
if __name__ == "__main__":
run_main(main)