diff options
author | Thomas Van Lenten <thomasvl@google.com> | 2018-03-30 18:09:58 -0400 |
---|---|---|
committer | Thomas Van Lenten <thomasvl@google.com> | 2018-04-02 09:54:29 -0400 |
commit | bd941d5d69de8eeea6a10669fab9a4605c95650e (patch) | |
tree | 9192193878b9534b334e928464e7c8ca739bbfb8 | |
parent | e998b8ff66e37fc7eb7313629bd10e86f857e909 (diff) | |
download | protobuf-bd941d5d69de8eeea6a10669fab9a4605c95650e.tar.gz protobuf-bd941d5d69de8eeea6a10669fab9a4605c95650e.tar.bz2 protobuf-bd941d5d69de8eeea6a10669fab9a4605c95650e.zip |
Don't generate imports for the WKTs unless generating the WKTs.
Since the generated header import GPBProtocolBuffers.h, there is no need
to generate imports for the WKTs as they will have already been imported.
4 files changed, 21 insertions, 8 deletions
diff --git a/src/google/protobuf/compiler/objectivec/objectivec_file.cc b/src/google/protobuf/compiler/objectivec/objectivec_file.cc index 2b14bbe8..f0d9b4d5 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_file.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_file.cc @@ -188,6 +188,7 @@ bool IsDirectDependency(const FileDescriptor* dep, const FileDescriptor* file) { FileGenerator::FileGenerator(const FileDescriptor *file, const Options& options) : file_(file), root_class_name_(FileClassName(file)), + is_bundled_proto_(IsProtobufLibraryBundledProtoFile(file)), options_(options) { for (int i = 0; i < file_->enum_type_count(); i++) { EnumGenerator *generator = new EnumGenerator(file_->enum_type(i)); @@ -217,7 +218,7 @@ void FileGenerator::GenerateHeader(io::Printer *printer) { std::set<string> headers; // Generated files bundled with the library get minimal imports, everything // else gets the wrapper so everything is usable. - if (IsProtobufLibraryBundledProtoFile(file_)) { + if (is_bundled_proto_) { headers.insert("GPBRootObject.h"); headers.insert("GPBMessage.h"); headers.insert("GPBDescriptor.h"); @@ -246,7 +247,8 @@ void FileGenerator::GenerateHeader(io::Printer *printer) { { ImportWriter import_writer( options_.generate_for_named_framework, - options_.named_framework_to_proto_path_mappings_path); + options_.named_framework_to_proto_path_mappings_path, + is_bundled_proto_); const string header_extension(kHeaderExtension); for (int i = 0; i < file_->public_dependency_count(); i++) { import_writer.AddFile(file_->public_dependency(i), header_extension); @@ -364,7 +366,8 @@ void FileGenerator::GenerateSource(io::Printer *printer) { { ImportWriter import_writer( options_.generate_for_named_framework, - options_.named_framework_to_proto_path_mappings_path); + options_.named_framework_to_proto_path_mappings_path, + is_bundled_proto_); const string header_extension(kHeaderExtension); // #import the header for this proto file. diff --git a/src/google/protobuf/compiler/objectivec/objectivec_file.h b/src/google/protobuf/compiler/objectivec/objectivec_file.h index 862f5bb9..1754fc0a 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_file.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_file.h @@ -66,6 +66,7 @@ class FileGenerator { private: const FileDescriptor* file_; string root_class_name_; + bool is_bundled_proto_; std::vector<EnumGenerator*> enum_generators_; std::vector<MessageGenerator*> message_generators_; diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc index 5727dd56..df71c8bb 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc @@ -1504,10 +1504,12 @@ bool ParseSimpleFile( ImportWriter::ImportWriter( const string& generate_for_named_framework, - const string& named_framework_to_proto_path_mappings_path) + const string& named_framework_to_proto_path_mappings_path, + bool include_wkt_imports) : generate_for_named_framework_(generate_for_named_framework), named_framework_to_proto_path_mappings_path_( named_framework_to_proto_path_mappings_path), + include_wkt_imports_(include_wkt_imports), need_to_parse_mapping_file_(true) { } @@ -1518,9 +1520,14 @@ void ImportWriter::AddFile(const FileDescriptor* file, const string file_path(FilePath(file)); if (IsProtobufLibraryBundledProtoFile(file)) { - protobuf_framework_imports_.push_back( - FilePathBasename(file) + header_extension); - protobuf_non_framework_imports_.push_back(file_path + header_extension); + // The imports of the WKTs are only needed within the library itself, + // in other cases, they get skipped because the generated code already + // import GPBProtocolBuffers.h and hence proves them. + if (include_wkt_imports_) { + protobuf_framework_imports_.push_back( + FilePathBasename(file) + header_extension); + protobuf_non_framework_imports_.push_back(file_path + header_extension); + } return; } diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.h b/src/google/protobuf/compiler/objectivec/objectivec_helpers.h index f74607c8..8999aa59 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.h @@ -253,7 +253,8 @@ bool LIBPROTOC_EXPORT ParseSimpleFile( class LIBPROTOC_EXPORT ImportWriter { public: ImportWriter(const string& generate_for_named_framework, - const string& named_framework_to_proto_path_mappings_path); + const string& named_framework_to_proto_path_mappings_path, + bool include_wkt_imports); ~ImportWriter(); void AddFile(const FileDescriptor* file, const string& header_extension); @@ -275,6 +276,7 @@ class LIBPROTOC_EXPORT ImportWriter { const string generate_for_named_framework_; const string named_framework_to_proto_path_mappings_path_; + const bool include_wkt_imports_; std::map<string, string> proto_file_to_framework_name_; bool need_to_parse_mapping_file_; |