Skip to content

Commit 5ea52d9

Browse files
thockinjuli4n
authored andcommitted
Add {update/verify}/proto-fmt.sh via clang-format
Next commit runs the tool.
1 parent 86cd169 commit 5ea52d9

2 files changed

Lines changed: 74 additions & 0 deletions

File tree

hack/update/proto-fmt.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2026 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -o errexit -o nounset -o pipefail
18+
19+
ROOT="$(git rev-parse --show-toplevel)"
20+
cd "${ROOT}"
21+
22+
# Find clang-format in the PATH, and exit if not found.
23+
tool="clang-format"
24+
clangfmt="$(which "$tool" 2>/dev/null || true)"
25+
if [[ ! -x "${clangfmt}" ]]; then
26+
echo "Failed to find ${tool}: please make sure it is in your PATH" >&2
27+
exit 1
28+
fi
29+
30+
# Find all top-level directories containing proto files, and run clangfmt on them.
31+
# shellcheck disable=SC2207 # reading array
32+
files=(
33+
$(git ls-files \
34+
-cmo \
35+
--exclude-standard \
36+
-- \
37+
':(glob)**/*.proto' \
38+
':!:vendor/*' \
39+
':!:**/vendor/*' \
40+
':!:LICENSES/*' \
41+
| sort \
42+
| uniq)
43+
)
44+
45+
# Run clang-format on the found files.
46+
#
47+
# Don't reflow long lines, wince those tend to be comments which then require
48+
# re-running the proto generators, which makes "update-all" awkward.
49+
"${clangfmt}" \
50+
-i \
51+
--style="{BasedOnStyle: LLVM, ColumnLimit: 0}" \
52+
"${files[@]}"

hack/verify/proto-fmt.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2026 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -o errexit -o nounset -o pipefail
18+
19+
ROOT="$(git rev-parse --show-toplevel)"
20+
cd "${ROOT}"
21+
22+
./hack/third_party/kubernetes/verify-generated.sh proto-fmt "$@"

0 commit comments

Comments
 (0)