internal change

PiperOrigin-RevId: 569242155
pull/14233/head
Sandy Zhang 2 years ago committed by Copybara-Service
parent 4246672186
commit 49f2388bf3
  1. 18
      src/google/protobuf/compiler/command_line_interface.cc
  2. 4
      src/google/protobuf/compiler/cpp/file.cc
  3. 18
      src/google/protobuf/compiler/cpp/main.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<std::string> 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);
}
}

@ -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);
}

@ -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);
}
Loading…
Cancel
Save