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

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.
parent e998b8ff
...@@ -188,6 +188,7 @@ bool IsDirectDependency(const FileDescriptor* dep, const FileDescriptor* file) { ...@@ -188,6 +188,7 @@ bool IsDirectDependency(const FileDescriptor* dep, const FileDescriptor* file) {
FileGenerator::FileGenerator(const FileDescriptor *file, const Options& options) FileGenerator::FileGenerator(const FileDescriptor *file, const Options& options)
: file_(file), : file_(file),
root_class_name_(FileClassName(file)), root_class_name_(FileClassName(file)),
is_bundled_proto_(IsProtobufLibraryBundledProtoFile(file)),
options_(options) { options_(options) {
for (int i = 0; i < file_->enum_type_count(); i++) { for (int i = 0; i < file_->enum_type_count(); i++) {
EnumGenerator *generator = new EnumGenerator(file_->enum_type(i)); EnumGenerator *generator = new EnumGenerator(file_->enum_type(i));
...@@ -217,7 +218,7 @@ void FileGenerator::GenerateHeader(io::Printer *printer) { ...@@ -217,7 +218,7 @@ void FileGenerator::GenerateHeader(io::Printer *printer) {
std::set<string> headers; std::set<string> headers;
// Generated files bundled with the library get minimal imports, everything // Generated files bundled with the library get minimal imports, everything
// else gets the wrapper so everything is usable. // else gets the wrapper so everything is usable.
if (IsProtobufLibraryBundledProtoFile(file_)) { if (is_bundled_proto_) {
headers.insert("GPBRootObject.h"); headers.insert("GPBRootObject.h");
headers.insert("GPBMessage.h"); headers.insert("GPBMessage.h");
headers.insert("GPBDescriptor.h"); headers.insert("GPBDescriptor.h");
...@@ -246,7 +247,8 @@ void FileGenerator::GenerateHeader(io::Printer *printer) { ...@@ -246,7 +247,8 @@ void FileGenerator::GenerateHeader(io::Printer *printer) {
{ {
ImportWriter import_writer( ImportWriter import_writer(
options_.generate_for_named_framework, 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); const string header_extension(kHeaderExtension);
for (int i = 0; i < file_->public_dependency_count(); i++) { for (int i = 0; i < file_->public_dependency_count(); i++) {
import_writer.AddFile(file_->public_dependency(i), header_extension); import_writer.AddFile(file_->public_dependency(i), header_extension);
...@@ -364,7 +366,8 @@ void FileGenerator::GenerateSource(io::Printer *printer) { ...@@ -364,7 +366,8 @@ void FileGenerator::GenerateSource(io::Printer *printer) {
{ {
ImportWriter import_writer( ImportWriter import_writer(
options_.generate_for_named_framework, 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); const string header_extension(kHeaderExtension);
// #import the header for this proto file. // #import the header for this proto file.
......
...@@ -66,6 +66,7 @@ class FileGenerator { ...@@ -66,6 +66,7 @@ class FileGenerator {
private: private:
const FileDescriptor* file_; const FileDescriptor* file_;
string root_class_name_; string root_class_name_;
bool is_bundled_proto_;
std::vector<EnumGenerator*> enum_generators_; std::vector<EnumGenerator*> enum_generators_;
std::vector<MessageGenerator*> message_generators_; std::vector<MessageGenerator*> message_generators_;
......
...@@ -1504,10 +1504,12 @@ bool ParseSimpleFile( ...@@ -1504,10 +1504,12 @@ bool ParseSimpleFile(
ImportWriter::ImportWriter( ImportWriter::ImportWriter(
const string& generate_for_named_framework, 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), : generate_for_named_framework_(generate_for_named_framework),
named_framework_to_proto_path_mappings_path_( named_framework_to_proto_path_mappings_path_(
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) { need_to_parse_mapping_file_(true) {
} }
...@@ -1518,9 +1520,14 @@ void ImportWriter::AddFile(const FileDescriptor* file, ...@@ -1518,9 +1520,14 @@ void ImportWriter::AddFile(const FileDescriptor* file,
const string file_path(FilePath(file)); const string file_path(FilePath(file));
if (IsProtobufLibraryBundledProtoFile(file)) { if (IsProtobufLibraryBundledProtoFile(file)) {
// 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( protobuf_framework_imports_.push_back(
FilePathBasename(file) + header_extension); FilePathBasename(file) + header_extension);
protobuf_non_framework_imports_.push_back(file_path + header_extension); protobuf_non_framework_imports_.push_back(file_path + header_extension);
}
return; return;
} }
......
...@@ -253,7 +253,8 @@ bool LIBPROTOC_EXPORT ParseSimpleFile( ...@@ -253,7 +253,8 @@ bool LIBPROTOC_EXPORT ParseSimpleFile(
class LIBPROTOC_EXPORT ImportWriter { class LIBPROTOC_EXPORT ImportWriter {
public: public:
ImportWriter(const string& generate_for_named_framework, 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(); ~ImportWriter();
void AddFile(const FileDescriptor* file, const string& header_extension); void AddFile(const FileDescriptor* file, const string& header_extension);
...@@ -275,6 +276,7 @@ class LIBPROTOC_EXPORT ImportWriter { ...@@ -275,6 +276,7 @@ class LIBPROTOC_EXPORT ImportWriter {
const string generate_for_named_framework_; const string generate_for_named_framework_;
const string named_framework_to_proto_path_mappings_path_; const string named_framework_to_proto_path_mappings_path_;
const bool include_wkt_imports_;
std::map<string, string> proto_file_to_framework_name_; std::map<string, string> proto_file_to_framework_name_;
bool need_to_parse_mapping_file_; bool need_to_parse_mapping_file_;
......
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