diff --git a/protoc/CppFileGenerator.cpp b/protoc/CppFileGenerator.cpp index a0eb51d0ce..df13428860 100644 --- a/protoc/CppFileGenerator.cpp +++ b/protoc/CppFileGenerator.cpp @@ -130,7 +130,13 @@ void FileGenerator::GenerateImplementation(Printer *printer) { "#include \"$file$.pb.h\"\n" "\n" "#include // NOLINT(build/include)\n" +#if GOOGLE_PROTOBUF_VERSION < 4022000 "#include \n" +#else + "#include \n" + "#include \n" + "#include \n" +#endif "\n" "#include \"common/rpc/RpcChannel.h\"\n" "#include \"common/rpc/RpcController.h\"\n" @@ -215,7 +221,11 @@ void FileGenerator::GenerateBuildDescriptors(Printer* printer) { " \"$filename$\");\n" // Note that this GOOGLE_CHECK is necessary to prevent a warning about // "file" being unused when compiling an empty .proto file. +#if GOOGLE_PROTOBUF_VERSION < 4022000 "GOOGLE_CHECK(file != NULL);\n", +#else + "ABSL_CHECK(file != NULL);\n", +#endif "filename", m_file->name()); for (int i = 0; i < m_file->service_count(); i++) { @@ -248,7 +258,7 @@ void FileGenerator::GenerateBuildDescriptors(Printer* printer) { "assigndescriptorsname", GlobalAssignDescriptorsName(m_output_name)); printer->Print("} // namespace\n"); -#else +#elif GOOGLE_PROTOBUF_VERSION < 4022000 printer->Print( "namespace {\n" "\n" @@ -260,6 +270,17 @@ void FileGenerator::GenerateBuildDescriptors(Printer* printer) { "\n", "assigndescriptorsname", GlobalAssignDescriptorsName(m_output_name)); printer->Print("} // namespace\n"); +#else + printer->Print( + "namespace {\n" + "\n" + "inline void protobuf_AssignDescriptorsOnce() {\n" + " static ::absl::once_flag once;\n" + " ::absl::call_once(once, &$assigndescriptorsname$);\n" + "}\n" + "\n", + "assigndescriptorsname", GlobalAssignDescriptorsName(m_output_name)); + printer->Print("} // namespace\n"); #endif } } diff --git a/protoc/ServiceGenerator.cpp b/protoc/ServiceGenerator.cpp index 47c1d6735f..5982244487 100644 --- a/protoc/ServiceGenerator.cpp +++ b/protoc/ServiceGenerator.cpp @@ -130,7 +130,12 @@ void ServiceGenerator::GenerateInterface(Printer* printer) { printer->Print(vars_, "\n" " private:\n" +#if GOOGLE_PROTOBUF_VERSION < 4022000 " GOOGLE_DISALLOW_EVIL_CONSTRUCTORS($classname$);\n" +#else + " $classname$(const $classname$&) = delete;\n" + " $classname$& operator=(const $classname$&) = delete;\n" +#endif "};\n" "\n"); } @@ -178,7 +183,12 @@ void ServiceGenerator::GenerateStubDefinition(Printer* printer) { " private:\n" " ola::rpc::RpcChannel* channel_;\n" " bool owns_channel_;\n" +#if GOOGLE_PROTOBUF_VERSION < 4022000 " GOOGLE_DISALLOW_EVIL_CONSTRUCTORS($classname$_Stub);\n" +#else + " $classname$_Stub(const $classname$_Stub&) = delete;\n" + " $classname$_Stub& operator=(const $classname$_Stub&) = delete;\n" +#endif "};\n" "\n"); } @@ -291,7 +301,11 @@ void ServiceGenerator::GenerateCallMethod(Printer* printer) { " const ::google::protobuf::Message* request,\n" " ::google::protobuf::Message* response,\n" " ola::rpc::RpcService::CompletionCallback* done) {\n" +#if GOOGLE_PROTOBUF_VERSION < 4022000 " GOOGLE_DCHECK_EQ(method->service(), $classname$_descriptor_);\n" +#else + " ABSL_DCHECK_EQ(method->service(), $classname$_descriptor_);\n" +#endif " switch (method->index()) {\n"); for (int i = 0; i < descriptor_->method_count(); i++) { @@ -308,17 +322,28 @@ void ServiceGenerator::GenerateCallMethod(Printer* printer) { " case $index$:\n" " $name$(\n" " controller,\n" +#if GOOGLE_PROTOBUF_VERSION < 4022000 " ::google::protobuf::down_cast<\n" " const $input_type$*>(request),\n" " ::google::protobuf::down_cast<\n" " $output_type$*>(response),\n" +#else + " ::google::protobuf::internal::DownCast<\n" + " const $input_type$*>(request),\n" + " ::google::protobuf::internal::DownCast<\n" + " $output_type$*>(response),\n" +#endif " done);\n" " break;\n"); } printer->Print(vars_, " default:\n" +#if GOOGLE_PROTOBUF_VERSION < 4022000 " GOOGLE_LOG(FATAL) << \"Bad method index; this should never " +#else + " ABSL_LOG(FATAL) << \"Bad method index; this should never " +#endif "happen.\";\n" " break;\n" " }\n" @@ -339,7 +364,11 @@ void ServiceGenerator::GenerateGetPrototype(RequestOrResponse which, printer->Print(vars_, " const ::google::protobuf::MethodDescriptor* method) const {\n" +#if GOOGLE_PROTOBUF_VERSION < 4022000 " GOOGLE_DCHECK_EQ(method->service(), descriptor());\n" +#else + " ABSL_DCHECK_EQ(method->service(), descriptor());\n" +#endif " switch (method->index()) {\n"); for (int i = 0; i < descriptor_->method_count(); i++) { @@ -358,7 +387,11 @@ void ServiceGenerator::GenerateGetPrototype(RequestOrResponse which, printer->Print(vars_, " default:\n" +#if GOOGLE_PROTOBUF_VERSION < 4022000 " GOOGLE_LOG(FATAL) << \"Bad method index; this should never happen." +#else + " ABSL_LOG(FATAL) << \"Bad method index; this should never happen." +#endif "\";\n" " return *static_cast< ::google::protobuf::Message*>(NULL);\n" " }\n" diff --git a/protoc/ServiceGenerator.h b/protoc/ServiceGenerator.h index d6be12abfb..e9f2b12eec 100644 --- a/protoc/ServiceGenerator.h +++ b/protoc/ServiceGenerator.h @@ -114,7 +114,12 @@ class ServiceGenerator { const ServiceDescriptor* descriptor_; std::map vars_; +#if GOOGLE_PROTOBUF_VERSION < 4022000 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ServiceGenerator); +#else + ServiceGenerator(const ServiceGenerator&) = delete; + ServiceGenerator& operator=(const ServiceGenerator&) = delete; +#endif }; } // namespace ola diff --git a/protoc/StrUtil.cpp b/protoc/StrUtil.cpp index 6c6c338ee2..31e73d6dff 100644 --- a/protoc/StrUtil.cpp +++ b/protoc/StrUtil.cpp @@ -56,6 +56,14 @@ #include #endif // HAVE_GOOGLE_PROTOBUF_STUBS_STL_UTIL_H +#if GOOGLE_PROTOBUF_VERSION >= 4022000 +#include +#include +#define GOOGLE_CHECK ABSL_CHECK +#define GOOGLE_DCHECK_LT ABSL_CHECK_LT +#define GOOGLE_LOG_IF(LEVEL, VECTOR) ABSL_LOG_IF(LEVEL, VECTOR) +#endif + #ifdef _WIN32 // MSVC has only _snprintf, not snprintf. //