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