Skip to content

Commit

Permalink
Merge pull request #23269 from rockwotj/clang-fmt
Browse files Browse the repository at this point in the history
bazel: add clang-format command
  • Loading branch information
rockwotj authored Sep 13, 2024
2 parents 249e02c + d6ff9cb commit 915b229
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tools/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,14 @@ py_binary(
"@python_deps//pyyaml",
],
)

sh_binary(
name = "clang_format",
srcs = ["clang_format.sh"],
args = [
"$(rootpath @llvm_18_toolchain//:clang-format)",
],
data = [
"@llvm_18_toolchain//:clang-format",
],
)
10 changes: 10 additions & 0 deletions tools/clang_format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

clang_format=$(readlink -f $1)
# See: https://bazel.build/docs/user-manual#running-executables
root_dir=$BUILD_WORKSPACE_DIRECTORY
working_dir=$BUILD_WORKING_DIRECTORY

pushd "$working_dir"
git ls-files --full-name "*.cc" "*.java" "*.h" "*.proto" | xargs -n1 "$clang_format" -i -style=file -fallback-style=none
popd

0 comments on commit 915b229

Please sign in to comment.