blob: 943274d113f6ccaf3a30843bbac1a7938006a955 [file] [log] [blame]
Philipp Schradere3a69d92023-07-05 20:54:16 -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 CLANG_FORMAT="$(rlocation llvm_k8/bin/clang-format)"
15
16# Run everything from the root of the tree.
17cd "${BUILD_WORKSPACE_DIRECTORY}"
18
19# Find all the C/C++ files in the repo.
20# Exclude third-party code. Both in //third_party and the third-party code
21# checked in to the main repo directly.
Philipp Schrader790cb542023-07-05 21:06:52 -070022# Also exclude the pistol grip vtables. Those are likely auto-generated and
23# shouldn't be auto-formatted too.
Philipp Schradere3a69d92023-07-05 20:54:16 -070024cc_files=($(git ls-tree --name-only --full-tree -r @ \
25 | grep -v -e '^third_party/' \
Philipp Schrader790cb542023-07-05 21:06:52 -070026 -e '^motors/core/kinetis\.h$' \
27 -e '^motors/core/mk20dx128\.*c$' \
28 -e '^motors/core/nonstd\..*$' \
29 -e '^motors/pistol_grip/vtable_.*\.cc$' \
30 -e '^motors/teensy_loader_cli/' \
31 -e '^motors/usb/usb_' \
32 -e '^y2023/vision/rkisp1-config\.h$' \
33 | (grep -e '\.c$' -e '\.cc$' -e '\.h$' || :)))
Philipp Schradere3a69d92023-07-05 20:54:16 -070034
35# If we have any C/C++ files, format them.
36if ((${#cc_files[@]} > 0)); then
37 exec "${CLANG_FORMAT}" -i "${cc_files[@]}"
38fi