Skip to content
This repository was archived by the owner on Dec 8, 2021. It is now read-only.

Commit c26a613

Browse files
authored
cleanup: use same clang-tidy in all repositories (#206)
Use the clang-tidy distributed with Fedora (currently clang-tidy-9) in this repository. I am planning to make similar changes in the other repositories and bring all our `clang-tidy` builds to use the same versions of `clang-format`, `clang-tidy`, `doxygen`, `buildifier`, `shellcheck`, and `cmake_format`. I also updated the clang-tidy configuration to match the newer repos (`-pubsub` and `-spanner`), and cleaned up any errors found in the files. Finally, fixed a number of Doxygen comments that used `<U>` (for a template parameter) which Doxygen thought was an unordered list or something.
1 parent 00175c5 commit c26a613

30 files changed

+404
-308
lines changed

.clang-tidy

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,30 @@
11
---
22
# Configure clang-tidy for this project.
33

4-
# Disabled:
5-
# -google-readability-namespace-comments the *_CLIENT_NS is a macro, and
6-
# clang-tidy fails to match it against the initial value.
4+
# Here is an explanation for why some of the checks are disabled:
5+
#
6+
# -google-readability-namespace-comments: the *_CLIENT_NS is a macro, and
7+
# clang-tidy fails to match it against the initial value.
8+
#
9+
# -modernize-use-trailing-return-type: clang-tidy recommends using
10+
# `auto Foo() -> std::string { return ...; }`, we think the code is less
11+
# readable in this form.
12+
#
13+
# -modernize-return-braced-init-list: We think removing typenames and using
14+
# only braced-init can hurt readability.
15+
#
16+
# -performance-move-const-arg: This warning requires the developer to
17+
# know/care more about the implementation details of types/functions than
18+
# should be necessary. For example, `A a; F(std::move(a));` will trigger a
19+
# warning IFF `A` is a trivial type (and therefore the move is
20+
# meaningless). It would also warn if `F` accepts by `const&`, which is
21+
# another detail that the caller need not care about.
22+
#
23+
# -readability-redundant-declaration: A friend declaration inside a class
24+
# counts as a declaration, so if we also declare that friend outside the
25+
# class in order to document it as part of the public API, that will
26+
# trigger a redundant declaration warning from this check.
27+
#
728
Checks: >
829
-*,
930
bugprone-*,
@@ -13,24 +34,32 @@ Checks: >
1334
performance-*,
1435
portability-*,
1536
readability-*,
37+
-google-readability-braces-around-statements,
1638
-google-readability-namespace-comments,
17-
-google-runtime-int,
1839
-google-runtime-references,
1940
-misc-non-private-member-variables-in-classes,
41+
-modernize-return-braced-init-list,
42+
-performance-move-const-arg,
2043
-readability-named-parameter,
44+
-modernize-use-trailing-return-type,
2145
-readability-braces-around-statements,
22-
-readability-magic-numbers
46+
-readability-redundant-declaration
2347
2448
# Turn all the warnings from the checks above into errors.
2549
WarningsAsErrors: "*"
2650

51+
# TODO(#205) - Enable clang-tidy checks in our headers.
52+
# HeaderFilterRegex: "google/cloud/.*"
53+
2754
CheckOptions:
2855
- { key: readability-identifier-naming.NamespaceCase, value: lower_case }
2956
- { key: readability-identifier-naming.ClassCase, value: CamelCase }
3057
- { key: readability-identifier-naming.StructCase, value: CamelCase }
3158
- { key: readability-identifier-naming.TemplateParameterCase, value: CamelCase }
32-
- { key: readability-identifier-naming.FunctionCase, value: CamelCase }
59+
- { key: readability-identifier-naming.FunctionCase, value: aNy_CasE }
3360
- { key: readability-identifier-naming.VariableCase, value: lower_case }
61+
- { key: readability-identifier-naming.ClassMemberCase, value: lower_case }
62+
- { key: readability-identifier-naming.ClassMemberSuffix, value: _ }
3463
- { key: readability-identifier-naming.PrivateMemberSuffix, value: _ }
3564
- { key: readability-identifier-naming.ProtectedMemberSuffix, value: _ }
3665
- { key: readability-identifier-naming.MacroDefinitionCase, value: UPPER_CASE }

ci/kokoro/docker/Dockerfile.fedora-install

Lines changed: 45 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -12,62 +12,59 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
ARG DISTRO_VERSION=30
15+
ARG DISTRO_VERSION=31
1616
FROM fedora:${DISTRO_VERSION}
1717
ARG NCPU=4
1818

19-
RUN dnf makecache && dnf install -y \
20-
autoconf \
21-
automake \
22-
c-ares-devel \
23-
ccache \
24-
clang \
25-
clang-analyzer \
26-
clang-tools-extra \
27-
cmake \
28-
curl \
29-
doxygen \
30-
gcc-c++ \
31-
git \
32-
grpc-devel \
33-
grpc-plugins \
34-
libcxx-devel \
35-
libcxxabi-devel \
36-
libtool \
37-
make \
38-
ncurses-term \
39-
openssl-devel \
40-
pkgconfig \
41-
protobuf-compiler \
42-
python3 \
43-
shtool \
44-
unzip \
45-
wget \
46-
which \
47-
zlib-devel
19+
# Fedora includes packages for gRPC, libcurl, and OpenSSL that are recent enough
20+
# for `google-cloud-cpp`. Install these packages and additional development
21+
# tools to compile the dependencies:
22+
RUN dnf makecache && \
23+
dnf install -y abi-compliance-checker abi-dumper \
24+
clang clang-tools-extra cmake diffutils doxygen findutils gcc-c++ git \
25+
grpc-devel grpc-plugins libcxx-devel libcxxabi-devel libcurl-devel \
26+
make openssl-devel pkgconfig protobuf-compiler python3 python3-pip \
27+
ShellCheck tar unzip w3m wget which zlib-devel
4828

49-
# Install googleapis.
50-
WORKDIR /var/tmp/build
51-
RUN wget -q https://github.com/googleapis/cpp-cmakefiles/archive/v0.4.1.tar.gz
52-
RUN tar -xf v0.4.1.tar.gz
53-
WORKDIR /var/tmp/build/cpp-cmakefiles-0.4.1
54-
RUN cmake \
55-
-DBUILD_SHARED_LIBS=YES \
56-
-H. -Bcmake-out
57-
RUN cmake --build cmake-out --target install -- -j ${NCPU}
58-
RUN ldconfig
29+
# Install the the buildifier tool, which does not compile with the default
30+
# golang compiler for Ubuntu 16.04 and Ubuntu 18.04.
31+
RUN wget -q -O /usr/bin/buildifier https://github.com/bazelbuild/buildtools/releases/download/0.29.0/buildifier
32+
RUN chmod 755 /usr/bin/buildifier
5933

60-
# Install googletest.
34+
# Install cmake_format to automatically format the CMake list files.
35+
# https://github.com/cheshirekow/cmake_format
36+
# Pin this to an specific version because the formatting changes when the
37+
# "latest" version is updated, and we do not want the builds to break just
38+
# because some third party changed something.
39+
RUN pip3 install --upgrade pip
40+
RUN pip3 install cmake_format==0.6.8
41+
42+
# Install googletest, remove the downloaded files and the temporary artifacts
43+
# after a successful build to keep the image smaller (and with fewer layers)
6144
WORKDIR /var/tmp/build
62-
RUN wget -q https://github.com/google/googletest/archive/release-1.10.0.tar.gz
63-
RUN tar -xf release-1.10.0.tar.gz
64-
WORKDIR /var/tmp/build/googletest-release-1.10.0
65-
RUN cmake \
45+
RUN wget -q https://github.com/google/googletest/archive/release-1.10.0.tar.gz && \
46+
tar -xf release-1.10.0.tar.gz && \
47+
cd /var/tmp/build/googletest-release-1.10.0 && \
48+
cmake \
6649
-DCMAKE_BUILD_TYPE="Release" \
6750
-DBUILD_SHARED_LIBS=yes \
68-
-H. -Bcmake-out/googletest
69-
RUN cmake --build cmake-out/googletest --target install -- -j ${NCPU}
70-
RUN ldconfig
51+
-H. -Bcmake-out/googletest && \
52+
cmake --build cmake-out/googletest --target install -- -j ${NCPU} && \
53+
ldconfig && \
54+
cd /var/tmp && rm -fr build
55+
56+
# Install googletest, remove the downloaded files and the temporary artifacts
57+
# after a successful build to keep the image smaller (and with fewer layers)
58+
WORKDIR /var/tmp/build
59+
RUN wget -q https://github.com/googleapis/cpp-cmakefiles/archive/v0.5.0.tar.gz && \
60+
tar -xf v0.5.0.tar.gz && \
61+
cd /var/tmp/build/cpp-cmakefiles-0.5.0 && \
62+
cmake \
63+
-DBUILD_SHARED_LIBS=YES \
64+
-H. -Bcmake-out && \
65+
cmake --build cmake-out --target install -- -j ${NCPU} && \
66+
ldconfig && \
67+
cd /var/tmp && rm -fr build
7168

7269
# Install Bazel because some of the builds need it.
7370
WORKDIR /var/tmp/ci

ci/kokoro/docker/Dockerfile.ubuntu-install

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -51,28 +51,6 @@ RUN apt-get update && \
5151
wget \
5252
zlib1g-dev
5353

54-
# By default, Ubuntu 18.04 does not install the alternatives for clang-format
55-
# and clang-tidy, so we need to manually install those.
56-
RUN if grep -q 18.04 /etc/lsb-release; then \
57-
apt-get update && apt-get --no-install-recommends install -y clang-tidy clang-format-7 clang-tools; \
58-
update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-6.0 100; \
59-
update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-7 100; \
60-
update-alternatives --install /usr/bin/scan-build scan-build /usr/bin/scan-build-6.0 100; \
61-
fi
62-
63-
# Install the the buildifier tool, which does not compile with the default
64-
# golang compiler for Ubuntu 16.04 and Ubuntu 18.04.
65-
RUN wget -q -O /usr/bin/buildifier https://github.com/bazelbuild/buildtools/releases/download/0.29.0/buildifier
66-
RUN chmod 755 /usr/bin/buildifier
67-
68-
# Install cmake_format to automatically format the CMake list files.
69-
# https://github.com/cheshirekow/cmake_format
70-
# Pin this to an specific version because the formatting changes when the
71-
# "latest" version is updated, and we do not want the builds to break just
72-
# because some third party changed something.
73-
RUN pip3 install --upgrade pip
74-
RUN pip3 install setuptools cmake_format==0.6.8
75-
7654
# Install protobuf using CMake. Some distributions include protobuf, but gRPC
7755
# requires 3.4.x or newer, and many of those distribution use older versions.
7856
# We need to install both the debug and Release version because:

ci/kokoro/docker/build-in-docker-cmake.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ cmake_extra_flags=(
5555
# Always set the build type, so it can be configured by the `build.sh`
5656
# script.
5757
"-DCMAKE_BUILD_TYPE=${BUILD_TYPE}"
58-
59-
# Always disable the ccache, it can make some builds flaky, and we do not
60-
# preserve the cache between builds.
61-
"-DGOOGLE_CLOUD_CPP_ENABLE_CCACHE=OFF"
6258
)
6359
if [[ "${BUILD_TESTING:-}" == "no" ]]; then
6460
cmake_extra_flags+=( "-DBUILD_TESTING=OFF" )
6561
fi
6662

63+
if [[ "${CLANG_TIDY:-}" = "yes" ]]; then
64+
cmake_extra_flags+=("-DGOOGLE_CLOUD_CPP_CLANG_TIDY=yes")
65+
fi
66+
6767
if [[ "${GOOGLE_CLOUD_CPP_CXX_STANDARD:-}" != "" ]]; then
6868
cmake_extra_flags+=(
6969
"-DGOOGLE_CLOUD_CPP_CXX_STANDARD=${GOOGLE_CLOUD_CPP_CXX_STANDARD}")

ci/kokoro/docker/build.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,16 @@ fi
5757
if [[ "${BUILD_NAME}" = "clang-tidy" ]]; then
5858
# Compile with clang-tidy(1) turned on. The build treats clang-tidy warnings
5959
# as errors.
60-
export BUILD_TYPE=Debug
60+
export DISTRO=fedora-install
61+
export DISTRO_VERSION=31
6162
export CC=clang
6263
export CXX=clang++
63-
export CMAKE_FLAGS="-DGOOGLE_CLOUD_CPP_CLANG_TIDY=yes"
64+
export BUILD_TYPE=Debug
6465
export CHECK_STYLE=yes
6566
export GENERATE_DOCS=yes
67+
export CLANG_TIDY=yes
68+
export TEST_INSTALL=yes
69+
in_docker_script="ci/kokoro/docker/build-in-docker-cmake.sh"
6670
elif [[ "${BUILD_NAME}" = "publish-refdocs" ]]; then
6771
export BUILD_TYPE=Debug
6872
export CC=clang
@@ -132,7 +136,6 @@ elif [[ "${BUILD_NAME}" = "no-tests" ]]; then
132136
# package maintainers, where the cost of running the tests for a fixed version
133137
# is too high.
134138
export BUILD_TESTING=no
135-
export CHECK_STYLE=yes
136139
elif [[ "${BUILD_NAME}" = "libcxx" ]]; then
137140
# Compile using libc++. This is easier to install on Fedora.
138141
export CC=clang
@@ -374,6 +377,10 @@ docker_flags=(
374377
# clang-format, cmake-format, and buildifier).
375378
"--env" "CHECK_STYLE=${CHECK_STYLE:-}"
376379

380+
# If set to 'yes', the build script will configure clang-tidy. Currently
381+
# only the CMake builds use this flag.
382+
"--env" "CLANG_TIDY=${CLANG_TIDY:-}"
383+
377384
# If set to 'no', skip the integration tests.
378385
"--env" "RUN_INTEGRATION_TESTS=${RUN_INTEGRATION_TESTS:-}"
379386

google/cloud/future_generic.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ class future final : private internal::future_base<T> {
9090
* ready. The return type is a future wrapping the return type of
9191
* @a func.
9292
*
93-
* @return future<T> where T is std::result_of_t<F, R> (basically).
94-
* If T matches future<U> then it returns future<U>. The returned
93+
* @return `future<T>` where T is `std::result_of_t<F, R>` (basically).
94+
* If T matches `future<U>` then it returns `future<U>`. The returned
9595
* future will contain the result of @a func.
9696
* @param func a Callable to be invoked when the future is ready.
9797
* The function might be called immediately, e.g., if the future is
9898
* ready.
9999
*
100-
* Side effects: valid() == false if the operation is successful.
100+
* Side effects: `valid() == false` if the operation is successful.
101101
*/
102102
template <typename F>
103103
typename internal::then_helper<F, T>::future_t then(F&& func) {

google/cloud/future_generic_test.cc

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,12 @@ TEST(FutureTestInt, conform_30_6_5_7) {
9898
EXPECT_TRUE(f0.valid());
9999
ASSERT_EQ(std::future_status::ready, f0.wait_for(0_ms));
100100
#if GOOGLE_CLOUD_CPP_HAVE_EXCEPTIONS
101-
EXPECT_THROW(try { f0.get(); } catch (std::future_error const& ex) {
102-
EXPECT_EQ(std::future_errc::broken_promise, ex.code());
103-
throw;
104-
},
105-
std::future_error);
101+
EXPECT_THROW(
102+
try { f0.get(); } catch (std::future_error const& ex) {
103+
EXPECT_EQ(std::future_errc::broken_promise, ex.code());
104+
throw;
105+
},
106+
std::future_error);
106107
#else
107108
EXPECT_DEATH_IF_SUPPORTED(
108109
f0.get(),
@@ -201,11 +202,12 @@ TEST(FutureTestInt, conform_30_6_5_18) {
201202
p0.set_exception(std::make_exception_ptr(std::runtime_error("testing")));
202203
ASSERT_EQ(std::future_status::ready, f0.wait_for(0_ms));
203204
#if GOOGLE_CLOUD_CPP_HAVE_EXCEPTIONS
204-
EXPECT_THROW(try { f0.get(); } catch (std::runtime_error const& ex) {
205-
EXPECT_EQ(std::string("testing"), ex.what());
206-
throw;
207-
},
208-
std::runtime_error);
205+
EXPECT_THROW(
206+
try { f0.get(); } catch (std::runtime_error const& ex) {
207+
EXPECT_EQ(std::string("testing"), ex.what());
208+
throw;
209+
},
210+
std::runtime_error);
209211
#else
210212
EXPECT_DEATH_IF_SUPPORTED(
211213
f0.get(),
@@ -430,11 +432,12 @@ TEST(FutureTestInt, conform_30_6_6_17) {
430432
future<int> f = p.get_future();
431433
p.set_exception(std::make_exception_ptr(std::runtime_error("test message")));
432434
#if GOOGLE_CLOUD_CPP_HAVE_EXCEPTIONS
433-
EXPECT_THROW(try { f.get(); } catch (std::runtime_error const& ex) {
434-
EXPECT_THAT(ex.what(), HasSubstr("test message"));
435-
throw;
436-
},
437-
std::runtime_error);
435+
EXPECT_THROW(
436+
try { f.get(); } catch (std::runtime_error const& ex) {
437+
EXPECT_THAT(ex.what(), HasSubstr("test message"));
438+
throw;
439+
},
440+
std::runtime_error);
438441
#else
439442
EXPECT_DEATH_IF_SUPPORTED(
440443
f.get(),

0 commit comments

Comments
 (0)