| Index: third_party/protobuf/src/google/protobuf/compiler/java/java_generator.cc
|
| diff --git a/third_party/protobuf/src/google/protobuf/compiler/java/java_generator.cc b/third_party/protobuf/src/google/protobuf/compiler/java/java_generator.cc
|
| index 2c02d996fe1f72aa04f7051a2087064a384c6cdd..a46c7fc41a4a5c73d7822a40c8675d10434a11e7 100644
|
| --- a/third_party/protobuf/src/google/protobuf/compiler/java/java_generator.cc
|
| +++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_generator.cc
|
| @@ -42,7 +42,6 @@
|
| #include <google/protobuf/compiler/java/java_file.h>
|
| #include <google/protobuf/compiler/java/java_generator_factory.h>
|
| #include <google/protobuf/compiler/java/java_helpers.h>
|
| -#include <google/protobuf/compiler/java/java_options.h>
|
| #include <google/protobuf/compiler/java/java_shared_code_generator.h>
|
| #include <google/protobuf/io/printer.h>
|
| #include <google/protobuf/io/zero_copy_stream.h>
|
| @@ -65,58 +64,63 @@ bool JavaGenerator::Generate(const FileDescriptor* file,
|
| // -----------------------------------------------------------------
|
| // parse generator options
|
|
|
| + // Name a file where we will write a list of generated file names, one
|
| + // per line.
|
| + string output_list_file;
|
|
|
| - std::vector<std::pair<string, string> > options;
|
| +
|
| + vector<pair<string, string> > options;
|
| ParseGeneratorParameter(parameter, &options);
|
| - Options file_options;
|
|
|
| + bool generate_immutable_code = false;
|
| + bool generate_mutable_code = false;
|
| + bool generate_shared_code = false;
|
| + bool enforce_lite = false;
|
| for (int i = 0; i < options.size(); i++) {
|
| if (options[i].first == "output_list_file") {
|
| - file_options.output_list_file = options[i].second;
|
| + output_list_file = options[i].second;
|
| } else if (options[i].first == "immutable") {
|
| - file_options.generate_immutable_code = true;
|
| + generate_immutable_code = true;
|
| } else if (options[i].first == "mutable") {
|
| - file_options.generate_mutable_code = true;
|
| + generate_mutable_code = true;
|
| } else if (options[i].first == "shared") {
|
| - file_options.generate_shared_code = true;
|
| - } else if (options[i].first == "annotate_code") {
|
| - file_options.annotate_code = true;
|
| - } else if (options[i].first == "annotation_list_file") {
|
| - file_options.annotation_list_file = options[i].second;
|
| + generate_shared_code = true;
|
| + } else if (options[i].first == "lite") {
|
| + // When set, the protoc will generate the current files and all the
|
| + // transitive dependencies as lite runtime.
|
| + enforce_lite = true;
|
| } else {
|
| *error = "Unknown generator option: " + options[i].first;
|
| return false;
|
| }
|
| }
|
|
|
| - if (file_options.enforce_lite && file_options.generate_mutable_code) {
|
| + if (enforce_lite && generate_mutable_code) {
|
| *error = "lite runtime generator option cannot be used with mutable API.";
|
| return false;
|
| }
|
|
|
| // By default we generate immutable code and shared code for immutable API.
|
| - if (!file_options.generate_immutable_code &&
|
| - !file_options.generate_mutable_code &&
|
| - !file_options.generate_shared_code) {
|
| - file_options.generate_immutable_code = true;
|
| - file_options.generate_shared_code = true;
|
| + if (!generate_immutable_code && !generate_mutable_code &&
|
| + !generate_shared_code) {
|
| + generate_immutable_code = true;
|
| + generate_shared_code = true;
|
| }
|
|
|
| // -----------------------------------------------------------------
|
|
|
|
|
| - std::vector<string> all_files;
|
| - std::vector<string> all_annotations;
|
| + vector<string> all_files;
|
|
|
|
|
| - std::vector<FileGenerator*> file_generators;
|
| - if (file_options.generate_immutable_code) {
|
| - file_generators.push_back(new FileGenerator(file, file_options,
|
| - /* immutable = */ true));
|
| + vector<FileGenerator*> file_generators;
|
| + if (generate_immutable_code) {
|
| + file_generators.push_back(
|
| + new FileGenerator(file, /* immutable = */ true, enforce_lite));
|
| }
|
| - if (file_options.generate_mutable_code) {
|
| - file_generators.push_back(new FileGenerator(file, file_options,
|
| - /* mutable = */ false));
|
| + if (generate_mutable_code) {
|
| + file_generators.push_back(
|
| + new FileGenerator(file, /* mutable = */ false, enforce_lite));
|
| }
|
| for (int i = 0; i < file_generators.size(); ++i) {
|
| if (!file_generators[i]->Validate(error)) {
|
| @@ -136,32 +140,15 @@ bool JavaGenerator::Generate(const FileDescriptor* file,
|
| java_filename += file_generator->classname();
|
| java_filename += ".java";
|
| all_files.push_back(java_filename);
|
| - string info_full_path = java_filename + ".pb.meta";
|
| - if (file_options.annotate_code) {
|
| - all_annotations.push_back(info_full_path);
|
| - }
|
|
|
| // Generate main java file.
|
| google::protobuf::scoped_ptr<io::ZeroCopyOutputStream> output(
|
| context->Open(java_filename));
|
| - GeneratedCodeInfo annotations;
|
| - io::AnnotationProtoCollector<GeneratedCodeInfo> annotation_collector(
|
| - &annotations);
|
| - io::Printer printer(output.get(), '$', file_options.annotate_code
|
| - ? &annotation_collector
|
| - : NULL);
|
| -
|
| + io::Printer printer(output.get(), '$');
|
| file_generator->Generate(&printer);
|
|
|
| // Generate sibling files.
|
| - file_generator->GenerateSiblings(package_dir, context, &all_files,
|
| - &all_annotations);
|
| -
|
| - if (file_options.annotate_code) {
|
| - google::protobuf::scoped_ptr<io::ZeroCopyOutputStream> info_output(
|
| - context->Open(info_full_path));
|
| - annotations.SerializeToZeroCopyStream(info_output.get());
|
| - }
|
| + file_generator->GenerateSiblings(package_dir, context, &all_files);
|
| }
|
|
|
| for (int i = 0; i < file_generators.size(); ++i) {
|
| @@ -170,29 +157,17 @@ bool JavaGenerator::Generate(const FileDescriptor* file,
|
| file_generators.clear();
|
|
|
| // Generate output list if requested.
|
| - if (!file_options.output_list_file.empty()) {
|
| + if (!output_list_file.empty()) {
|
| // Generate output list. This is just a simple text file placed in a
|
| // deterministic location which lists the .java files being generated.
|
| google::protobuf::scoped_ptr<io::ZeroCopyOutputStream> srclist_raw_output(
|
| - context->Open(file_options.output_list_file));
|
| + context->Open(output_list_file));
|
| io::Printer srclist_printer(srclist_raw_output.get(), '$');
|
| for (int i = 0; i < all_files.size(); i++) {
|
| srclist_printer.Print("$filename$\n", "filename", all_files[i]);
|
| }
|
| }
|
|
|
| - if (!file_options.annotation_list_file.empty()) {
|
| - // Generate output list. This is just a simple text file placed in a
|
| - // deterministic location which lists the .java files being generated.
|
| - google::protobuf::scoped_ptr<io::ZeroCopyOutputStream> annotation_list_raw_output(
|
| - context->Open(file_options.annotation_list_file));
|
| - io::Printer annotation_list_printer(annotation_list_raw_output.get(), '$');
|
| - for (int i = 0; i < all_annotations.size(); i++) {
|
| - annotation_list_printer.Print("$filename$\n", "filename",
|
| - all_annotations[i]);
|
| - }
|
| - }
|
| -
|
| return true;
|
| }
|
|
|
|
|