Skip to content

Commit

Permalink
Defines Protobuf compiler version strings as macros and separates out…
Browse files Browse the repository at this point in the history
… suffix string definition.

This conforms to the Protobuf release process so that suffix "-main" will stay in main and not be overwritten.

PiperOrigin-RevId: 570480115
  • Loading branch information
protobuf-github-bot authored and Copybara-Service committed Oct 3, 2023
1 parent 68fce2e commit 3c59585
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 29 deletions.
5 changes: 4 additions & 1 deletion src/google/protobuf/compiler/BUILD.bazel
Expand Up @@ -82,7 +82,10 @@ cc_library(

cc_library(
name = "versions",
hdrs = ["versions.h"],
hdrs = [
"versions.h",
"versions_suffix.h",
],
copts = COPTS,
include_prefix = "google/protobuf/compiler",
visibility = [
Expand Down
2 changes: 1 addition & 1 deletion src/google/protobuf/compiler/cpp/file.cc
Expand Up @@ -314,7 +314,7 @@ void FileGenerator::GenerateFile(io::Printer* p, GeneratedFileType file_type,
"// source: $filename$\n");
if (options_.opensource_runtime) {
p->Print("// Protobuf C++ Version: $protobuf_cpp_version$\n",
"protobuf_cpp_version", internal::kProtoCppVersionString);
"protobuf_cpp_version", PROTOBUF_CPP_VERSION_STRING);
}
p->Print("\n");
p->Emit({{"cb", cb}, {"guard", guard}}, R"(
Expand Down
4 changes: 2 additions & 2 deletions src/google/protobuf/compiler/java/file.cc
Expand Up @@ -248,7 +248,7 @@ void FileGenerator::Generate(io::Printer* printer) {
"filename", file_->name());
if (options_.opensource_runtime) {
printer->Print("// Protobuf Java Version: $protobuf_java_version$\n",
"protobuf_java_version", internal::kProtoJavaVersionString);
"protobuf_java_version", PROTOBUF_JAVA_VERSION_STRING);
}
if (!java_package_.empty()) {
printer->Print(
Expand Down Expand Up @@ -608,7 +608,7 @@ static void GenerateSibling(
"\n",
"filename", descriptor->file()->name());
printer.Print("// Protobuf Java Version: $protobuf_java_version$\n",
"protobuf_java_version", internal::kProtoJavaVersionString);
"protobuf_java_version", PROTOBUF_JAVA_VERSION_STRING);
if (!java_package.empty()) {
printer.Print(
"package $package$;\n"
Expand Down
2 changes: 1 addition & 1 deletion src/google/protobuf/compiler/plugin.pb.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions src/google/protobuf/compiler/python/generator.cc
Expand Up @@ -341,8 +341,7 @@ void Generator::PrintTopBoilerplate() const {
"filename", file_->name());
if (opensource_runtime_) {
printer_->Print("# Protobuf Python Version: $protobuf_python_version$\n",
"protobuf_python_version",
internal::kProtoPythonVersionString);
"protobuf_python_version", PROTOBUF_PYTHON_VERSION_STRING);
}
printer_->Print("\"\"\"Generated protocol buffer code.\"\"\"\n");
if (!opensource_runtime_) {
Expand Down
25 changes: 5 additions & 20 deletions src/google/protobuf/compiler/versions.h
Expand Up @@ -31,22 +31,10 @@
#ifndef GOOGLE_PROTOBUF_VERSIONS_H__
#define GOOGLE_PROTOBUF_VERSIONS_H__

#include "absl/strings/string_view.h"
#include "google/protobuf/compiler/versions_suffix.h"

namespace google {
namespace protobuf {
namespace compiler {
namespace internal {
// Defines compiler version strings for Protobuf code generators.
//
// Note that the version suffix "-main" implies the main branch. For example,
// 4.25-main reflects a main branch version under development towards 25.x
// release, and thus should not be used for production.
//
// Unlike other repo versions, this file should be updated together with
// version.json whenever possible and reflect the correct version numbers
// correspondingly.
//
// Currently, they are embedded into comments at each gencode for public
// Protobuf C++, Java and Python. Further, we will add version strings for rest
// of languages in version.json, and they will be used to validate version
Expand All @@ -58,11 +46,8 @@ namespace internal {
//
// Please avoid changing them manually, as they should be updated automatically
// by Protobuf release process.
constexpr absl::string_view kProtoCppVersionString = "4.25-main";
constexpr absl::string_view kProtoJavaVersionString = "3.25-main";
constexpr absl::string_view kProtoPythonVersionString = "4.25-main";
} // namespace internal
} // namespace compiler
} // namespace protobuf
} // namespace google
#define PROTOBUF_CPP_VERSION_STRING "4.24.0" PROTOBUF_GENCODE_VERSION_SUFFIX
#define PROTOBUF_JAVA_VERSION_STRING "3.24.0" PROTOBUF_GENCODE_VERSION_SUFFIX
#define PROTOBUF_PYTHON_VERSION_STRING "4.24.0" PROTOBUF_GENCODE_VERSION_SUFFIX

#endif // GOOGLE_PROTOBUF_VERSIONS_H__
26 changes: 26 additions & 0 deletions src/google/protobuf/compiler/versions_suffix.h
@@ -0,0 +1,26 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd

#ifndef GOOGLE_PROTOBUF_COMPILER_VERSIONS_SUFFIX_H__
#define GOOGLE_PROTOBUF_COMPILER_VERSIONS_SUFFIX_H__

// Defines compiler version suffix for Protobuf code generators.
//
// It is defined separately from the language-specific version strings that are
// in versions.h to prevent it from being overwritten when merging Protobuf
// release branches back to main, as the suffix "-main" should stay in the
// Protobuf github main branch.
//
// Note that the version suffix "-main" implies the main branch. For example,
// 4.25-main reflects a main branch version under development towards 25.x
// release, and thus should not be used for production.
//
// Please avoid changing it manually, as they should be updated automatically by
// the Protobuf release process.
#define PROTOBUF_GENCODE_VERSION_SUFFIX "-main"

#endif // GOOGLE_PROTOBUF_COMPILER_VERSIONS_SUFFIX_H__
2 changes: 1 addition & 1 deletion src/google/protobuf/cpp_features.pb.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/google/protobuf/descriptor.pb.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3c59585

Please sign in to comment.