Add `source_file_descriptors` to `CodeGeneratorRequest`

PiperOrigin-RevId: 542949247
pull/13134/head
Adam Cozzette 1 year ago committed by Copybara-Service
parent dc934f439f
commit 80df4b29e0
  1. 18
      cmake/tests.cmake
  2. 43
      pkg/BUILD.bazel
  3. 28
      src/google/protobuf/compiler/BUILD.bazel
  4. 23
      src/google/protobuf/compiler/command_line_interface.cc
  5. 143
      src/google/protobuf/compiler/command_line_interface_unittest.cc
  6. 63
      src/google/protobuf/compiler/fake_plugin.cc
  7. 80
      src/google/protobuf/compiler/plugin.pb.cc
  8. 65
      src/google/protobuf/compiler/plugin.pb.h
  9. 10
      src/google/protobuf/compiler/plugin.proto
  10. 5
      src/google/protobuf/io/BUILD.bazel

@ -61,6 +61,7 @@ set(tests_files
)
if(protobuf_ABSOLUTE_TEST_PLUGIN_PATH)
add_compile_options(-DGOOGLE_PROTOBUF_FAKE_PLUGIN_PATH="$<TARGET_FILE:fake_plugin>")
add_compile_options(-DGOOGLE_PROTOBUF_TEST_PLUGIN_PATH="$<TARGET_FILE:test_plugin>")
endif()
@ -102,12 +103,27 @@ target_link_libraries(tests
GTest::gmock_main
)
set(fake_plugin_files
${fake_plugin_files}
${common_test_hdrs}
${common_test_srcs}
)
set(test_plugin_files
${test_plugin_files}
${common_test_hdrs}
${common_test_srcs}
)
add_executable(fake_plugin ${fake_plugin_files})
target_include_directories(fake_plugin PRIVATE ${ABSL_ROOT_DIR})
target_link_libraries(fake_plugin
${protobuf_LIB_PROTOC}
${protobuf_LIB_PROTOBUF}
${protobuf_ABSL_USED_TARGETS}
${protobuf_ABSL_USED_TEST_TARGETS}
GTest::gmock
)
add_executable(test_plugin ${test_plugin_files})
target_include_directories(test_plugin PRIVATE ${ABSL_ROOT_DIR})
target_link_libraries(test_plugin
@ -136,7 +152,7 @@ add_test(NAME lite-test
add_custom_target(full-test
COMMAND tests
DEPENDS tests lite-test test_plugin
DEPENDS tests lite-test fake_plugin test_plugin
WORKING_DIRECTORY ${protobuf_SOURCE_DIR})
add_test(NAME full-test

@ -1,10 +1,8 @@
load("@rules_pkg//:pkg.bzl", "pkg_tar", "pkg_zip")
load("@rules_pkg//:pkg.bzl", "pkg_zip")
load(
"@rules_pkg//:mappings.bzl",
"pkg_attributes",
"pkg_filegroup",
"pkg_files",
"strip_prefix",
)
load("//:protobuf_release.bzl", "package_naming")
load(":build_systems.bzl", "gen_file_lists")
@ -123,6 +121,7 @@ gen_file_lists(
"//src/google/protobuf:test_proto_srcs": "protobuf_test_protos",
"//src/google/protobuf:lite_test_srcs": "protobuf_lite_test",
"//src/google/protobuf:lite_test_proto_srcs": "protobuf_lite_test_protos",
"//src/google/protobuf/compiler:fake_plugin_srcs": "fake_plugin",
"//src/google/protobuf/compiler:test_srcs": "compiler_test",
"//src/google/protobuf/compiler:test_proto_srcs": "compiler_test_protos",
"//src/google/protobuf/compiler:test_plugin_srcs": "test_plugin",
@ -162,8 +161,8 @@ cc_dist_library(
tags = ["manual"],
deps = [
"//src/google/protobuf:arena_align",
"//src/google/protobuf:protobuf_nowkt",
"//src/google/protobuf:cmake_wkt_cc_proto",
"//src/google/protobuf:protobuf_nowkt",
"//src/google/protobuf/compiler:importer",
"//src/google/protobuf/json",
"//src/google/protobuf/util:delimited_message_util",
@ -177,6 +176,10 @@ cc_dist_library(
cc_dist_library(
name = "protoc",
dist_deps = [
":protobuf",
":protobuf_lite",
],
tags = ["manual"],
deps = [
"//src/google/protobuf/compiler:command_line_interface",
@ -189,44 +192,45 @@ cc_dist_library(
"//src/google/protobuf/compiler/ruby",
"//src/google/protobuf/compiler/rust",
],
dist_deps = [
":protobuf",
":protobuf_lite",
],
)
cc_dist_library(
name = "lite_test_util",
testonly = 1,
dist_deps = [":protobuf"],
tags = ["manual"],
deps = ["//src/google/protobuf:lite_test_util"],
dist_deps = [":protobuf"],
)
cc_dist_library(
name = "test_util",
testonly = 1,
dist_deps = [
":common_test",
":lite_test_util",
":protoc",
":protobuf",
":protobuf_lite",
],
tags = ["manual"],
deps = [
"//src/google/protobuf:lite_test_util",
"//src/google/protobuf:test_util",
"//src/google/protobuf:test_util2",
"//src/google/protobuf/io:test_zero_copy_stream",
"//src/google/protobuf/compiler:annotation_test_util",
"//src/google/protobuf/compiler/cpp:unittest_lib",
],
dist_deps = [
":common_test",
":lite_test_util",
":protoc",
":protobuf",
":protobuf_lite",
"//src/google/protobuf/io:test_zero_copy_stream",
],
)
cc_dist_library(
name = "common_test",
testonly = 1,
dist_deps = [
":protobuf",
":protobuf_lite",
":protoc",
],
tags = ["manual"],
deps = [
"//src/google/protobuf:test_textproto",
@ -234,9 +238,4 @@ cc_dist_library(
"//src/google/protobuf/compiler:mock_code_generator",
"//src/google/protobuf/testing",
],
dist_deps = [
":protobuf",
":protobuf_lite",
":protoc",
],
)

@ -2,7 +2,7 @@
# Protocol Buffers Compiler
################################################################################
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test")
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_proto_library", "cc_test")
load(
"@rules_pkg//:mappings.bzl",
"pkg_attributes",
@ -24,6 +24,12 @@ proto_library(
deps = ["//:descriptor_proto"],
)
cc_proto_library(
name = "plugin_cc_proto",
visibility = ["//visibility:public"],
deps = [":plugin_proto"],
)
cc_library(
name = "importer",
srcs = [
@ -63,6 +69,7 @@ cc_library(
visibility = ["//visibility:public"],
deps = [
"//src/google/protobuf:protobuf_nowkt",
"//src/google/protobuf/io:io_win32",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/log:absl_check",
"@com_google_absl//absl/log:absl_log",
@ -230,6 +237,17 @@ cc_binary(
],
)
cc_binary(
name = "fake_plugin",
testonly = True,
srcs = ["fake_plugin.cc"],
deps = [
":plugin_cc_proto",
"@com_google_absl//absl/log:absl_check",
"@com_google_absl//absl/strings",
],
)
cc_test(
name = "command_line_interface_unittest",
srcs = ["command_line_interface_unittest.cc"],
@ -241,9 +259,11 @@ cc_test(
],
}) + [
# Note: This only works on Windows with symlinks and runfiles enabled.
"-DGOOGLE_PROTOBUF_FAKE_PLUGIN_PATH=\\\"$(rootpath :fake_plugin)\\\"",
"-DGOOGLE_PROTOBUF_TEST_PLUGIN_PATH=\\\"$(rootpath :test_plugin)\\\"",
],
data = [
":fake_plugin",
":test_plugin",
"//:test_proto_srcs",
"//src/google/protobuf:descriptor_proto_srcs",
@ -422,6 +442,12 @@ filegroup(
visibility = ["//pkg:__pkg__"],
)
filegroup(
name = "fake_plugin_srcs",
srcs = ["fake_plugin.cc"],
visibility = ["//pkg:__pkg__"],
)
filegroup(
name = "test_plugin_srcs",
srcs = ["test_plugin.cc"],

@ -2582,15 +2582,30 @@ bool CommandLineInterface::GeneratePluginOutput(
absl::flat_hash_set<const FileDescriptor*> already_seen;
for (int i = 0; i < parsed_files.size(); i++) {
request.add_file_to_generate(parsed_files[i]->name());
GetTransitiveDependencies(parsed_files[i], &already_seen,
request.mutable_proto_file(),
for (const FileDescriptor* file : parsed_files) {
request.add_file_to_generate(file->name());
GetTransitiveDependencies(file, &already_seen, request.mutable_proto_file(),
{/*.include_json_name =*/true,
/*.include_source_code_info =*/true,
/*.retain_options =*/true});
}
// Populate source_file_descriptors and remove source-retention options from
// proto_file.
ABSL_CHECK(!parsed_files.empty());
const DescriptorPool* pool = parsed_files[0]->pool();
absl::flat_hash_set<std::string> files_to_generate(input_files_.begin(),
input_files_.end());
for (FileDescriptorProto& file_proto : *request.mutable_proto_file()) {
if (files_to_generate.contains(file_proto.name())) {
const FileDescriptor* file = pool->FindFileByName(file_proto.name());
*request.add_source_file_descriptors() = std::move(file_proto);
file_proto = StripSourceRetentionOptions(*file);
file->CopySourceCodeInfoTo(&file_proto);
file->CopyJsonNameTo(&file_proto);
}
}
google::protobuf::compiler::Version* version =
request.mutable_compiler_version();
version->set_major(PROTOBUF_VERSION / 1000000);

@ -64,6 +64,7 @@
#include "google/protobuf/compiler/command_line_interface.h"
#include "google/protobuf/compiler/cpp/names.h"
#include "google/protobuf/compiler/mock_code_generator.h"
#include "google/protobuf/compiler/plugin.pb.h"
#include "google/protobuf/compiler/subprocess.h"
#include "google/protobuf/io/io_win32.h"
#include "google/protobuf/test_util2.h"
@ -190,6 +191,7 @@ class CommandLineInterfaceTest : public CommandLineInterfaceTester {
#endif // _WIN32
std::string ReadFile(absl::string_view filename);
void ReadDescriptorSet(absl::string_view filename,
FileDescriptorSet* descriptor_set);
@ -318,14 +320,18 @@ void CommandLineInterfaceTest::ExpectNullCodeGeneratorCalled(
#endif // _WIN32
void CommandLineInterfaceTest::ReadDescriptorSet(
absl::string_view filename, FileDescriptorSet* descriptor_set) {
std::string CommandLineInterfaceTest::ReadFile(absl::string_view filename) {
std::string path = absl::StrCat(temp_directory(), "/", filename);
std::string file_contents;
ABSL_CHECK_OK(File::GetContents(path, &file_contents, true));
return file_contents;
}
void CommandLineInterfaceTest::ReadDescriptorSet(
absl::string_view filename, FileDescriptorSet* descriptor_set) {
std::string file_contents = ReadFile(filename);
if (!descriptor_set->ParseFromString(file_contents)) {
FAIL() << "Could not parse file contents: " << path;
FAIL() << "Could not parse file contents: " << filename;
}
}
@ -399,6 +405,137 @@ TEST_F(CommandLineInterfaceTest, BasicPlugin_DescriptorSetIn) {
ExpectGenerated("test_plugin", "", "foo.proto", "Foo");
}
TEST_F(CommandLineInterfaceTest, Plugin_OptionRetention) {
CreateTempFile("foo.proto",
R"pb(syntax = "proto2"
;
import "bar.proto";
package foo;
message Foo {
optional bar.Bar b = 1;
extensions 1000 to max [
declaration = {
number: 1000
full_name: ".foo.my_ext"
type: ".foo.MyType"
}
];
})pb");
CreateTempFile("bar.proto",
R"pb(syntax = "proto2"
;
package bar;
message Bar {
extensions 1000 to max [
declaration = {
number: 1000
full_name: ".baz.my_ext"
type: ".baz.MyType"
}
];
})pb");
#ifdef GOOGLE_PROTOBUF_FAKE_PLUGIN_PATH
std::string plugin_path = GOOGLE_PROTOBUF_FAKE_PLUGIN_PATH;
#else
std::string plugin_path = absl::StrCat(
TestUtil::TestSourceDir(), "/third_party/protobuf/compiler/fake_plugin");
#endif
// Invoke protoc with fake_plugin to get ahold of the CodeGeneratorRequest
// sent by protoc.
Run(absl::StrCat(
"protocol_compiler --fake_plugin_out=$tmpdir --proto_path=$tmpdir "
"foo.proto --plugin=prefix-gen-fake_plugin=",
plugin_path));
ExpectNoErrors();
std::string base64_output = ReadFile("foo.proto.request");
std::string binary_request;
ASSERT_TRUE(absl::Base64Unescape(base64_output, &binary_request));
CodeGeneratorRequest request;
ASSERT_TRUE(request.ParseFromString(binary_request));
// request.proto_file() should include source-retention options for bar.proto
// but not for foo.proto. Protoc should strip source-retention options from
// the immediate proto files being built, but not for all dependencies.
ASSERT_EQ(request.proto_file_size(), 2);
{
EXPECT_EQ(request.proto_file(0).name(), "bar.proto");
ASSERT_EQ(request.proto_file(0).message_type_size(), 1);
const DescriptorProto& m = request.proto_file(0).message_type(0);
ASSERT_EQ(m.extension_range_size(), 1);
EXPECT_EQ(m.extension_range(0).options().declaration_size(), 1);
}
{
EXPECT_EQ(request.proto_file(1).name(), "foo.proto");
ASSERT_EQ(request.proto_file(1).message_type_size(), 1);
const DescriptorProto& m = request.proto_file(1).message_type(0);
ASSERT_EQ(m.extension_range_size(), 1);
EXPECT_TRUE(m.extension_range(0).options().declaration().empty());
}
}
TEST_F(CommandLineInterfaceTest, Plugin_SourceFileDescriptors) {
CreateTempFile("foo.proto",
R"pb(syntax = "proto2"
;
import "bar.proto";
package foo;
message Foo {
optional bar.Bar b = 1;
extensions 1000 to max [
declaration = {
number: 1000
full_name: ".foo.my_ext"
type: ".foo.MyType"
}
];
})pb");
CreateTempFile("bar.proto",
R"pb(syntax = "proto2"
;
package bar;
message Bar {
extensions 1000 to max [
declaration = {
number: 1000
full_name: ".baz.my_ext"
type: ".baz.MyType"
}
];
})pb");
#ifdef GOOGLE_PROTOBUF_FAKE_PLUGIN_PATH
std::string plugin_path = GOOGLE_PROTOBUF_FAKE_PLUGIN_PATH;
#else
std::string plugin_path = absl::StrCat(
TestUtil::TestSourceDir(), "/third_party/protobuf/compiler/fake_plugin");
#endif
// Invoke protoc with fake_plugin to get ahold of the CodeGeneratorRequest
// sent by protoc.
Run(absl::StrCat(
"protocol_compiler --fake_plugin_out=$tmpdir --proto_path=$tmpdir "
"foo.proto --plugin=prefix-gen-fake_plugin=",
plugin_path));
ExpectNoErrors();
std::string base64_output = ReadFile("foo.proto.request");
std::string binary_request;
ASSERT_TRUE(absl::Base64Unescape(base64_output, &binary_request));
CodeGeneratorRequest request;
ASSERT_TRUE(request.ParseFromString(binary_request));
// request.source_file_descriptors() should consist of a descriptor for
// foo.proto that includes source-retention options.
ASSERT_EQ(request.source_file_descriptors_size(), 1);
EXPECT_EQ(request.source_file_descriptors(0).name(), "foo.proto");
ASSERT_EQ(request.source_file_descriptors(0).message_type_size(), 1);
const DescriptorProto& m = request.source_file_descriptors(0).message_type(0);
ASSERT_EQ(m.extension_range_size(), 1);
EXPECT_EQ(m.extension_range(0).options().declaration_size(), 1);
}
TEST_F(CommandLineInterfaceTest, GeneratorAndPlugin) {
// Invoke a generator and a plugin at the same time.

@ -0,0 +1,63 @@
// 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.
#ifdef _WIN32
#include <fcntl.h>
#else
#include <unistd.h>
#endif
#include "absl/log/absl_check.h"
#include "absl/strings/escaping.h"
#include "google/protobuf/compiler/plugin.pb.h"
#include "google/protobuf/io/io_win32.h"
// This fake protoc plugin does nothing but write out the CodeGeneratorRequest
// in base64. This is not very useful except that it gives us a way to make
// assertions in tests about the contents of requests that protoc sends to
// plugins.
int main(int argc, char* argv[]) {
#ifdef _WIN32
google::protobuf::io::win32::setmode(STDIN_FILENO, _O_BINARY);
google::protobuf::io::win32::setmode(STDOUT_FILENO, _O_BINARY);
#endif
google::protobuf::compiler::CodeGeneratorRequest request;
ABSL_CHECK(request.ParseFromFileDescriptor(STDIN_FILENO));
ABSL_CHECK(!request.file_to_generate().empty());
google::protobuf::compiler::CodeGeneratorResponse response;
response.add_file()->set_name(
absl::StrCat(request.file_to_generate(0), ".request"));
response.mutable_file(0)->set_content(
absl::Base64Escape(request.SerializeAsString()));
ABSL_CHECK(response.SerializeToFileDescriptor(STDOUT_FILENO));
return 0;
}

@ -53,6 +53,7 @@ PROTOBUF_CONSTEXPR CodeGeneratorRequest::CodeGeneratorRequest(::_pbi::ConstantIn
/*decltype(_impl_._cached_size_)*/ {},
/*decltype(_impl_.file_to_generate_)*/ {},
/*decltype(_impl_.proto_file_)*/ {},
/*decltype(_impl_.source_file_descriptors_)*/ {},
/*decltype(_impl_.parameter_)*/ {
&::_pbi::fixed_address_empty_string,
::_pbi::ConstantInitialized{},
@ -156,10 +157,12 @@ const ::uint32_t TableStruct_google_2fprotobuf_2fcompiler_2fplugin_2eproto::offs
PROTOBUF_FIELD_OFFSET(::google::protobuf::compiler::CodeGeneratorRequest, _impl_.file_to_generate_),
PROTOBUF_FIELD_OFFSET(::google::protobuf::compiler::CodeGeneratorRequest, _impl_.parameter_),
PROTOBUF_FIELD_OFFSET(::google::protobuf::compiler::CodeGeneratorRequest, _impl_.proto_file_),
PROTOBUF_FIELD_OFFSET(::google::protobuf::compiler::CodeGeneratorRequest, _impl_.source_file_descriptors_),
PROTOBUF_FIELD_OFFSET(::google::protobuf::compiler::CodeGeneratorRequest, _impl_.compiler_version_),
~0u,
0,
~0u,
~0u,
1,
PROTOBUF_FIELD_OFFSET(::google::protobuf::compiler::CodeGeneratorResponse_File, _impl_._has_bits_),
PROTOBUF_FIELD_OFFSET(::google::protobuf::compiler::CodeGeneratorResponse_File, _internal_metadata_),
@ -196,9 +199,9 @@ const ::uint32_t TableStruct_google_2fprotobuf_2fcompiler_2fplugin_2eproto::offs
static const ::_pbi::MigrationSchema
schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = {
{0, 12, -1, sizeof(::google::protobuf::compiler::Version)},
{16, 28, -1, sizeof(::google::protobuf::compiler::CodeGeneratorRequest)},
{32, 44, -1, sizeof(::google::protobuf::compiler::CodeGeneratorResponse_File)},
{48, 59, -1, sizeof(::google::protobuf::compiler::CodeGeneratorResponse)},
{16, 29, -1, sizeof(::google::protobuf::compiler::CodeGeneratorRequest)},
{34, 46, -1, sizeof(::google::protobuf::compiler::CodeGeneratorResponse_File)},
{50, 61, -1, sizeof(::google::protobuf::compiler::CodeGeneratorResponse)},
};
static const ::_pb::Message* const file_default_instances[] = {
@ -212,22 +215,24 @@ const char descriptor_table_protodef_google_2fprotobuf_2fcompiler_2fplugin_2epro
"\030google.protobuf.compiler\032 google/protob"
"uf/descriptor.proto\"F\n\007Version\022\r\n\005major\030"
"\001 \001(\005\022\r\n\005minor\030\002 \001(\005\022\r\n\005patch\030\003 \001(\005\022\016\n\006s"
"uffix\030\004 \001(\t\"\272\001\n\024CodeGeneratorRequest\022\030\n\020"
"uffix\030\004 \001(\t\"\201\002\n\024CodeGeneratorRequest\022\030\n\020"
"file_to_generate\030\001 \003(\t\022\021\n\tparameter\030\002 \001("
"\t\0228\n\nproto_file\030\017 \003(\0132$.google.protobuf."
"FileDescriptorProto\022;\n\020compiler_version\030"
"\003 \001(\0132!.google.protobuf.compiler.Version"
"\"\301\002\n\025CodeGeneratorResponse\022\r\n\005error\030\001 \001("
"\t\022\032\n\022supported_features\030\002 \001(\004\022B\n\004file\030\017 "
"\003(\01324.google.protobuf.compiler.CodeGener"
"atorResponse.File\032\177\n\004File\022\014\n\004name\030\001 \001(\t\022"
"\027\n\017insertion_point\030\002 \001(\t\022\017\n\007content\030\017 \001("
"\t\022\?\n\023generated_code_info\030\020 \001(\0132\".google."
"protobuf.GeneratedCodeInfo\"8\n\007Feature\022\020\n"
"\014FEATURE_NONE\020\000\022\033\n\027FEATURE_PROTO3_OPTION"
"AL\020\001Br\n\034com.google.protobuf.compilerB\014Pl"
"uginProtosZ)google.golang.org/protobuf/t"
"ypes/pluginpb\252\002\030Google.Protobuf.Compiler"
"FileDescriptorProto\022E\n\027source_file_descr"
"iptors\030\021 \003(\0132$.google.protobuf.FileDescr"
"iptorProto\022;\n\020compiler_version\030\003 \001(\0132!.g"
"oogle.protobuf.compiler.Version\"\301\002\n\025Code"
"GeneratorResponse\022\r\n\005error\030\001 \001(\t\022\032\n\022supp"
"orted_features\030\002 \001(\004\022B\n\004file\030\017 \003(\01324.goo"
"gle.protobuf.compiler.CodeGeneratorRespo"
"nse.File\032\177\n\004File\022\014\n\004name\030\001 \001(\t\022\027\n\017insert"
"ion_point\030\002 \001(\t\022\017\n\007content\030\017 \001(\t\022\?\n\023gene"
"rated_code_info\030\020 \001(\0132\".google.protobuf."
"GeneratedCodeInfo\"8\n\007Feature\022\020\n\014FEATURE_"
"NONE\020\000\022\033\n\027FEATURE_PROTO3_OPTIONAL\020\001Br\n\034c"
"om.google.protobuf.compilerB\014PluginProto"
"sZ)google.golang.org/protobuf/types/plug"
"inpb\252\002\030Google.Protobuf.Compiler"
};
static const ::_pbi::DescriptorTable* const descriptor_table_google_2fprotobuf_2fcompiler_2fplugin_2eproto_deps[1] =
{
@ -237,7 +242,7 @@ static ::absl::once_flag descriptor_table_google_2fprotobuf_2fcompiler_2fplugin_
const ::_pbi::DescriptorTable descriptor_table_google_2fprotobuf_2fcompiler_2fplugin_2eproto = {
false,
false,
800,
871,
descriptor_table_protodef_google_2fprotobuf_2fcompiler_2fplugin_2eproto,
"google/protobuf/compiler/plugin.proto",
&descriptor_table_google_2fprotobuf_2fcompiler_2fplugin_2eproto_once,
@ -625,6 +630,9 @@ const ::google::protobuf::compiler::Version& CodeGeneratorRequest::_Internal::co
void CodeGeneratorRequest::clear_proto_file() {
_internal_mutable_proto_file()->Clear();
}
void CodeGeneratorRequest::clear_source_file_descriptors() {
_internal_mutable_source_file_descriptors()->Clear();
}
CodeGeneratorRequest::CodeGeneratorRequest(::google::protobuf::Arena* arena)
: ::google::protobuf::Message(arena) {
SharedCtor(arena);
@ -638,6 +646,7 @@ CodeGeneratorRequest::CodeGeneratorRequest(const CodeGeneratorRequest& from) : :
/*decltype(_impl_._cached_size_)*/ {},
decltype(_impl_.file_to_generate_){from._impl_.file_to_generate_},
decltype(_impl_.proto_file_){from._impl_.proto_file_},
decltype(_impl_.source_file_descriptors_){from._impl_.source_file_descriptors_},
decltype(_impl_.parameter_){},
decltype(_impl_.compiler_version_){nullptr},
};
@ -663,6 +672,7 @@ inline void CodeGeneratorRequest::SharedCtor(::_pb::Arena* arena) {
/*decltype(_impl_._cached_size_)*/ {},
decltype(_impl_.file_to_generate_){arena},
decltype(_impl_.proto_file_){arena},
decltype(_impl_.source_file_descriptors_){arena},
decltype(_impl_.parameter_){},
decltype(_impl_.compiler_version_){nullptr},
};
@ -680,6 +690,7 @@ inline void CodeGeneratorRequest::SharedDtor() {
ABSL_DCHECK(GetArenaForAllocation() == nullptr);
_internal_mutable_file_to_generate()->~RepeatedPtrField();
_impl_.proto_file_.~RepeatedPtrField();
_impl_.source_file_descriptors_.~RepeatedPtrField();
_impl_.parameter_.Destroy();
if (this != internal_default_instance()) delete _impl_.compiler_version_;
}
@ -695,6 +706,7 @@ PROTOBUF_NOINLINE void CodeGeneratorRequest::Clear() {
_internal_mutable_file_to_generate()->Clear();
_internal_mutable_proto_file()->Clear();
_internal_mutable_source_file_descriptors()->Clear();
cached_has_bits = _impl_._has_bits_[0];
if (cached_has_bits & 0x00000003u) {
if (cached_has_bits & 0x00000001u) {
@ -717,16 +729,16 @@ const char* CodeGeneratorRequest::_InternalParse(
PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1
const ::_pbi::TcParseTable<3, 4, 2, 79, 2> CodeGeneratorRequest::_table_ = {
const ::_pbi::TcParseTable<3, 5, 3, 79, 2> CodeGeneratorRequest::_table_ = {
{
PROTOBUF_FIELD_OFFSET(CodeGeneratorRequest, _impl_._has_bits_),
0, // no _extensions_
15, 56, // max_field_number, fast_idx_mask
17, 56, // max_field_number, fast_idx_mask
offsetof(decltype(_table_), field_lookup_table),
4294950904, // skipmap
4294885368, // skipmap
offsetof(decltype(_table_), field_entries),
4, // num_field_entries
2, // num_aux_entries
5, // num_field_entries
3, // num_aux_entries
offsetof(decltype(_table_), aux_entries),
&_CodeGeneratorRequest_default_instance_._instance,
::_pbi::TcParser::GenericFallback, // fallback
@ -762,9 +774,13 @@ const ::_pbi::TcParseTable<3, 4, 2, 79, 2> CodeGeneratorRequest::_table_ = {
// repeated .google.protobuf.FileDescriptorProto proto_file = 15;
{PROTOBUF_FIELD_OFFSET(CodeGeneratorRequest, _impl_.proto_file_), -1, 1,
(0 | ::_fl::kFcRepeated | ::_fl::kMessage | ::_fl::kTvTable)},
// repeated .google.protobuf.FileDescriptorProto source_file_descriptors = 17;
{PROTOBUF_FIELD_OFFSET(CodeGeneratorRequest, _impl_.source_file_descriptors_), -1, 2,
(0 | ::_fl::kFcRepeated | ::_fl::kMessage | ::_fl::kTvTable)},
}}, {{
{::_pbi::TcParser::GetTable<::google::protobuf::compiler::Version>()},
{::_pbi::TcParser::GetTable<::google::protobuf::FileDescriptorProto>()},
{::_pbi::TcParser::GetTable<::google::protobuf::FileDescriptorProto>()},
}}, {{
"\55\20\11\0\0\0\0\0"
"google.protobuf.compiler.CodeGeneratorRequest"
@ -812,6 +828,14 @@ const ::_pbi::TcParseTable<3, 4, 2, 79, 2> CodeGeneratorRequest::_table_ = {
InternalWriteMessage(15, repfield, repfield.GetCachedSize(), target, stream);
}
// repeated .google.protobuf.FileDescriptorProto source_file_descriptors = 17;
for (unsigned i = 0,
n = static_cast<unsigned>(this->_internal_source_file_descriptors_size()); i < n; i++) {
const auto& repfield = this->_internal_source_file_descriptors().Get(i);
target = ::google::protobuf::internal::WireFormatLite::
InternalWriteMessage(17, repfield, repfield.GetCachedSize(), target, stream);
}
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
target =
::_pbi::WireFormat::InternalSerializeUnknownFieldsToArray(
@ -841,6 +865,12 @@ const ::_pbi::TcParseTable<3, 4, 2, 79, 2> CodeGeneratorRequest::_table_ = {
total_size +=
::google::protobuf::internal::WireFormatLite::MessageSize(msg);
}
// repeated .google.protobuf.FileDescriptorProto source_file_descriptors = 17;
total_size += 2UL * this->_internal_source_file_descriptors_size();
for (const auto& msg : this->_internal_source_file_descriptors()) {
total_size +=
::google::protobuf::internal::WireFormatLite::MessageSize(msg);
}
cached_has_bits = _impl_._has_bits_[0];
if (cached_has_bits & 0x00000003u) {
// optional string parameter = 2;
@ -877,6 +907,7 @@ void CodeGeneratorRequest::MergeImpl(::google::protobuf::Message& to_msg, const
_this->_internal_mutable_file_to_generate()->MergeFrom(from._internal_file_to_generate());
_this->_internal_mutable_proto_file()->MergeFrom(from._internal_proto_file());
_this->_internal_mutable_source_file_descriptors()->MergeFrom(from._internal_source_file_descriptors());
cached_has_bits = from._impl_._has_bits_[0];
if (cached_has_bits & 0x00000003u) {
if (cached_has_bits & 0x00000001u) {
@ -900,6 +931,8 @@ void CodeGeneratorRequest::CopyFrom(const CodeGeneratorRequest& from) {
PROTOBUF_NOINLINE bool CodeGeneratorRequest::IsInitialized() const {
if (!::google::protobuf::internal::AllAreInitialized(_internal_proto_file()))
return false;
if (!::google::protobuf::internal::AllAreInitialized(_internal_source_file_descriptors()))
return false;
return true;
}
@ -912,6 +945,7 @@ void CodeGeneratorRequest::InternalSwap(CodeGeneratorRequest* other) {
_internal_mutable_file_to_generate()->InternalSwap(
other->_internal_mutable_file_to_generate());
_internal_mutable_proto_file()->InternalSwap(other->_internal_mutable_proto_file());
_internal_mutable_source_file_descriptors()->InternalSwap(other->_internal_mutable_source_file_descriptors());
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.parameter_, lhs_arena,
&other->_impl_.parameter_, rhs_arena);
swap(_impl_.compiler_version_, other->_impl_.compiler_version_);

@ -460,6 +460,7 @@ class PROTOC_EXPORT CodeGeneratorRequest final :
enum : int {
kFileToGenerateFieldNumber = 1,
kProtoFileFieldNumber = 15,
kSourceFileDescriptorsFieldNumber = 17,
kParameterFieldNumber = 2,
kCompilerVersionFieldNumber = 3,
};
@ -509,6 +510,24 @@ class PROTOC_EXPORT CodeGeneratorRequest final :
::google::protobuf::FileDescriptorProto* add_proto_file();
const ::google::protobuf::RepeatedPtrField< ::google::protobuf::FileDescriptorProto >&
proto_file() const;
// repeated .google.protobuf.FileDescriptorProto source_file_descriptors = 17;
int source_file_descriptors_size() const;
private:
int _internal_source_file_descriptors_size() const;
public:
void clear_source_file_descriptors() ;
::google::protobuf::FileDescriptorProto* mutable_source_file_descriptors(int index);
::google::protobuf::RepeatedPtrField< ::google::protobuf::FileDescriptorProto >*
mutable_source_file_descriptors();
private:
const ::google::protobuf::RepeatedPtrField<::google::protobuf::FileDescriptorProto>& _internal_source_file_descriptors() const;
::google::protobuf::RepeatedPtrField<::google::protobuf::FileDescriptorProto>* _internal_mutable_source_file_descriptors();
public:
const ::google::protobuf::FileDescriptorProto& source_file_descriptors(int index) const;
::google::protobuf::FileDescriptorProto* add_source_file_descriptors();
const ::google::protobuf::RepeatedPtrField< ::google::protobuf::FileDescriptorProto >&
source_file_descriptors() const;
// optional string parameter = 2;
bool has_parameter() const;
void clear_parameter() ;
@ -546,7 +565,7 @@ class PROTOC_EXPORT CodeGeneratorRequest final :
class _Internal;
friend class ::google::protobuf::internal::TcParser;
static const ::google::protobuf::internal::TcParseTable<3, 4, 2, 79, 2> _table_;
static const ::google::protobuf::internal::TcParseTable<3, 5, 3, 79, 2> _table_;
template <typename T> friend class ::google::protobuf::Arena::InternalHelper;
typedef void InternalArenaConstructable_;
typedef void DestructorSkippable_;
@ -555,6 +574,7 @@ class PROTOC_EXPORT CodeGeneratorRequest final :
mutable ::google::protobuf::internal::CachedSize _cached_size_;
::google::protobuf::RepeatedPtrField<std::string> file_to_generate_;
::google::protobuf::RepeatedPtrField< ::google::protobuf::FileDescriptorProto > proto_file_;
::google::protobuf::RepeatedPtrField< ::google::protobuf::FileDescriptorProto > source_file_descriptors_;
::google::protobuf::internal::ArenaStringPtr parameter_;
::google::protobuf::compiler::Version* compiler_version_;
PROTOBUF_TSAN_DECLARE_MEMBER;
@ -1383,6 +1403,49 @@ CodeGeneratorRequest::_internal_mutable_proto_file() {
return &_impl_.proto_file_;
}
// repeated .google.protobuf.FileDescriptorProto source_file_descriptors = 17;
inline int CodeGeneratorRequest::_internal_source_file_descriptors_size() const {
return _internal_source_file_descriptors().size();
}
inline int CodeGeneratorRequest::source_file_descriptors_size() const {
return _internal_source_file_descriptors_size();
}
inline ::google::protobuf::FileDescriptorProto* CodeGeneratorRequest::mutable_source_file_descriptors(int index) {
// @@protoc_insertion_point(field_mutable:google.protobuf.compiler.CodeGeneratorRequest.source_file_descriptors)
return _internal_mutable_source_file_descriptors()->Mutable(index);
}
inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::FileDescriptorProto >*
CodeGeneratorRequest::mutable_source_file_descriptors() {
// @@protoc_insertion_point(field_mutable_list:google.protobuf.compiler.CodeGeneratorRequest.source_file_descriptors)
PROTOBUF_TSAN_WRITE_REPEATED(&_impl_._tsan_detect_race);
return _internal_mutable_source_file_descriptors();
}
inline const ::google::protobuf::FileDescriptorProto& CodeGeneratorRequest::source_file_descriptors(int index) const {
// @@protoc_insertion_point(field_get:google.protobuf.compiler.CodeGeneratorRequest.source_file_descriptors)
return _internal_source_file_descriptors().Get(index);
}
inline ::google::protobuf::FileDescriptorProto* CodeGeneratorRequest::add_source_file_descriptors() {
PROTOBUF_TSAN_WRITE_REPEATED(&_impl_._tsan_detect_race);
::google::protobuf::FileDescriptorProto* _add = _internal_mutable_source_file_descriptors()->Add();
// @@protoc_insertion_point(field_add:google.protobuf.compiler.CodeGeneratorRequest.source_file_descriptors)
return _add;
}
inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::FileDescriptorProto >&
CodeGeneratorRequest::source_file_descriptors() const {
// @@protoc_insertion_point(field_list:google.protobuf.compiler.CodeGeneratorRequest.source_file_descriptors)
return _internal_source_file_descriptors();
}
inline const ::google::protobuf::RepeatedPtrField<::google::protobuf::FileDescriptorProto>&
CodeGeneratorRequest::_internal_source_file_descriptors() const {
PROTOBUF_TSAN_READ_REPEATED(&_impl_._tsan_detect_race);
return _impl_.source_file_descriptors_;
}
inline ::google::protobuf::RepeatedPtrField<::google::protobuf::FileDescriptorProto>*
CodeGeneratorRequest::_internal_mutable_source_file_descriptors() {
PROTOBUF_TSAN_READ_REPEATED(&_impl_._tsan_detect_race);
return &_impl_.source_file_descriptors_;
}
// optional .google.protobuf.compiler.Version compiler_version = 3;
inline bool CodeGeneratorRequest::has_compiler_version() const {
bool value = (_impl_._has_bits_[0] & 0x00000002u) != 0;

@ -76,6 +76,11 @@ message CodeGeneratorRequest {
// they import. The files will appear in topological order, so each file
// appears before any file that imports it.
//
// Note: the files listed in files_to_generate will include runtime-retention
// options only, but all other files will include source-retention options.
// The source_file_descriptors field below is available in case you need
// source-retention options for files_to_generate.
//
// protoc guarantees that all proto_files will be written after
// the fields above, even though this is not technically guaranteed by the
// protobuf wire format. This theoretically could allow a plugin to stream
@ -88,6 +93,11 @@ message CodeGeneratorRequest {
// fully qualified.
repeated FileDescriptorProto proto_file = 15;
// File descriptors with all options, including source-retention options.
// These descriptors are only provided for the files listed in
// files_to_generate.
repeated FileDescriptorProto source_file_descriptors = 17;
// The version number of protocol compiler.
optional Version compiler_version = 3;
}

@ -152,7 +152,10 @@ cc_library(
hdrs = ["io_win32.h"],
copts = COPTS,
include_prefix = "google/protobuf/io",
visibility = ["//pkg:__pkg__"],
visibility = [
"//pkg:__pkg__",
"//src/google/protobuf/compiler:__pkg__",
],
deps = [
"//src/google/protobuf:arena",
"//src/google/protobuf/stubs:lite",

Loading…
Cancel
Save