aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Van Lenten <thomasvl@google.com>2018-03-28 16:53:39 -0400
committerThomas Van Lenten <thomasvl@google.com>2018-04-02 09:54:29 -0400
commitbca797dac9c5c6f549be12e2bc9addbf51b1d18f (patch)
tree7c7847cd60c0ca9a1f65829737538794960fb323
parent7bf47a6b5d10382a4b427677cf7ca9288f4e2833 (diff)
downloadprotobuf-bca797dac9c5c6f549be12e2bc9addbf51b1d18f.tar.gz
protobuf-bca797dac9c5c6f549be12e2bc9addbf51b1d18f.tar.bz2
protobuf-bca797dac9c5c6f549be12e2bc9addbf51b1d18f.zip
Trim imports for bundled generated protos.
To avoid a cycle between headers, have the WKTs use minimal imports instead of using the helper to get everything from the library. Fixes https://github.com/google/protobuf/issues/4301 Fixes https://github.com/google/protobuf/issues/4403
-rw-r--r--objectivec/GPBProtocolBuffers_RuntimeSupport.h2
-rw-r--r--objectivec/google/protobuf/Any.pbobjc.h8
-rw-r--r--objectivec/google/protobuf/Api.pbobjc.h8
-rw-r--r--objectivec/google/protobuf/Duration.pbobjc.h8
-rw-r--r--objectivec/google/protobuf/Empty.pbobjc.h8
-rw-r--r--objectivec/google/protobuf/FieldMask.pbobjc.h8
-rw-r--r--objectivec/google/protobuf/SourceContext.pbobjc.h8
-rw-r--r--objectivec/google/protobuf/Struct.pbobjc.h8
-rw-r--r--objectivec/google/protobuf/Timestamp.pbobjc.h8
-rw-r--r--objectivec/google/protobuf/Type.pbobjc.h8
-rw-r--r--objectivec/google/protobuf/Wrappers.pbobjc.h8
-rw-r--r--src/google/protobuf/compiler/objectivec/objectivec_file.cc51
-rw-r--r--src/google/protobuf/compiler/objectivec/objectivec_file.h2
13 files changed, 102 insertions, 33 deletions
diff --git a/objectivec/GPBProtocolBuffers_RuntimeSupport.h b/objectivec/GPBProtocolBuffers_RuntimeSupport.h
index fea75b93..04dde620 100644
--- a/objectivec/GPBProtocolBuffers_RuntimeSupport.h
+++ b/objectivec/GPBProtocolBuffers_RuntimeSupport.h
@@ -31,7 +31,7 @@
// This header is meant to only be used by the generated source, it should not
// be included in code using protocol buffers.
-#import "GPBProtocolBuffers.h"
+#import "GPBBootstrap.h"
#import "GPBDescriptor_PackagePrivate.h"
#import "GPBExtensionInternals.h"
diff --git a/objectivec/google/protobuf/Any.pbobjc.h b/objectivec/google/protobuf/Any.pbobjc.h
index 89c99bdb..ad261898 100644
--- a/objectivec/google/protobuf/Any.pbobjc.h
+++ b/objectivec/google/protobuf/Any.pbobjc.h
@@ -8,9 +8,13 @@
#endif
#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
- #import <Protobuf/GPBProtocolBuffers.h>
+ #import <Protobuf/GPBDescriptor.h>
+ #import <Protobuf/GPBMessage.h>
+ #import <Protobuf/GPBRootObject.h>
#else
- #import "GPBProtocolBuffers.h"
+ #import "GPBDescriptor.h"
+ #import "GPBMessage.h"
+ #import "GPBRootObject.h"
#endif
#if GOOGLE_PROTOBUF_OBJC_VERSION < 30002
diff --git a/objectivec/google/protobuf/Api.pbobjc.h b/objectivec/google/protobuf/Api.pbobjc.h
index 095fc2cd..c93f3f15 100644
--- a/objectivec/google/protobuf/Api.pbobjc.h
+++ b/objectivec/google/protobuf/Api.pbobjc.h
@@ -8,9 +8,13 @@
#endif
#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
- #import <Protobuf/GPBProtocolBuffers.h>
+ #import <Protobuf/GPBDescriptor.h>
+ #import <Protobuf/GPBMessage.h>
+ #import <Protobuf/GPBRootObject.h>
#else
- #import "GPBProtocolBuffers.h"
+ #import "GPBDescriptor.h"
+ #import "GPBMessage.h"
+ #import "GPBRootObject.h"
#endif
#if GOOGLE_PROTOBUF_OBJC_VERSION < 30002
diff --git a/objectivec/google/protobuf/Duration.pbobjc.h b/objectivec/google/protobuf/Duration.pbobjc.h
index d9a388ac..3e367590 100644
--- a/objectivec/google/protobuf/Duration.pbobjc.h
+++ b/objectivec/google/protobuf/Duration.pbobjc.h
@@ -8,9 +8,13 @@
#endif
#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
- #import <Protobuf/GPBProtocolBuffers.h>
+ #import <Protobuf/GPBDescriptor.h>
+ #import <Protobuf/GPBMessage.h>
+ #import <Protobuf/GPBRootObject.h>
#else
- #import "GPBProtocolBuffers.h"
+ #import "GPBDescriptor.h"
+ #import "GPBMessage.h"
+ #import "GPBRootObject.h"
#endif
#if GOOGLE_PROTOBUF_OBJC_VERSION < 30002
diff --git a/objectivec/google/protobuf/Empty.pbobjc.h b/objectivec/google/protobuf/Empty.pbobjc.h
index bd49cfdb..fdc247ae 100644
--- a/objectivec/google/protobuf/Empty.pbobjc.h
+++ b/objectivec/google/protobuf/Empty.pbobjc.h
@@ -8,9 +8,13 @@
#endif
#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
- #import <Protobuf/GPBProtocolBuffers.h>
+ #import <Protobuf/GPBDescriptor.h>
+ #import <Protobuf/GPBMessage.h>
+ #import <Protobuf/GPBRootObject.h>
#else
- #import "GPBProtocolBuffers.h"
+ #import "GPBDescriptor.h"
+ #import "GPBMessage.h"
+ #import "GPBRootObject.h"
#endif
#if GOOGLE_PROTOBUF_OBJC_VERSION < 30002
diff --git a/objectivec/google/protobuf/FieldMask.pbobjc.h b/objectivec/google/protobuf/FieldMask.pbobjc.h
index 74aa8568..73296d57 100644
--- a/objectivec/google/protobuf/FieldMask.pbobjc.h
+++ b/objectivec/google/protobuf/FieldMask.pbobjc.h
@@ -8,9 +8,13 @@
#endif
#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
- #import <Protobuf/GPBProtocolBuffers.h>
+ #import <Protobuf/GPBDescriptor.h>
+ #import <Protobuf/GPBMessage.h>
+ #import <Protobuf/GPBRootObject.h>
#else
- #import "GPBProtocolBuffers.h"
+ #import "GPBDescriptor.h"
+ #import "GPBMessage.h"
+ #import "GPBRootObject.h"
#endif
#if GOOGLE_PROTOBUF_OBJC_VERSION < 30002
diff --git a/objectivec/google/protobuf/SourceContext.pbobjc.h b/objectivec/google/protobuf/SourceContext.pbobjc.h
index 799d190a..e4923959 100644
--- a/objectivec/google/protobuf/SourceContext.pbobjc.h
+++ b/objectivec/google/protobuf/SourceContext.pbobjc.h
@@ -8,9 +8,13 @@
#endif
#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
- #import <Protobuf/GPBProtocolBuffers.h>
+ #import <Protobuf/GPBDescriptor.h>
+ #import <Protobuf/GPBMessage.h>
+ #import <Protobuf/GPBRootObject.h>
#else
- #import "GPBProtocolBuffers.h"
+ #import "GPBDescriptor.h"
+ #import "GPBMessage.h"
+ #import "GPBRootObject.h"
#endif
#if GOOGLE_PROTOBUF_OBJC_VERSION < 30002
diff --git a/objectivec/google/protobuf/Struct.pbobjc.h b/objectivec/google/protobuf/Struct.pbobjc.h
index 3fc80caa..fb204251 100644
--- a/objectivec/google/protobuf/Struct.pbobjc.h
+++ b/objectivec/google/protobuf/Struct.pbobjc.h
@@ -8,9 +8,13 @@
#endif
#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
- #import <Protobuf/GPBProtocolBuffers.h>
+ #import <Protobuf/GPBDescriptor.h>
+ #import <Protobuf/GPBMessage.h>
+ #import <Protobuf/GPBRootObject.h>
#else
- #import "GPBProtocolBuffers.h"
+ #import "GPBDescriptor.h"
+ #import "GPBMessage.h"
+ #import "GPBRootObject.h"
#endif
#if GOOGLE_PROTOBUF_OBJC_VERSION < 30002
diff --git a/objectivec/google/protobuf/Timestamp.pbobjc.h b/objectivec/google/protobuf/Timestamp.pbobjc.h
index 7e65b15b..2c4b8b20 100644
--- a/objectivec/google/protobuf/Timestamp.pbobjc.h
+++ b/objectivec/google/protobuf/Timestamp.pbobjc.h
@@ -8,9 +8,13 @@
#endif
#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
- #import <Protobuf/GPBProtocolBuffers.h>
+ #import <Protobuf/GPBDescriptor.h>
+ #import <Protobuf/GPBMessage.h>
+ #import <Protobuf/GPBRootObject.h>
#else
- #import "GPBProtocolBuffers.h"
+ #import "GPBDescriptor.h"
+ #import "GPBMessage.h"
+ #import "GPBRootObject.h"
#endif
#if GOOGLE_PROTOBUF_OBJC_VERSION < 30002
diff --git a/objectivec/google/protobuf/Type.pbobjc.h b/objectivec/google/protobuf/Type.pbobjc.h
index 17986970..e14d15df 100644
--- a/objectivec/google/protobuf/Type.pbobjc.h
+++ b/objectivec/google/protobuf/Type.pbobjc.h
@@ -8,9 +8,13 @@
#endif
#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
- #import <Protobuf/GPBProtocolBuffers.h>
+ #import <Protobuf/GPBDescriptor.h>
+ #import <Protobuf/GPBMessage.h>
+ #import <Protobuf/GPBRootObject.h>
#else
- #import "GPBProtocolBuffers.h"
+ #import "GPBDescriptor.h"
+ #import "GPBMessage.h"
+ #import "GPBRootObject.h"
#endif
#if GOOGLE_PROTOBUF_OBJC_VERSION < 30002
diff --git a/objectivec/google/protobuf/Wrappers.pbobjc.h b/objectivec/google/protobuf/Wrappers.pbobjc.h
index 3cb9fe77..0411e1ec 100644
--- a/objectivec/google/protobuf/Wrappers.pbobjc.h
+++ b/objectivec/google/protobuf/Wrappers.pbobjc.h
@@ -8,9 +8,13 @@
#endif
#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
- #import <Protobuf/GPBProtocolBuffers.h>
+ #import <Protobuf/GPBDescriptor.h>
+ #import <Protobuf/GPBMessage.h>
+ #import <Protobuf/GPBRootObject.h>
#else
- #import "GPBProtocolBuffers.h"
+ #import "GPBDescriptor.h"
+ #import "GPBMessage.h"
+ #import "GPBRootObject.h"
#endif
#if GOOGLE_PROTOBUF_OBJC_VERSION < 30002
diff --git a/src/google/protobuf/compiler/objectivec/objectivec_file.cc b/src/google/protobuf/compiler/objectivec/objectivec_file.cc
index 6f80a0de..2b14bbe8 100644
--- a/src/google/protobuf/compiler/objectivec/objectivec_file.cc
+++ b/src/google/protobuf/compiler/objectivec/objectivec_file.cc
@@ -214,7 +214,17 @@ FileGenerator::~FileGenerator() {
}
void FileGenerator::GenerateHeader(io::Printer *printer) {
- PrintFileRuntimePreamble(printer, "GPBProtocolBuffers.h");
+ 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_)) {
+ headers.insert("GPBRootObject.h");
+ headers.insert("GPBMessage.h");
+ headers.insert("GPBDescriptor.h");
+ } else {
+ headers.insert("GPBProtocolBuffers.h");
+ }
+ PrintFileRuntimePreamble(printer, headers);
// Add some verification that the generated code matches the source the
// code is being compiled with.
@@ -337,7 +347,9 @@ void FileGenerator::GenerateHeader(io::Printer *printer) {
void FileGenerator::GenerateSource(io::Printer *printer) {
// #import the runtime support.
- PrintFileRuntimePreamble(printer, "GPBProtocolBuffers_RuntimeSupport.h");
+ std::set<string> headers;
+ headers.insert("GPBProtocolBuffers_RuntimeSupport.h");
+ PrintFileRuntimePreamble(printer, headers);
// Enums use atomic in the generated code, so add the system import as needed.
if (FileContainsEnums(file_)) {
@@ -566,7 +578,7 @@ void FileGenerator::GenerateSource(io::Printer *printer) {
// files. This currently only supports the runtime coming from a framework
// as defined by the official CocoaPod.
void FileGenerator::PrintFileRuntimePreamble(
- io::Printer* printer, const string& header_to_import) const {
+ io::Printer* printer, const std::set<string>& headers_to_import) const {
printer->Print(
"// Generated by the protocol buffer compiler. DO NOT EDIT!\n"
"// source: $filename$\n"
@@ -575,6 +587,7 @@ void FileGenerator::PrintFileRuntimePreamble(
const string framework_name(ProtobufLibraryFrameworkName);
const string cpp_symbol(ProtobufFrameworkImportSymbol(framework_name));
+
printer->Print(
"// This CPP symbol can be defined to use imports that match up to the framework\n"
"// imports needed when using CocoaPods.\n"
@@ -582,15 +595,31 @@ void FileGenerator::PrintFileRuntimePreamble(
" #define $cpp_symbol$ 0\n"
"#endif\n"
"\n"
- "#if $cpp_symbol$\n"
- " #import <$framework_name$/$header$>\n"
- "#else\n"
- " #import \"$header$\"\n"
+ "#if $cpp_symbol$\n",
+ "cpp_symbol", cpp_symbol);
+
+
+ for (std::set<string>::const_iterator iter = headers_to_import.begin();
+ iter != headers_to_import.end(); ++iter) {
+ printer->Print(
+ " #import <$framework_name$/$header$>\n",
+ "header", *iter,
+ "framework_name", framework_name);
+ }
+
+ printer->Print(
+ "#else\n");
+
+ for (std::set<string>::const_iterator iter = headers_to_import.begin();
+ iter != headers_to_import.end(); ++iter) {
+ printer->Print(
+ " #import \"$header$\"\n",
+ "header", *iter);
+ }
+
+ printer->Print(
"#endif\n"
- "\n",
- "cpp_symbol", cpp_symbol,
- "header", header_to_import,
- "framework_name", framework_name);
+ "\n");
}
} // namespace objectivec
diff --git a/src/google/protobuf/compiler/objectivec/objectivec_file.h b/src/google/protobuf/compiler/objectivec/objectivec_file.h
index 9c3f0071..862f5bb9 100644
--- a/src/google/protobuf/compiler/objectivec/objectivec_file.h
+++ b/src/google/protobuf/compiler/objectivec/objectivec_file.h
@@ -74,7 +74,7 @@ class FileGenerator {
const Options options_;
void PrintFileRuntimePreamble(
- io::Printer* printer, const string& header_to_import) const;
+ io::Printer* printer, const std::set<string>& headers_to_import) const;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileGenerator);
};