@@ -28,9 +28,6 @@ readonly BINDIR="$(dirname $0)"
2828find google/cloud -name ' *.h' -print0 \
2929 | xargs -0 awk -f ${BINDIR} /check-include-guards.gawk
3030
31- find google/cloud -name ' *.h' -o -name ' *.cc' -print0 \
32- | xargs -0 sed -i ' s/grpc::\([A-Z][A-Z_][A-Z_]*\)/grpc::StatusCode::\1/g'
33-
3431# Apply cmake_format to all the CMake list files.
3532# https://github.com/cheshirekow/cmake_format
3633find . \( -path ./.git \
@@ -52,26 +49,33 @@ find . \( -path ./.git -prune -o -path ./third_party -prune \
5249 -o \( -name ' *.cc' -o -name ' *.h' \) -print0 \
5350 | xargs -0 clang-format -i
5451
52+ # Apply several transformations that cannot be enforced by clang-format:
53+ # - Replace any #include for grpc++/* with grpcpp/*. The paths with grpc++
54+ # are obsoleted by the gRPC team, so we should not use them in our code.
55+ # - Replace grpc::<BLAH> with grpc::StatusCode::<BLAH>, the aliases in the
56+ # `grpc::` namespace do not exist inside google.
57+ for file in $( find google/cloud -name ' *.h' -o -name ' *.cc' -print) ; do
58+ # We used to run run `sed -i` to apply these changes, but that touches the
59+ # files even if there are no changes applied, forcing a rebuild each time.
60+ # So we first apply the change to a temporary file, and replace the original
61+ # only if something changed.
62+ sed -e ' s/grpc::\([A-Z][A-Z_][A-Z_]*\)/grpc::StatusCode::\1/g' \
63+ -e ' s;#include <grpc\\+\\+/grpc\+\+.h>;#include <grpcpp/grpcpp.h>;' \
64+ -e ' s;#include <grpc\\+\\+/;#include <grpcpp/;' \
65+ " ${file} " > " ${file} .tmp"
66+ if cmp " ${file} " " ${file} .tmp" ; then
67+ rm -f " ${file} .tmp"
68+ else
69+ mv -f " ${file} .tmp" " ${file} "
70+ fi
71+ done
72+
5573# Apply buildifier to fix the BUILD and .bzl formatting rules.
5674# https://github.com/bazelbuild/buildtools/tree/master/buildifier
5775find . \( -path ./.git -prune -o -path ./third_party -prune \
5876 -o -path ' ./cmake-build-*' -o -path ./build-output -prune \) \
5977 -o \( -name BUILD -o -name ' *.bzl' \) -print0 \
6078 | xargs -0 buildifier -mode=fix
6179
62- # Replace any #include for grpc++/grpc++.h with grpcpp/grpcpp.h, and in general,
63- # any include of grpc++/ files with grpcpp/. The paths with grpc++ are
64- # obsoleted by the gRPC team, so we should not use them in our code.
65- find . \( -path ./.git -prune -o -path ./third_party -prune \
66- -o -path ' ./cmake-build-*' -o -path ./build-output -prune \
67- -o -name ' *.pb.h' -prune -o -name ' *.pb.cc' -prune \) \
68- -o \( -name ' *.cc' -o -name ' *.h' \) -print0 \
69- | xargs -0 sed -i ' s;#include <grpc\\+\\+/grpc\+\+.h>;#include <grpcpp/grpcpp.h>;'
70- find . \( -path ./.git -prune -o -path ./third_party -prune \
71- -o -path ' ./cmake-build-*' -o -path ./build-output -prune \
72- -o -name ' *.pb.h' -prune -o -name ' *.pb.cc' -prune \) \
73- -o \( -name ' *.cc' -o -name ' *.h' \) -print0 \
74- | xargs -0 sed -i ' s;#include <grpc\\+\\+/;#include <grpcpp/;'
75-
7680# Report any differences created by running clang-format.
7781git diff --ignore-submodules=all --color --exit-code .
0 commit comments