Skip to content

Commit

Permalink
Setting up version updater to prepare for poison pills and embedding …
Browse files Browse the repository at this point in the history
…version info into C++, Python and Java gencode.

PiperOrigin-RevId: 562046003
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Sep 5, 2023
1 parent f7d6dd1 commit 6deeac1
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/google/protobuf/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ cc_library(
"service.h",
"text_format.h",
"unknown_field_set.h",
"versions.h",
"wire_format.h",
],
copts = COPTS,
Expand Down
11 changes: 8 additions & 3 deletions src/google/protobuf/compiler/cpp/file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,15 @@ void FileGenerator::GenerateFile(io::Printer* p, GeneratedFileType file_type,
std::function<void()> cb) {
auto v = p->WithVars(FileVars(file_, options_));
auto guard = IncludeGuard(file_, file_type, options_);
p->Print(
"// Generated by the protocol buffer compiler. DO NOT EDIT!\n"
"// source: $filename$\n");
p->Print("// Protobuf C++ Version: $protobuf_cpp_version$\n",
"protobuf_cpp_version",
absl::StrCat(internal::VersionString(GOOGLE_PROTOBUF_VERSION),
GOOGLE_PROTOBUF_VERSION_SUFFIX));
p->Print("\n");
p->Emit({{"cb", cb}, {"guard", guard}}, R"(
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: $filename$
#ifndef $guard$
#define $guard$
Expand Down
3 changes: 3 additions & 0 deletions src/google/protobuf/compiler/java/file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include "google/protobuf/dynamic_message.h"
#include "google/protobuf/io/printer.h"
#include "google/protobuf/io/zero_copy_stream.h"
#include "google/protobuf/versions.h"

// Must be last.
#include "google/protobuf/port_def.inc"
Expand Down Expand Up @@ -267,6 +268,8 @@ void FileGenerator::Generate(io::Printer* printer) {
"// source: $filename$\n"
"\n",
"filename", file_->name());
printer->Print("// Protobuf Java Version: $protobuf_java_version$\n",
"protobuf_java_version", kProtoJavaVersionString);
if (!java_package_.empty()) {
printer->Print(
"package $package$;\n"
Expand Down
7 changes: 5 additions & 2 deletions src/google/protobuf/compiler/python/generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
#include "google/protobuf/io/printer.h"
#include "google/protobuf/io/strtod.h"
#include "google/protobuf/io/zero_copy_stream.h"
#include "google/protobuf/versions.h"

namespace google {
namespace protobuf {
Expand Down Expand Up @@ -359,9 +360,11 @@ void Generator::PrintTopBoilerplate() const {
printer_->Print(
"# -*- coding: utf-8 -*-\n"
"# Generated by the protocol buffer compiler. DO NOT EDIT!\n"
"# source: $filename$\n"
"\"\"\"Generated protocol buffer code.\"\"\"\n",
"# source: $filename$\n",
"filename", file_->name());
printer_->Print("# Protobuf Python Version: $protobuf_python_version$\n",
"protobuf_python_version", kProtoPythonVersionString);
printer_->Print("\"\"\"Generated protocol buffer code.\"\"\"\n");
if (!opensource_runtime_) {
// This import is needed so that compatibility proto1 compiler output
// inserted at protoc_insertion_point can refer to other protos like
Expand Down
2 changes: 1 addition & 1 deletion src/google/protobuf/stubs/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ namespace internal {
#define GOOGLE_PROTOBUF_VERSION 4024000

// A suffix string for alpha, beta or rc releases. Empty for stable releases.
#define GOOGLE_PROTOBUF_VERSION_SUFFIX ""
#define GOOGLE_PROTOBUF_VERSION_SUFFIX "-main"

// The minimum header version which works with the current version of
// the library. This constant should only be used by protoc's C++ code
Expand Down
52 changes: 52 additions & 0 deletions src/google/protobuf/versions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#ifndef GOOGLE_PROTOBUF_VERSIONS_H__
#define GOOGLE_PROTOBUF_VERSIONS_H__

#include "absl/strings/string_view.h"
#include "google/protobuf/port_def.inc"

namespace google {
namespace protobuf {
namespace compiler {
// Versions to be injected into Protobuf language gencode.
constexpr absl::string_view kProtoJavaVersionString = "3.24.0-main";
constexpr absl::string_view kProtoCSharpVersionString = "3.24.0-main";
constexpr absl::string_view kProtoObjectiveCVersionString = "3.24.0-main";
constexpr absl::string_view kProtoPhpVersionString = "3.24.0-main";
constexpr absl::string_view kProtoPythonVersionString = "4.24.0-main";
constexpr absl::string_view kProtoRubyVersionString = "3.24.0-main";
} // namespace compiler
} // namespace protobuf
} // namespace google
#endif // GOOGLE_PROTOBUF_VERSIONS_H__

#include "google/protobuf/port_undef.inc"

0 comments on commit 6deeac1

Please sign in to comment.