diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc index 8d4e455d38..6820f077a3 100644 --- a/src/google/protobuf/compiler/command_line_interface.cc +++ b/src/google/protobuf/compiler/command_line_interface.cc @@ -284,6 +284,16 @@ std::string PluginName(absl::string_view plugin_prefix, directive.substr(2, directive.size() - 6)); } +bool GetBootstrapParam(const std::string& parameter) { + std::vector parts = absl::StrSplit(parameter, ','); + for (const auto& part : parts) { + if (part == "bootstrap") { + return true; + } + } + return false; +} + bool EnforceEditionsSupport( const std::string& codegen_name, uint64_t supported_features, @@ -2700,6 +2710,7 @@ bool CommandLineInterface::GeneratePluginOutput( CodeGeneratorResponse response; std::string processed_parameter = parameter; + bool bootstrap = GetBootstrapParam(processed_parameter); // Build the request. if (!processed_parameter.empty()) { @@ -2727,8 +2738,11 @@ bool CommandLineInterface::GeneratePluginOutput( const FileDescriptor* file = pool->FindFileByName(file_proto.name()); *request.add_source_file_descriptors() = std::move(file_proto); file->CopyTo(&file_proto); - file->CopySourceCodeInfoTo(&file_proto); - file->CopyJsonNameTo(&file_proto); + // Don't populate source code info or json_name for bootstrap protos. + if (!bootstrap) { + file->CopySourceCodeInfoTo(&file_proto); + file->CopyJsonNameTo(&file_proto); + } StripSourceRetentionOptions(*file->pool(), file_proto); } } diff --git a/src/google/protobuf/compiler/cpp/file.cc b/src/google/protobuf/compiler/cpp/file.cc index 8e29ea3ef9..700b0c95c4 100644 --- a/src/google/protobuf/compiler/cpp/file.cc +++ b/src/google/protobuf/compiler/cpp/file.cc @@ -652,7 +652,7 @@ void FileGenerator::GenerateSourceIncludes(io::Printer* p) { if (ShouldSkipDependencyImports(dep)) continue; std::string basename = StripProto(dep->name()); - if (IsBootstrapProto(options_, file_)) { + if (options_.bootstrap) { GetBootstrapBasename(options_, basename, &basename); } p->Emit({{"name", basename}}, R"( @@ -1642,7 +1642,7 @@ void FileGenerator::GenerateDependencyIncludes(io::Printer* p) { } std::string basename = StripProto(dep->name()); - if (IsBootstrapProto(options_, file_)) { + if (options_.bootstrap) { GetBootstrapBasename(options_, basename, &basename); } diff --git a/src/google/protobuf/compiler/cpp/main.cc b/src/google/protobuf/compiler/cpp/main.cc new file mode 100644 index 0000000000..eae03b1434 --- /dev/null +++ b/src/google/protobuf/compiler/cpp/main.cc @@ -0,0 +1,18 @@ +// 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 + +#include "google/protobuf/compiler/cpp/generator.h" +#include "google/protobuf/compiler/plugin.h" + +int main(int argc, char *argv[]) { + ::google::protobuf::compiler::cpp::CppGenerator generator; +#ifdef GOOGLE_PROTOBUF_RUNTIME_INCLUDE_BASE + generator.set_opensource_runtime(true); + generator.set_runtime_include_base(GOOGLE_PROTOBUF_RUNTIME_INCLUDE_BASE); +#endif + return ::google::protobuf::compiler::PluginMain(argc, argv, &generator); +}