Philipp Schrader | e3a69d9 | 2023-07-05 20:54:16 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # --- begin runfiles.bash initialization v2 --- |
| 4 | # Copy-pasted from the Bazel Bash runfiles library v2. |
| 5 | set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash |
| 6 | source "${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 | |
| 14 | readonly CLANG_FORMAT="$(rlocation llvm_k8/bin/clang-format)" |
| 15 | |
| 16 | # Run everything from the root of the tree. |
| 17 | cd "${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 Schrader | 790cb54 | 2023-07-05 21:06:52 -0700 | [diff] [blame^] | 22 | # Also exclude the pistol grip vtables. Those are likely auto-generated and |
| 23 | # shouldn't be auto-formatted too. |
Philipp Schrader | e3a69d9 | 2023-07-05 20:54:16 -0700 | [diff] [blame] | 24 | cc_files=($(git ls-tree --name-only --full-tree -r @ \ |
| 25 | | grep -v -e '^third_party/' \ |
Philipp Schrader | 790cb54 | 2023-07-05 21:06:52 -0700 | [diff] [blame^] | 26 | -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 Schrader | e3a69d9 | 2023-07-05 20:54:16 -0700 | [diff] [blame] | 34 | |
| 35 | # If we have any C/C++ files, format them. |
| 36 | if ((${#cc_files[@]} > 0)); then |
| 37 | exec "${CLANG_FORMAT}" -i "${cc_files[@]}" |
| 38 | fi |