Skip to content

Commit

Permalink
Upgrade clang-tidy and clang-format to 11 (grpc#25590)
Browse files Browse the repository at this point in the history
* Upgrade clang-tidy and clang-format to 11
* Reformat code
* Fix abseil-string-find-str-contains
* Fix modernize-make-unique
  • Loading branch information
veblush authored Mar 4, 2021
1 parent dae5624 commit 377fe60
Show file tree
Hide file tree
Showing 20 changed files with 131 additions and 132 deletions.
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Language: Cpp
BasedOnStyle: Google
DerivePointerAlignment: false
PointerAlignment: Left
IncludeBlocks: Preserve
---
Language: ObjC
BasedOnStyle: Google
Expand Down
13 changes: 12 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,18 @@ Checks: '-*,
readability-inconsistent-declaration-parameter-name,
readability-redundant-control-flow,
readability-redundant-smartptr-get,
readability-string-compare'
readability-string-compare,
-bugprone-branch-clone,
-bugprone-infinite-loop,
-bugprone-not-null-terminated-result,
-bugprone-reserved-identifier,
-bugprone-signed-char-misuse,
-bugprone-sizeof-expression,
-bugprone-unhandled-self-assignment,
-google-readability-avoid-underscore-in-googletest-name,
-google-upgrade-googletest-case,
-performance-no-automatic-move'
WarningsAsErrors: '*'
CheckOptions:
- key: readability-function-size.StatementThreshold
Expand Down
7 changes: 3 additions & 4 deletions src/cpp/server/health/default_health_check_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,9 @@ bool DefaultHealthCheckService::HealthCheckServiceImpl::EncodeResponse(
grpc_health_v1_HealthCheckResponse_new(arena.ptr());
grpc_health_v1_HealthCheckResponse_set_status(
response_struct,
status == NOT_FOUND
? grpc_health_v1_HealthCheckResponse_SERVICE_UNKNOWN
: status == SERVING ? grpc_health_v1_HealthCheckResponse_SERVING
: grpc_health_v1_HealthCheckResponse_NOT_SERVING);
status == NOT_FOUND ? grpc_health_v1_HealthCheckResponse_SERVICE_UNKNOWN
: status == SERVING ? grpc_health_v1_HealthCheckResponse_SERVING
: grpc_health_v1_HealthCheckResponse_NOT_SERVING);
size_t buf_length;
char* buf = grpc_health_v1_HealthCheckResponse_serialize(
response_struct, arena.ptr(), &buf_length);
Expand Down
4 changes: 2 additions & 2 deletions src/objective-c/GRPCClient/private/GRPCCore/GRPCChannel.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ - (instancetype)initWithHost:(NSString *)host callOptions:(GRPCCallOptions *)cal
if (_callOptions.transport != NULL) {
id<GRPCTransportFactory> transportFactory =
[[GRPCTransportRegistry sharedInstance] getTransportFactoryWithID:_callOptions.transport];
if (!
[transportFactory respondsToSelector:@selector(createCoreChannelFactoryWithCallOptions:)]) {
if (![transportFactory
respondsToSelector:@selector(createCoreChannelFactoryWithCallOptions:)]) {
// impossible because we are using GRPCCore now
[NSException raise:NSInternalInconsistencyException
format:@"Transport factory type is wrong"];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM debian:10

# Add buster-backports for more recent clang packages
RUN echo "deb http://deb.debian.org/debian buster-backports main" | tee /etc/apt/sources.list.d/buster-backports.list
FROM debian:bullseye

# Install clang-format
RUN apt-get update && apt-get install -y clang-format-8
ENV CLANG_FORMAT=clang-format-8
RUN apt-get update && apt-get install -y clang-format-11
ENV CLANG_FORMAT=clang-format-11

ADD clang_format_all_the_things.sh /

Expand Down
11 changes: 4 additions & 7 deletions templates/tools/dockerfile/grpc_clang_tidy/Dockerfile.template
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

<%include file="../python_debian10.include"/>
FROM debian:bullseye

# Add buster-backports for more recent clang packages
RUN echo "deb http://deb.debian.org/debian buster-backports main" | tee /etc/apt/sources.list.d/buster-backports.list

# Install clang-tidy 7
RUN apt-get update && apt-get install -y clang-tidy-8 jq
ENV CLANG_TIDY=clang-tidy-8
# Install clang-tidy 11
RUN apt-get update && apt-get install -y clang-tidy-11 jq
ENV CLANG_TIDY=clang-tidy-11

ADD clang_tidy_all_the_things.sh /

Expand Down
6 changes: 0 additions & 6 deletions templates/tools/dockerfile/python_debian10.include

This file was deleted.

53 changes: 53 additions & 0 deletions templates/tools/dockerfile/python_debian11.include
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
FROM debian:bullseye

# Install Git and basic packages.
RUN apt-get update && apt-get install -y ${'\\'}
autoconf ${'\\'}
autotools-dev ${'\\'}
build-essential ${'\\'}
bzip2 ${'\\'}
ccache ${'\\'}
curl ${'\\'}
dnsutils ${'\\'}
gcc ${'\\'}
gcc-multilib ${'\\'}
git ${'\\'}
golang ${'\\'}
gyp ${'\\'}
lcov ${'\\'}
libc6 ${'\\'}
libc6-dbg ${'\\'}
libc6-dev ${'\\'}
libgtest-dev ${'\\'}
libtool ${'\\'}
make ${'\\'}
perl ${'\\'}
strace ${'\\'}
telnet ${'\\'}
unzip ${'\\'}
wget ${'\\'}
zip && apt-get clean

#================
# Build profiling
RUN apt-get update && apt-get install -y time && apt-get clean

# Install Python 3.7 from source (and installed as a default python3)
# (Bullseye comes with Python 3.9 which isn't supported by pytype yet)
RUN apt update && apt install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev ${'\\'}
libnss3-dev libssl-dev libreadline-dev libffi-dev
RUN curl -O https://www.python.org/ftp/python/3.7.9/Python-3.7.9.tar.xz && ${'\\'}
tar -xf Python-3.7.9.tar.xz && ${'\\'}
cd Python-3.7.9 && ${'\\'}
./configure && ${'\\'}
make -j 4 && ${'\\'}
make install
RUN curl https://bootstrap.pypa.io/get-pip.py | python3

# Install Python 2.7
RUN apt-get update && apt-get install -y python2 python2-dev
RUN ln -s /usr/bin/python2 /usr/bin/python
RUN curl https://bootstrap.pypa.io/2.7/get-pip.py | python2

<%include file="./gcp_api_libraries.include"/>
<%include file="./run_tests_addons.include"/>
16 changes: 5 additions & 11 deletions templates/tools/dockerfile/test/sanity/Dockerfile.template
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

<%include file="../../python_debian10.include"/>
<%include file="../../python_debian11.include"/>
<%include file="../../cxx_deps.include"/>

#========================
# Sanity test dependencies
RUN apt-get update && apt-get -t buster install -y python3.7 python3-all-dev
RUN curl https://bootstrap.pypa.io/get-pip.py | python3.7

# Make Python 3.7 the default Python 3 version
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 1
RUN apt-get update && apt-get install -y ${"\\"}
autoconf ${"\\"}
automake ${"\\"}
Expand All @@ -34,15 +30,13 @@
RUN python3 -m pip install simplejson mako virtualenv==16.7.9 lxml six

# Upgrade Python's YAML library
RUN python2 -m pip install --upgrade --ignore-installed PyYAML==5.4.1 --user
RUN python3 -m pip install --upgrade --ignore-installed PyYAML==5.4.1 --user

# Add buster-backports for more recent clang packages
RUN echo "deb http://deb.debian.org/debian buster-backports main" | tee /etc/apt/sources.list.d/buster-backports.list

# Install clang, clang-format, and clang-tidy
RUN apt-get update && apt-get install -y clang clang-format-8 clang-tidy-8 jq
ENV CLANG_FORMAT=clang-format-8
ENV CLANG_TIDY=clang-tidy-8
RUN apt-get update && apt-get install -y clang clang-format-11 clang-tidy-11 jq
ENV CLANG_FORMAT=clang-format-11
ENV CLANG_TIDY=clang-tidy-11


<%include file="../../bazel.include"/>
Expand Down
5 changes: 3 additions & 2 deletions test/cpp/client/client_channel_stress_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <string>
#include <thread>

#include "absl/memory/memory.h"
#include "absl/strings/str_cat.h"

#include <grpc/grpc.h>
Expand Down Expand Up @@ -180,8 +181,8 @@ class ClientChannelStressTest {
port_ = grpc_pick_unused_port_or_die();
gpr_log(GPR_INFO, "starting %s server on port %d", type_.c_str(), port_);
grpc::internal::CondVar cond;
thread_.reset(new std::thread(
std::bind(&ServerThread::Start, this, server_host, &mu, &cond)));
thread_ = absl::make_unique<std::thread>(
std::bind(&ServerThread::Start, this, server_host, &mu, &cond));
cond.Wait(&mu);
gpr_log(GPR_INFO, "%s server startup complete", type_.c_str());
}
Expand Down
2 changes: 1 addition & 1 deletion test/cpp/end2end/client_callback_end2end_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ class ClientCallbackEnd2endTest
cv.notify_one();
#if GRPC_ALLOW_EXCEPTIONS
if (maybe_except) {
throw - 1;
throw -1;
}
#else
GPR_ASSERT(!maybe_except);
Expand Down
13 changes: 6 additions & 7 deletions test/cpp/end2end/end2end_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <thread>

#include "absl/memory/memory.h"
#include "absl/strings/match.h"
#include "absl/strings/str_format.h"

#include "src/core/ext/filters/client_channel/backup_poller.h"
Expand Down Expand Up @@ -1459,13 +1460,11 @@ TEST_P(End2endTest, ExpectErrorTest) {
EXPECT_EQ(iter->code(), s.error_code());
EXPECT_EQ(iter->error_message(), s.error_message());
EXPECT_EQ(iter->binary_error_details(), s.error_details());
EXPECT_TRUE(context.debug_error_string().find("created") !=
std::string::npos);
EXPECT_TRUE(context.debug_error_string().find("file") != std::string::npos);
EXPECT_TRUE(context.debug_error_string().find("line") != std::string::npos);
EXPECT_TRUE(context.debug_error_string().find("status") !=
std::string::npos);
EXPECT_TRUE(context.debug_error_string().find("13") != std::string::npos);
EXPECT_TRUE(absl::StrContains(context.debug_error_string(), "created"));
EXPECT_TRUE(absl::StrContains(context.debug_error_string(), "file"));
EXPECT_TRUE(absl::StrContains(context.debug_error_string(), "line"));
EXPECT_TRUE(absl::StrContains(context.debug_error_string(), "status"));
EXPECT_TRUE(absl::StrContains(context.debug_error_string(), "13"));
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/cpp/end2end/exception_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ExceptingServiceImpl : public ::grpc::testing::EchoTestService::Service {
public:
Status Echo(ServerContext* /*server_context*/, const EchoRequest* /*request*/,
EchoResponse* /*response*/) override {
throw - 1;
throw -1;
}
Status RequestStream(ServerContext* /*context*/,
ServerReader<EchoRequest>* /*reader*/,
Expand Down
5 changes: 3 additions & 2 deletions test/cpp/end2end/grpclb_end2end_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <string>
#include <thread>

#include "absl/memory/memory.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"

Expand Down Expand Up @@ -696,8 +697,8 @@ class GrpclbEnd2endTest : public ::testing::Test {
// by ServerThread::Serve from firing before the wait below is hit.
grpc::internal::MutexLock lock(&mu);
grpc::internal::CondVar cond;
thread_.reset(new std::thread(
std::bind(&ServerThread::Serve, this, server_host, &mu, &cond)));
thread_ = absl::make_unique<std::thread>(
std::bind(&ServerThread::Serve, this, server_host, &mu, &cond));
cond.Wait(&mu);
gpr_log(GPR_INFO, "%s server startup complete", type_.c_str());
}
Expand Down
5 changes: 3 additions & 2 deletions test/cpp/interop/interop_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <type_traits>
#include <utility>

#include "absl/strings/match.h"
#include "absl/strings/str_format.h"

#include <grpc/grpc.h>
Expand Down Expand Up @@ -225,7 +226,7 @@ bool InteropClient::DoComputeEngineCreds(
GPR_ASSERT(response.username().c_str() == default_service_account);
GPR_ASSERT(!response.oauth_scope().empty());
const char* oauth_scope_str = response.oauth_scope().c_str();
GPR_ASSERT(oauth_scope.find(oauth_scope_str) != std::string::npos);
GPR_ASSERT(absl::StrContains(oauth_scope, oauth_scope_str));
gpr_log(GPR_DEBUG, "Large unary with compute engine creds done.");
return true;
}
Expand All @@ -251,7 +252,7 @@ bool InteropClient::DoOauth2AuthToken(const std::string& username,
GPR_ASSERT(!response.oauth_scope().empty());
GPR_ASSERT(username == response.username());
const char* oauth_scope_str = response.oauth_scope().c_str();
GPR_ASSERT(oauth_scope.find(oauth_scope_str) != std::string::npos);
GPR_ASSERT(absl::StrContains(oauth_scope, oauth_scope_str));
gpr_log(GPR_DEBUG, "Unary with oauth2 access token credentials done.");
return true;
}
Expand Down
6 changes: 3 additions & 3 deletions test/cpp/qps/client_async.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class ClientRpcContextUnaryImpl : public ClientRpcContext {
if (!next_issue_) { // ready to issue
RunNextState(true, nullptr);
} else { // wait for the issue time
alarm_.reset(new Alarm);
alarm_ = absl::make_unique<Alarm>();
alarm_->Set(cq_, next_issue_(), ClientRpcContext::tag(this));
}
}
Expand Down Expand Up @@ -371,7 +371,7 @@ class ClientRpcContextStreamingPingPongImpl : public ClientRpcContext {
break; // loop around, don't return
case State::WAIT:
next_state_ = State::READY_TO_WRITE;
alarm_.reset(new Alarm);
alarm_ = absl::make_unique<Alarm>();
alarm_->Set(cq_, next_issue_(), ClientRpcContext::tag(this));
return true;
case State::READY_TO_WRITE:
Expand Down Expand Up @@ -556,7 +556,7 @@ class ClientRpcContextStreamingFromClientImpl : public ClientRpcContext {
}
break; // loop around, don't return
case State::WAIT:
alarm_.reset(new Alarm);
alarm_ = absl::make_unique<Alarm>();
alarm_->Set(cq_, next_issue_(), ClientRpcContext::tag(this));
next_state_ = State::READY_TO_WRITE;
return true;
Expand Down
2 changes: 1 addition & 1 deletion tools/distrib/run_clang_tidy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2.7
#!/usr/bin/env python3
# Copyright 2017 gRPC authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
9 changes: 3 additions & 6 deletions tools/dockerfile/grpc_clang_format/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM debian:10

# Add buster-backports for more recent clang packages
RUN echo "deb http://deb.debian.org/debian buster-backports main" | tee /etc/apt/sources.list.d/buster-backports.list
FROM debian:bullseye

# Install clang-format
RUN apt-get update && apt-get install -y clang-format-8
ENV CLANG_FORMAT=clang-format-8
RUN apt-get update && apt-get install -y clang-format-11
ENV CLANG_FORMAT=clang-format-11

ADD clang_format_all_the_things.sh /

Expand Down
Loading

0 comments on commit 377fe60

Please sign in to comment.