blob: 57ce64f6ad2247097d68db9948e683ea7b376831 [file] [log] [blame]
Brian Silverman4e278082022-05-19 22:47:41 -07001#!/bin/bash
2
3# --- begin runfiles.bash initialization v2 ---
4# Copy-pasted from the Bazel Bash runfiles library v2.
5set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash
6source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
7 source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
8 source "$0.runfiles/$f" 2>/dev/null || \
9 source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
10 source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
11 { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
12# --- end runfiles.bash initialization v2 ---
13
14readonly RUSTFMT="$(rlocation rust/bin/rustfmt)"
15
16# Run everything from the root of the tree.
17cd "${BUILD_WORKSPACE_DIRECTORY}"
18
19# Find all the Rust files in the repo.
20rust_files=($(git ls-tree --name-only --full-tree -r @ \
21 | grep -v '^third_party/' \
22 | (grep '\.rs$' || :)))
23
24# If we have any Rust files, format them.
25if ((${#rust_files[@]} > 0)); then
26 exec "${RUSTFMT}" "${rust_files[@]}"
27fi