Commit bca797da authored by Thomas Van Lenten's avatar Thomas Van Lenten

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
parent 7bf47a6b
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
// This header is meant to only be used by the generated source, it should not // This header is meant to only be used by the generated source, it should not
// be included in code using protocol buffers. // be included in code using protocol buffers.
#import "GPBProtocolBuffers.h" #import "GPBBootstrap.h"
#import "GPBDescriptor_PackagePrivate.h" #import "GPBDescriptor_PackagePrivate.h"
#import "GPBExtensionInternals.h" #import "GPBExtensionInternals.h"
......
...@@ -8,9 +8,13 @@ ...@@ -8,9 +8,13 @@
#endif #endif
#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS #if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
#import <Protobuf/GPBProtocolBuffers.h> #import <Protobuf/GPBDescriptor.h>
#import <Protobuf/GPBMessage.h>
#import <Protobuf/GPBRootObject.h>
#else #else
#import "GPBProtocolBuffers.h" #import "GPBDescriptor.h"
#import "GPBMessage.h"
#import "GPBRootObject.h"
#endif #endif
#if GOOGLE_PROTOBUF_OBJC_VERSION < 30002 #if GOOGLE_PROTOBUF_OBJC_VERSION < 30002
......
...@@ -8,9 +8,13 @@ ...@@ -8,9 +8,13 @@
#endif #endif
#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS #if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
#import <Protobuf/GPBProtocolBuffers.h> #import <Protobuf/GPBDescriptor.h>
#import <Protobuf/GPBMessage.h>
#import <Protobuf/GPBRootObject.h>
#else #else
#import "GPBProtocolBuffers.h" #import "GPBDescriptor.h"
#import "GPBMessage.h"
#import "GPBRootObject.h"
#endif #endif
#if GOOGLE_PROTOBUF_OBJC_VERSION < 30002 #if GOOGLE_PROTOBUF_OBJC_VERSION < 30002
......
...@@ -8,9 +8,13 @@ ...@@ -8,9 +8,13 @@
#endif #endif
#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS #if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
#import <Protobuf/GPBProtocolBuffers.h> #import <Protobuf/GPBDescriptor.h>
#import <Protobuf/GPBMessage.h>
#import <Protobuf/GPBRootObject.h>
#else #else
#import "GPBProtocolBuffers.h" #import "GPBDescriptor.h"
#import "GPBMessage.h"
#import "GPBRootObject.h"
#endif #endif
#if GOOGLE_PROTOBUF_OBJC_VERSION < 30002 #if GOOGLE_PROTOBUF_OBJC_VERSION < 30002
......
...@@ -8,9 +8,13 @@ ...@@ -8,9 +8,13 @@
#endif #endif
#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS #if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
#import <Protobuf/GPBProtocolBuffers.h> #import <Protobuf/GPBDescriptor.h>
#import <Protobuf/GPBMessage.h>
#import <Protobuf/GPBRootObject.h>
#else #else
#import "GPBProtocolBuffers.h" #import "GPBDescriptor.h"
#import "GPBMessage.h"
#import "GPBRootObject.h"
#endif #endif
#if GOOGLE_PROTOBUF_OBJC_VERSION < 30002 #if GOOGLE_PROTOBUF_OBJC_VERSION < 30002
......
...@@ -8,9 +8,13 @@ ...@@ -8,9 +8,13 @@
#endif #endif
#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS #if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
#import <Protobuf/GPBProtocolBuffers.h> #import <Protobuf/GPBDescriptor.h>
#import <Protobuf/GPBMessage.h>
#import <Protobuf/GPBRootObject.h>
#else #else
#import "GPBProtocolBuffers.h" #import "GPBDescriptor.h"
#import "GPBMessage.h"
#import "GPBRootObject.h"
#endif #endif
#if GOOGLE_PROTOBUF_OBJC_VERSION < 30002 #if GOOGLE_PROTOBUF_OBJC_VERSION < 30002
......
...@@ -8,9 +8,13 @@ ...@@ -8,9 +8,13 @@
#endif #endif
#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS #if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
#import <Protobuf/GPBProtocolBuffers.h> #import <Protobuf/GPBDescriptor.h>
#import <Protobuf/GPBMessage.h>
#import <Protobuf/GPBRootObject.h>
#else #else
#import "GPBProtocolBuffers.h" #import "GPBDescriptor.h"
#import "GPBMessage.h"
#import "GPBRootObject.h"
#endif #endif
#if GOOGLE_PROTOBUF_OBJC_VERSION < 30002 #if GOOGLE_PROTOBUF_OBJC_VERSION < 30002
......
...@@ -8,9 +8,13 @@ ...@@ -8,9 +8,13 @@
#endif #endif
#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS #if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
#import <Protobuf/GPBProtocolBuffers.h> #import <Protobuf/GPBDescriptor.h>
#import <Protobuf/GPBMessage.h>
#import <Protobuf/GPBRootObject.h>
#else #else
#import "GPBProtocolBuffers.h" #import "GPBDescriptor.h"
#import "GPBMessage.h"
#import "GPBRootObject.h"
#endif #endif
#if GOOGLE_PROTOBUF_OBJC_VERSION < 30002 #if GOOGLE_PROTOBUF_OBJC_VERSION < 30002
......
...@@ -8,9 +8,13 @@ ...@@ -8,9 +8,13 @@
#endif #endif
#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS #if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
#import <Protobuf/GPBProtocolBuffers.h> #import <Protobuf/GPBDescriptor.h>
#import <Protobuf/GPBMessage.h>
#import <Protobuf/GPBRootObject.h>
#else #else
#import "GPBProtocolBuffers.h" #import "GPBDescriptor.h"
#import "GPBMessage.h"
#import "GPBRootObject.h"
#endif #endif
#if GOOGLE_PROTOBUF_OBJC_VERSION < 30002 #if GOOGLE_PROTOBUF_OBJC_VERSION < 30002
......
...@@ -8,9 +8,13 @@ ...@@ -8,9 +8,13 @@
#endif #endif
#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS #if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
#import <Protobuf/GPBProtocolBuffers.h> #import <Protobuf/GPBDescriptor.h>
#import <Protobuf/GPBMessage.h>
#import <Protobuf/GPBRootObject.h>
#else #else
#import "GPBProtocolBuffers.h" #import "GPBDescriptor.h"
#import "GPBMessage.h"
#import "GPBRootObject.h"
#endif #endif
#if GOOGLE_PROTOBUF_OBJC_VERSION < 30002 #if GOOGLE_PROTOBUF_OBJC_VERSION < 30002
......
...@@ -8,9 +8,13 @@ ...@@ -8,9 +8,13 @@
#endif #endif
#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS #if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
#import <Protobuf/GPBProtocolBuffers.h> #import <Protobuf/GPBDescriptor.h>
#import <Protobuf/GPBMessage.h>
#import <Protobuf/GPBRootObject.h>
#else #else
#import "GPBProtocolBuffers.h" #import "GPBDescriptor.h"
#import "GPBMessage.h"
#import "GPBRootObject.h"
#endif #endif
#if GOOGLE_PROTOBUF_OBJC_VERSION < 30002 #if GOOGLE_PROTOBUF_OBJC_VERSION < 30002
......
...@@ -214,7 +214,17 @@ FileGenerator::~FileGenerator() { ...@@ -214,7 +214,17 @@ FileGenerator::~FileGenerator() {
} }
void FileGenerator::GenerateHeader(io::Printer *printer) { 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 // Add some verification that the generated code matches the source the
// code is being compiled with. // code is being compiled with.
...@@ -337,7 +347,9 @@ void FileGenerator::GenerateHeader(io::Printer *printer) { ...@@ -337,7 +347,9 @@ void FileGenerator::GenerateHeader(io::Printer *printer) {
void FileGenerator::GenerateSource(io::Printer *printer) { void FileGenerator::GenerateSource(io::Printer *printer) {
// #import the runtime support. // #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. // Enums use atomic in the generated code, so add the system import as needed.
if (FileContainsEnums(file_)) { if (FileContainsEnums(file_)) {
...@@ -566,7 +578,7 @@ void FileGenerator::GenerateSource(io::Printer *printer) { ...@@ -566,7 +578,7 @@ void FileGenerator::GenerateSource(io::Printer *printer) {
// files. This currently only supports the runtime coming from a framework // files. This currently only supports the runtime coming from a framework
// as defined by the official CocoaPod. // as defined by the official CocoaPod.
void FileGenerator::PrintFileRuntimePreamble( 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( printer->Print(
"// Generated by the protocol buffer compiler. DO NOT EDIT!\n" "// Generated by the protocol buffer compiler. DO NOT EDIT!\n"
"// source: $filename$\n" "// source: $filename$\n"
...@@ -575,6 +587,7 @@ void FileGenerator::PrintFileRuntimePreamble( ...@@ -575,6 +587,7 @@ void FileGenerator::PrintFileRuntimePreamble(
const string framework_name(ProtobufLibraryFrameworkName); const string framework_name(ProtobufLibraryFrameworkName);
const string cpp_symbol(ProtobufFrameworkImportSymbol(framework_name)); const string cpp_symbol(ProtobufFrameworkImportSymbol(framework_name));
printer->Print( printer->Print(
"// This CPP symbol can be defined to use imports that match up to the framework\n" "// This CPP symbol can be defined to use imports that match up to the framework\n"
"// imports needed when using CocoaPods.\n" "// imports needed when using CocoaPods.\n"
...@@ -582,15 +595,31 @@ void FileGenerator::PrintFileRuntimePreamble( ...@@ -582,15 +595,31 @@ void FileGenerator::PrintFileRuntimePreamble(
" #define $cpp_symbol$ 0\n" " #define $cpp_symbol$ 0\n"
"#endif\n" "#endif\n"
"\n" "\n"
"#if $cpp_symbol$\n" "#if $cpp_symbol$\n",
" #import <$framework_name$/$header$>\n" "cpp_symbol", cpp_symbol);
"#else\n"
" #import \"$header$\"\n"
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" "#endif\n"
"\n", "\n");
"cpp_symbol", cpp_symbol,
"header", header_to_import,
"framework_name", framework_name);
} }
} // namespace objectivec } // namespace objectivec
......
...@@ -74,7 +74,7 @@ class FileGenerator { ...@@ -74,7 +74,7 @@ class FileGenerator {
const Options options_; const Options options_;
void PrintFileRuntimePreamble( 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); GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileGenerator);
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment