Commit 290d26b4 authored by Thomas Van Lenten's avatar Thomas Van Lenten

Remove the compiler options from ImportWriter.

Breaks the tie of the ImportWriter to the ObjC generation, allow grpc to use
a different extension and to relay the values they need for these.

- Pass in the two framework options to the ctor.
- Pass in the header extension to AddFile.
parent 93362a5a
...@@ -51,6 +51,8 @@ namespace protobuf { ...@@ -51,6 +51,8 @@ namespace protobuf {
// runtime being used. // runtime being used.
const int32 GOOGLE_PROTOBUF_OBJC_GEN_VERSION = 30001; const int32 GOOGLE_PROTOBUF_OBJC_GEN_VERSION = 30001;
const char* kHeaderExtension = ".pbobjc.h";
namespace compiler { namespace compiler {
namespace objectivec { namespace objectivec {
...@@ -100,13 +102,16 @@ void FileGenerator::GenerateHeader(io::Printer *printer) { ...@@ -100,13 +102,16 @@ void FileGenerator::GenerateHeader(io::Printer *printer) {
// #import any headers for "public imports" in the proto file. // #import any headers for "public imports" in the proto file.
{ {
ImportWriter import_writer(options_); ImportWriter import_writer(
options_.generate_for_named_framework,
options_.named_framework_to_proto_path_mappings_path);
const vector<FileGenerator *> &dependency_generators = DependencyGenerators(); const vector<FileGenerator *> &dependency_generators = DependencyGenerators();
const string header_extension(kHeaderExtension);
for (vector<FileGenerator *>::const_iterator iter = for (vector<FileGenerator *>::const_iterator iter =
dependency_generators.begin(); dependency_generators.begin();
iter != dependency_generators.end(); ++iter) { iter != dependency_generators.end(); ++iter) {
if ((*iter)->IsPublicDependency()) { if ((*iter)->IsPublicDependency()) {
import_writer.AddFile((*iter)->file_); import_writer.AddFile((*iter)->file_, header_extension);
} }
} }
import_writer.Print(printer); import_writer.Print(printer);
...@@ -208,10 +213,13 @@ void FileGenerator::GenerateSource(io::Printer *printer) { ...@@ -208,10 +213,13 @@ void FileGenerator::GenerateSource(io::Printer *printer) {
PrintFileRuntimePreamble(printer, "GPBProtocolBuffers_RuntimeSupport.h"); PrintFileRuntimePreamble(printer, "GPBProtocolBuffers_RuntimeSupport.h");
{ {
ImportWriter import_writer(options_); ImportWriter import_writer(
options_.generate_for_named_framework,
options_.named_framework_to_proto_path_mappings_path);
const string header_extension(kHeaderExtension);
// #import the header for this proto file. // #import the header for this proto file.
import_writer.AddFile(file_); import_writer.AddFile(file_, header_extension);
// #import the headers for anything that a plain dependency of this proto // #import the headers for anything that a plain dependency of this proto
// file (that means they were just an include, not a "public" include). // file (that means they were just an include, not a "public" include).
...@@ -221,7 +229,7 @@ void FileGenerator::GenerateSource(io::Printer *printer) { ...@@ -221,7 +229,7 @@ void FileGenerator::GenerateSource(io::Printer *printer) {
dependency_generators.begin(); dependency_generators.begin();
iter != dependency_generators.end(); ++iter) { iter != dependency_generators.end(); ++iter) {
if (!(*iter)->IsPublicDependency()) { if (!(*iter)->IsPublicDependency()) {
import_writer.AddFile((*iter)->file_); import_writer.AddFile((*iter)->file_, header_extension);
} }
} }
......
...@@ -1434,14 +1434,25 @@ bool ParseSimpleFile( ...@@ -1434,14 +1434,25 @@ bool ParseSimpleFile(
return parser.Finish(); return parser.Finish();
} }
void ImportWriter::AddFile(const FileDescriptor* file) { ImportWriter::ImportWriter(
const string extension(".pbobjc.h"); const string& generate_for_named_framework,
const string& named_framework_to_proto_path_mappings_path)
: generate_for_named_framework_(generate_for_named_framework),
named_framework_to_proto_path_mappings_path_(
named_framework_to_proto_path_mappings_path),
need_to_parse_mapping_file_(true) {
}
ImportWriter::~ImportWriter() {}
void ImportWriter::AddFile(const FileDescriptor* file,
const string& header_extension) {
const string file_path(FilePath(file)); const string file_path(FilePath(file));
if (IsProtobufLibraryBundledProtoFile(file)) { if (IsProtobufLibraryBundledProtoFile(file)) {
protobuf_framework_imports_.push_back( protobuf_framework_imports_.push_back(
FilePathBasename(file) + extension); FilePathBasename(file) + header_extension);
protobuf_non_framework_imports_.push_back(file_path + extension); protobuf_non_framework_imports_.push_back(file_path + header_extension);
return; return;
} }
...@@ -1455,18 +1466,18 @@ void ImportWriter::AddFile(const FileDescriptor* file) { ...@@ -1455,18 +1466,18 @@ void ImportWriter::AddFile(const FileDescriptor* file) {
if (proto_lookup != proto_file_to_framework_name_.end()) { if (proto_lookup != proto_file_to_framework_name_.end()) {
other_framework_imports_.push_back( other_framework_imports_.push_back(
proto_lookup->second + "/" + proto_lookup->second + "/" +
FilePathBasename(file) + extension); FilePathBasename(file) + header_extension);
return; return;
} }
if (!options_.generate_for_named_framework.empty()) { if (!generate_for_named_framework_.empty()) {
other_framework_imports_.push_back( other_framework_imports_.push_back(
options_.generate_for_named_framework + "/" + generate_for_named_framework_ + "/" +
FilePathBasename(file) + extension); FilePathBasename(file) + header_extension);
return; return;
} }
other_imports_.push_back(file_path + extension); other_imports_.push_back(file_path + header_extension);
} }
void ImportWriter::Print(io::Printer* printer) const { void ImportWriter::Print(io::Printer* printer) const {
...@@ -1534,15 +1545,15 @@ void ImportWriter::Print(io::Printer* printer) const { ...@@ -1534,15 +1545,15 @@ void ImportWriter::Print(io::Printer* printer) const {
void ImportWriter::ParseFrameworkMappings() { void ImportWriter::ParseFrameworkMappings() {
need_to_parse_mapping_file_ = false; need_to_parse_mapping_file_ = false;
if (options_.named_framework_to_proto_path_mappings_path.empty()) { if (named_framework_to_proto_path_mappings_path_.empty()) {
return; // Nothing to do. return; // Nothing to do.
} }
ProtoFrameworkCollector collector(&proto_file_to_framework_name_); ProtoFrameworkCollector collector(&proto_file_to_framework_name_);
string parse_error; string parse_error;
if (!ParseSimpleFile(options_.named_framework_to_proto_path_mappings_path, if (!ParseSimpleFile(named_framework_to_proto_path_mappings_path_,
&collector, &parse_error)) { &collector, &parse_error)) {
cerr << "error parsing " << options_.named_framework_to_proto_path_mappings_path cerr << "error parsing " << named_framework_to_proto_path_mappings_path_
<< " : " << parse_error << endl; << " : " << parse_error << endl;
cerr.flush(); cerr.flush();
} }
......
...@@ -230,11 +230,11 @@ bool ParseSimpleFile( ...@@ -230,11 +230,11 @@ bool ParseSimpleFile(
// import statements. // import statements.
class LIBPROTOC_EXPORT ImportWriter { class LIBPROTOC_EXPORT ImportWriter {
public: public:
ImportWriter(const Options& options) ImportWriter(const string& generate_for_named_framework,
: options_(options), const string& named_framework_to_proto_path_mappings_path);
need_to_parse_mapping_file_(true) {} ~ImportWriter();
void AddFile(const FileDescriptor* file); void AddFile(const FileDescriptor* file, const string& header_extension);
void Print(io::Printer *printer) const; void Print(io::Printer *printer) const;
private: private:
...@@ -251,7 +251,8 @@ class LIBPROTOC_EXPORT ImportWriter { ...@@ -251,7 +251,8 @@ class LIBPROTOC_EXPORT ImportWriter {
void ParseFrameworkMappings(); void ParseFrameworkMappings();
const Options options_; const string generate_for_named_framework_;
const string named_framework_to_proto_path_mappings_path_;
map<string, string> proto_file_to_framework_name_; 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