diff options
Diffstat (limited to 'src')
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_; |