summary refs log tree commit diff
path: root/bin/fmt
blob: b1bf5fec639f1d4eb2014aae035bec4a0e268246 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env bash

# Copyright 2019 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 crosvm. This is different from
# `cargo fmt --all` which formats multiple crates but a single workspace only.
# Crosvm consists of multiple workspaces.
#
# Usage:
#
#    $ bin/fmt
#
# To print a diff and exit 1 if code is not formatted, but without changing any
# files, use:
#
#    $ bin/fmt --check
#

set -euo pipefail

# Change into directory of script, which is crosvm/bin.
cd "$(dirname "${BASH_SOURCE[0]}")"

# Jump up to root directory of crosvm repo.
cd ..

find . -name '*.rs' -print0 | grep -vz '^./target/' | xargs -0 rustfmt --edition=2018 "$@" --