|
@@ -54,14 +54,16 @@ namespace {
|
|
|
|
|
|
class ImportWriter {
|
|
|
public:
|
|
|
- ImportWriter() {}
|
|
|
+ ImportWriter(const Options& options) : options_(options) {}
|
|
|
|
|
|
void AddFile(const FileGenerator* file);
|
|
|
void Print(io::Printer *printer) const;
|
|
|
|
|
|
private:
|
|
|
+ const Options options_;
|
|
|
vector<string> protobuf_framework_imports_;
|
|
|
vector<string> protobuf_non_framework_imports_;
|
|
|
+ vector<string> other_framework_imports_;
|
|
|
vector<string> other_imports_;
|
|
|
};
|
|
|
|
|
@@ -72,6 +74,10 @@ void ImportWriter::AddFile(const FileGenerator* file) {
|
|
|
protobuf_framework_imports_.push_back(
|
|
|
FilePathBasename(file_descriptor) + extension);
|
|
|
protobuf_non_framework_imports_.push_back(file->Path() + extension);
|
|
|
+ } else if (!options_.generate_for_named_framework.empty()) {
|
|
|
+ other_framework_imports_.push_back(
|
|
|
+ options_.generate_for_named_framework + "/" +
|
|
|
+ FilePathBasename(file_descriptor) + extension);
|
|
|
} else {
|
|
|
other_imports_.push_back(file->Path() + extension);
|
|
|
}
|
|
@@ -81,6 +87,8 @@ void ImportWriter::Print(io::Printer *printer) const {
|
|
|
assert(protobuf_non_framework_imports_.size() ==
|
|
|
protobuf_framework_imports_.size());
|
|
|
|
|
|
+ bool add_blank_line = false;
|
|
|
+
|
|
|
if (protobuf_framework_imports_.size() > 0) {
|
|
|
const string framework_name(ProtobufLibraryFrameworkName);
|
|
|
const string cpp_symbol(ProtobufFrameworkImportSymbol(framework_name));
|
|
@@ -106,12 +114,29 @@ void ImportWriter::Print(io::Printer *printer) const {
|
|
|
printer->Print(
|
|
|
"#endif\n");
|
|
|
|
|
|
- if (other_imports_.size() > 0) {
|
|
|
+ add_blank_line = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (other_framework_imports_.size() > 0) {
|
|
|
+ if (add_blank_line) {
|
|
|
printer->Print("\n");
|
|
|
}
|
|
|
+
|
|
|
+ for (vector<string>::const_iterator iter = other_framework_imports_.begin();
|
|
|
+ iter != other_framework_imports_.end(); ++iter) {
|
|
|
+ printer->Print(
|
|
|
+ " #import <$header$>\n",
|
|
|
+ "header", *iter);
|
|
|
+ }
|
|
|
+
|
|
|
+ add_blank_line = true;
|
|
|
}
|
|
|
|
|
|
if (other_imports_.size() > 0) {
|
|
|
+ if (add_blank_line) {
|
|
|
+ printer->Print("\n");
|
|
|
+ }
|
|
|
+
|
|
|
for (vector<string>::const_iterator iter = other_imports_.begin();
|
|
|
iter != other_imports_.end(); ++iter) {
|
|
|
printer->Print(
|
|
@@ -156,7 +181,7 @@ FileGenerator::~FileGenerator() {
|
|
|
}
|
|
|
|
|
|
void FileGenerator::GenerateHeader(io::Printer *printer) {
|
|
|
- PrintFilePreamble(printer, "GPBProtocolBuffers.h");
|
|
|
+ PrintFileRuntimePreamble(printer, "GPBProtocolBuffers.h");
|
|
|
|
|
|
// Add some verification that the generated code matches the source the
|
|
|
// code is being compiled with.
|
|
@@ -170,7 +195,7 @@ void FileGenerator::GenerateHeader(io::Printer *printer) {
|
|
|
|
|
|
// #import any headers for "public imports" in the proto file.
|
|
|
{
|
|
|
- ImportWriter import_writer;
|
|
|
+ ImportWriter import_writer(options_);
|
|
|
const vector<FileGenerator *> &dependency_generators = DependencyGenerators();
|
|
|
for (vector<FileGenerator *>::const_iterator iter =
|
|
|
dependency_generators.begin();
|
|
@@ -273,10 +298,10 @@ void FileGenerator::GenerateHeader(io::Printer *printer) {
|
|
|
|
|
|
void FileGenerator::GenerateSource(io::Printer *printer) {
|
|
|
// #import the runtime support.
|
|
|
- PrintFilePreamble(printer, "GPBProtocolBuffers_RuntimeSupport.h");
|
|
|
+ PrintFileRuntimePreamble(printer, "GPBProtocolBuffers_RuntimeSupport.h");
|
|
|
|
|
|
{
|
|
|
- ImportWriter import_writer;
|
|
|
+ ImportWriter import_writer(options_);
|
|
|
|
|
|
// #import the header for this proto file.
|
|
|
import_writer.AddFile(this);
|
|
@@ -471,7 +496,10 @@ const vector<FileGenerator *> &FileGenerator::DependencyGenerators() {
|
|
|
return dependency_generators_;
|
|
|
}
|
|
|
|
|
|
-void FileGenerator::PrintFilePreamble(
|
|
|
+// Helper to print the import of the runtime support at the top of generated
|
|
|
+// 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 {
|
|
|
printer->Print(
|
|
|
"// Generated by the protocol buffer compiler. DO NOT EDIT!\n"
|