Skip to content

Commit 5862f09

Browse files
authored
ci: speed up checkers (#12872)
1 parent d71c071 commit 5862f09

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

ci/cloudbuild/builds/checkers.sh

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ time {
9191
printf "%-50s" "Running check-include-guards:" >&2
9292
time {
9393
git_files -z -- '*.h' |
94-
xargs -r -0 awk -f "ci/check-include-guards.gawk"
94+
xargs -r -P "$(nproc)" -n 50 -0 awk -f "ci/check-include-guards.gawk"
9595
}
9696

9797
# TODO(#4501) - this fixup can be removed if #include <absl/...> works
@@ -103,8 +103,7 @@ time {
103103
printf "%-50s" "Running Abseil header fixes:" >&2
104104
time {
105105
expressions=("-e" "'s;#include \"absl/strings/str_\(cat\|replace\|join\).h\";#include \"google/cloud/internal/absl_str_\1_quiet.h\";'")
106-
git_files -z -- '*.h' '*.cc' |
107-
(grep -zv 'google/cloud/internal/absl_.*quiet.h$' || true) |
106+
(git grep -zEl '#include "absl/strings/str_(cat|replace|join).h"' -- '*.h' '*.cc' ':!google/cloud/internal/absl_str_*quiet.h' || true) |
108107
xargs -r -P "$(nproc)" -n 50 -0 bash -c "sed_edit ${expressions[*]} \"\$0\" \"\$@\""
109108
}
110109

@@ -115,10 +114,13 @@ time {
115114
# `grpc::` namespace do not exist inside google.
116115
printf "%-50s" "Running include fixes:" >&2
117116
time {
118-
expressions=("-e" "'s/grpc::\([A-Z][A-Z_]\+\)/grpc::StatusCode::\1/g'")
119117
expressions+=("-e" "'s;#include <grpc++/grpc++.h>;#include <grpcpp/grpcpp.h>;'")
118+
(git grep -zEl 'grpc::([A-Z][A-Z_]+)' -- '*.h' '*.cc' || true) |
119+
xargs -r -P "$(nproc)" -n 50 -0 bash -c "sed_edit ${expressions[*]} \"\$0\" \"\$@\""
120+
121+
expression=("-e" "'s;#include <grpc++/grpc++.h>;#include <grpcpp/grpcpp.h>;'")
120122
expressions+=("-e" "'s;#include <grpc++/;#include <grpcpp/;'")
121-
git_files -z -- '*.h' '*.cc' |
123+
(git grep -zl '#include <grpc++/' -- '*.h' '*.cc' || true) |
122124
xargs -r -P "$(nproc)" -n 50 -0 bash -c "sed_edit ${expressions[*]} \"\$0\" \"\$@\""
123125
}
124126

@@ -145,27 +147,27 @@ time {
145147
printf "%-50s" "Running buildifier:" >&2
146148
time {
147149
git_files -z -- '*.BUILD' '*.bzl' '*.bazel' |
148-
xargs -r -0 buildifier -mode=fix
150+
xargs -r -P "$(nproc)" -n 50 -0 buildifier -mode=fix
149151
}
150152

151153
# Apply psf/black to format Python files.
152154
# https://pypi.org/project/black/
153155
printf "%-50s" "Running black:" >&2
154156
time {
155-
git_files -z -- '*.py' | xargs -r -0 python3 -m black --quiet
157+
git_files -z -- '*.py' | xargs -r -P "$(nproc)" -n 50 -0 python3 -m black --quiet
156158
}
157159

158160
# Apply shfmt to format all shell scripts
159161
printf "%-50s" "Running shfmt:" >&2
160162
time {
161-
git_files -z -- '*.sh' | xargs -r -0 shfmt -w
163+
git_files -z -- '*.sh' | xargs -r -P "$(nproc)" -n 50 -0 shfmt -w
162164
}
163165

164166
# Apply shellcheck(1) to emit warnings for common scripting mistakes.
165167
printf "%-50s" "Running shellcheck:" >&2
166168
time {
167169
git_files -z -- '*.sh' |
168-
xargs -r -P "$(nproc)" -n 1 -0 shellcheck \
170+
xargs -r -P "$(nproc)" -n 50 -0 shellcheck \
169171
--exclude=SC1090 \
170172
--exclude=SC1091 \
171173
--exclude=SC2034 \
@@ -178,15 +180,15 @@ time {
178180
printf "%-50s" "Running clang-format:" >&2
179181
time {
180182
git_files -z -- '*.h' '*.cc' '*.proto' |
181-
xargs -r -P "$(nproc)" -n 1 -0 clang-format -i
183+
xargs -r -P "$(nproc)" -n 50 -0 clang-format -i
182184
}
183185

184186
# Apply cmake_format to all the CMake list files.
185187
# https://github.com/cheshirekow/cmake_format
186188
printf "%-50s" "Running cmake-format:" >&2
187189
time {
188190
git_files -z -- 'CMakeLists.txt' '**/CMakeLists.txt' '*.cmake' |
189-
xargs -r -P "$(nproc)" -n 1 -0 cmake-format -i
191+
xargs -r -P "$(nproc)" -n 50 -0 cmake-format -i
190192
}
191193

192194
# The markdown generators run last. This is useful because as part of the
@@ -214,7 +216,7 @@ time {
214216
printf "%-50s" "Running markdown formatter:" >&2
215217
time {
216218
# See `.mdformat.toml` for the configuration parameters.
217-
git_files -z -- '*.md' | xargs -r -P "$(nproc)" -n 1 -0 mdformat
219+
git_files -z -- '*.md' | xargs -r -P "$(nproc)" -n 50 -0 mdformat
218220
git_files -z -- '*.md' | xargs -r -0 chmod go=u-w
219221
}
220222

ci/cloudbuild/builds/generate-libraries.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ if [ -z "${GENERATE_GOLDEN_ONLY}" ]; then
5757

5858
io::log_h2 "Formatting generated protos"
5959
git ls-files -z -- '*.proto' |
60-
xargs -P "$(nproc)" -n 1 -0 clang-format -i
60+
xargs -P "$(nproc)" -n 50 -0 clang-format -i
6161
else
6262
io::log_red "Skipping update of protos generated from discovery docs."
6363
fi
@@ -81,19 +81,19 @@ if [ -z "${GENERATE_GOLDEN_ONLY}" ]; then
8181
# so we don't need this extra step.
8282
io::log_h2 "Formatting generated code"
8383
git ls-files -z -- '*.h' '*.cc' '*.proto' |
84-
xargs -P "$(nproc)" -n 1 -0 clang-format -i
84+
xargs -P "$(nproc)" -n 50 -0 clang-format -i
8585
git ls-files -z -- '*.h' '*.cc' '*.proto' |
8686
xargs -r -P "$(nproc)" -n 50 -0 sed -i 's/[[:blank:]]\+$//'
8787
# TODO(#12621): Remove this second execution of clang-format when this issue
8888
# is resolved.
8989
git ls-files -z -- 'google/cloud/compute/firewall_policies/v1/internal/firewall_policies_rest_connection_impl.cc' |
90-
xargs -P "$(nproc)" -n 1 -0 clang-format -i
90+
xargs -P "$(nproc)" -n 50 -0 clang-format -i
9191
else
9292
io::log_red "Only formatting generated golden code."
9393
git ls-files -z -- 'generator/integration_tests/golden/**/*.h' \
9494
'generator/integration_tests/golden/v1/**/*.cc' \
9595
'generator/integration_tests/*.proto' |
96-
xargs -P "$(nproc)" -n 1 -0 clang-format -i
96+
xargs -P "$(nproc)" -n 50 -0 clang-format -i
9797
git ls-files -z -- 'generator/integration_tests/golden/**/*.h' \
9898
'generator/integration_tests/golden/v1/**/*.cc' \
9999
'generator/integration_tests/*.proto' |

0 commit comments

Comments
 (0)