From 690f100a6683d51779b3f0eb3300b8a5ff07a678 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 31 Jan 2024 14:49:01 -0800 Subject: [PATCH] Automated rollback of commit 2b86c3d9ed696f89156651a6d1a73af878c78aff. PiperOrigin-RevId: 603166021 --- src/google/protobuf/compiler/java/file.cc | 4 +-- src/google/protobuf/compiler/java/helpers.cc | 36 ++++++++++++-------- src/google/protobuf/compiler/versions.cc | 24 ++++--------- src/google/protobuf/compiler/versions.h | 6 ++-- 4 files changed, 33 insertions(+), 37 deletions(-) diff --git a/src/google/protobuf/compiler/java/file.cc b/src/google/protobuf/compiler/java/file.cc index 6fa447dd27..875b35d5a8 100644 --- a/src/google/protobuf/compiler/java/file.cc +++ b/src/google/protobuf/compiler/java/file.cc @@ -519,13 +519,13 @@ static void GenerateSibling( printer.Print( "// Generated by the protocol buffer compiler. DO NOT EDIT!\n" - "// source: $filename$\n", + "// source: $filename$\n" + "\n", "filename", descriptor->file()->name()); if (opensource_runtime) { printer.Print("// Protobuf Java Version: $protobuf_java_version$\n", "protobuf_java_version", PROTOBUF_JAVA_VERSION_STRING); } - printer.Print("\n"); if (!java_package.empty()) { printer.Print( "package $package$;\n" diff --git a/src/google/protobuf/compiler/java/helpers.cc b/src/google/protobuf/compiler/java/helpers.cc index 826d9f8344..a9d6ad3430 100644 --- a/src/google/protobuf/compiler/java/helpers.cc +++ b/src/google/protobuf/compiler/java/helpers.cc @@ -87,21 +87,27 @@ void PrintEnumVerifierLogic( void PrintGencodeVersionValidator(io::Printer* printer, bool oss_runtime, absl::string_view java_class_name) { - const auto& version = GetProtobufJavaVersion(oss_runtime); - printer->Print( - "com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion(\n" - " com.google.protobuf.RuntimeVersion.RuntimeDomain.$domain$,\n" - " $major$,\n" - " $minor$,\n" - " $patch$,\n" - " $suffix$,\n" - " $location$);\n", - "domain", oss_runtime ? "PUBLIC" : "GOOGLE_INTERNAL", "major", - absl::StrCat("/* major= */ ", version.major()), "minor", - absl::StrCat("/* minor= */ ", version.minor()), "patch", - absl::StrCat("/* patch= */ ", version.patch()), "suffix", - absl::StrCat("/* suffix= */ \"", version.suffix(), "\""), "location", - absl::StrCat(java_class_name, ".class.getName()")); + if (oss_runtime) { + const auto& version = GetProtobufJavaVersion(); + printer->Print( + "com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion(\n" + " com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC,\n" + " $major$,\n" + " $minor$,\n" + " $patch$,\n" + " $suffix$,\n" + " $location$);\n", + "major", absl::StrCat("/* major= */ ", version.major()), "minor", + absl::StrCat("/* minor= */ ", version.minor()), "patch", + absl::StrCat("/* patch= */ ", version.patch()), "suffix", + absl::StrCat("/* suffix= */ \"", version.suffix(), "\""), "location", + absl::StrCat(java_class_name, ".class.getName()")); + } else { + printer->Print( + "com.google.protobuf.RuntimeVersion.validateProtobufGencodeDomain(\n" + " " + "com.google.protobuf.RuntimeVersion.RuntimeDomain.GOOGLE_INTERNAL);\n"); + } } std::string UnderscoresToCamelCase(absl::string_view input, diff --git a/src/google/protobuf/compiler/versions.cc b/src/google/protobuf/compiler/versions.cc index f1761ba621..8927d8c03d 100644 --- a/src/google/protobuf/compiler/versions.cc +++ b/src/google/protobuf/compiler/versions.cc @@ -16,9 +16,6 @@ #include "absl/strings/string_view.h" #include "google/protobuf/compiler/plugin.pb.h" -// Must be included last. -#include "google/protobuf/port_def.inc" - namespace google { namespace protobuf { namespace compiler { @@ -40,29 +37,22 @@ Version ParseProtobufVersion(absl::string_view version) { } } // namespace internal -const Version& GetProtobufCPPVersion(bool oss_runtime) { - absl::string_view version = PROTOBUF_CPP_VERSION_STRING; +const Version& GetProtobufCPPVersion() { // Heap-allocated versions to avoid re-parsing version strings static const Version* cpp_version = - new Version(internal::ParseProtobufVersion(version)); + new Version(internal::ParseProtobufVersion(PROTOBUF_CPP_VERSION_STRING)); return *cpp_version; } - -const Version& GetProtobufJavaVersion(bool oss_runtime) { - absl::string_view version = PROTOBUF_JAVA_VERSION_STRING; +const Version& GetProtobufJavaVersion() { static const Version* java_version = - new Version(internal::ParseProtobufVersion(version)); + new Version(internal::ParseProtobufVersion(PROTOBUF_JAVA_VERSION_STRING)); return *java_version; } - -const Version& GetProtobufPythonVersion(bool oss_runtime) { - absl::string_view version = PROTOBUF_PYTHON_VERSION_STRING; - static const Version* python_version = - new Version(internal::ParseProtobufVersion(version)); +const Version& GetProtobufPythonVersion() { + static const Version* python_version = new Version( + internal::ParseProtobufVersion(PROTOBUF_PYTHON_VERSION_STRING)); return *python_version; } } // namespace compiler } // namespace protobuf } // namespace google - -#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/compiler/versions.h b/src/google/protobuf/compiler/versions.h index 6b32ca3475..0e31f18ddb 100644 --- a/src/google/protobuf/compiler/versions.h +++ b/src/google/protobuf/compiler/versions.h @@ -67,9 +67,9 @@ PROTOC_EXPORT Version ParseProtobufVersion(absl::string_view version); } // namespace internal // Gets the version message according to the version strings defined above. -const Version& GetProtobufCPPVersion(bool oss_runtime); -const Version& GetProtobufJavaVersion(bool oss_runtime); -const Version& GetProtobufPythonVersion(bool oss_runtime); +const Version& GetProtobufCPPVersion(); +const Version& GetProtobufJavaVersion(); +const Version& GetProtobufPythonVersion(); } // namespace compiler } // namespace protobuf } // namespace google