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# $ bin/fmt 12# 13# To print a diff and exit 1 if code is not formatted, but without changing any 14# files, use: 15# 16# $ bin/fmt --check 17# 18 19from impl.common import ( 20 CROSVM_ROOT, 21 run_main, 22 cmd, 23 chdir, 24) 25 26 27def main(check: bool = False, nightly: bool = False): 28 chdir(CROSVM_ROOT) 29 cmd( 30 "./tools/presubmit format", 31 "--fix" if not check else None, 32 "--nightly-fmt" if nightly else None, 33 ).fg() 34 35 36if __name__ == "__main__": 37 run_main(main) 38