|
|
@ -162,78 +162,112 @@ void ImportWriter::AddFile(const FileDescriptor* file, |
|
|
|
other_imports_.push_back(FilePath(file) + header_extension); |
|
|
|
other_imports_.push_back(FilePath(file) + header_extension); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void ImportWriter::Print(io::Printer* printer) const { |
|
|
|
void ImportWriter::Emit(io::Printer* p) const { |
|
|
|
bool add_blank_line = false; |
|
|
|
p->Emit( |
|
|
|
|
|
|
|
{ |
|
|
|
if (!protobuf_imports_.empty()) { |
|
|
|
{"runtime_import", |
|
|
|
PrintRuntimeImports(printer, protobuf_imports_, runtime_import_prefix_); |
|
|
|
[&] { |
|
|
|
add_blank_line = true; |
|
|
|
if (!protobuf_imports_.empty()) { |
|
|
|
} |
|
|
|
EmitRuntimeImports(p, protobuf_imports_, runtime_import_prefix_); |
|
|
|
|
|
|
|
} |
|
|
|
if (!other_framework_imports_.empty()) { |
|
|
|
}}, |
|
|
|
if (add_blank_line) { |
|
|
|
{"other_framework_imports", |
|
|
|
printer->Print("\n"); |
|
|
|
[&] { |
|
|
|
} |
|
|
|
for (const auto& header : other_framework_imports_) { |
|
|
|
|
|
|
|
p->Emit({{"header", header}}, |
|
|
|
for (std::vector<std::string>::const_iterator iter = |
|
|
|
R"objc( |
|
|
|
other_framework_imports_.begin(); |
|
|
|
#import <$header$> |
|
|
|
iter != other_framework_imports_.end(); ++iter) { |
|
|
|
)objc"); |
|
|
|
printer->Print("#import <$header$>\n", "header", *iter); |
|
|
|
} |
|
|
|
} |
|
|
|
}}, |
|
|
|
|
|
|
|
{"other_imports", |
|
|
|
add_blank_line = true; |
|
|
|
[&] { |
|
|
|
} |
|
|
|
for (const auto& header : other_imports_) { |
|
|
|
|
|
|
|
p->Emit({{"header", header}}, |
|
|
|
if (!other_imports_.empty()) { |
|
|
|
R"objc( |
|
|
|
if (add_blank_line) { |
|
|
|
#import "$header$" |
|
|
|
printer->Print("\n"); |
|
|
|
)objc"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}}, |
|
|
|
for (std::vector<std::string>::const_iterator iter = other_imports_.begin(); |
|
|
|
}, |
|
|
|
iter != other_imports_.end(); ++iter) { |
|
|
|
R"objc( |
|
|
|
printer->Print("#import \"$header$\"\n", "header", *iter); |
|
|
|
$runtime_import$; |
|
|
|
} |
|
|
|
$other_framework_imports$; |
|
|
|
} |
|
|
|
$other_imports$; |
|
|
|
|
|
|
|
)objc"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void ImportWriter::PrintRuntimeImports( |
|
|
|
void ImportWriter::EmitRuntimeImports( |
|
|
|
io::Printer* printer, const std::vector<std::string>& header_to_import, |
|
|
|
io::Printer* p, const std::vector<std::string>& header_to_import, |
|
|
|
const std::string& runtime_import_prefix, bool default_cpp_symbol) { |
|
|
|
const std::string& runtime_import_prefix, bool default_cpp_symbol) { |
|
|
|
// Given an override, use that.
|
|
|
|
// Given an override, use that.
|
|
|
|
if (!runtime_import_prefix.empty()) { |
|
|
|
if (!runtime_import_prefix.empty()) { |
|
|
|
for (const auto& header : header_to_import) { |
|
|
|
p->Emit( |
|
|
|
printer->Print(" #import \"$import_prefix$/$header$\"\n", "import_prefix", |
|
|
|
{ |
|
|
|
runtime_import_prefix, "header", header); |
|
|
|
{"import_prefix", runtime_import_prefix}, |
|
|
|
} |
|
|
|
{"imports", |
|
|
|
|
|
|
|
[&] { |
|
|
|
|
|
|
|
for (const auto& header : header_to_import) { |
|
|
|
|
|
|
|
p->Emit({{"header", header}}, |
|
|
|
|
|
|
|
R"objc( |
|
|
|
|
|
|
|
#import "$import_prefix$/$header$" |
|
|
|
|
|
|
|
)objc"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}}, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
R"objc( |
|
|
|
|
|
|
|
$imports$; |
|
|
|
|
|
|
|
)objc"); |
|
|
|
|
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const std::string framework_name(ProtobufLibraryFrameworkName); |
|
|
|
auto v = p->WithVars({ |
|
|
|
const std::string cpp_symbol(ProtobufFrameworkImportSymbol(framework_name)); |
|
|
|
{"cpp_symbol", |
|
|
|
|
|
|
|
ProtobufFrameworkImportSymbol(ProtobufLibraryFrameworkName)}, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
if (default_cpp_symbol) { |
|
|
|
if (default_cpp_symbol) { |
|
|
|
printer->Print( |
|
|
|
p->Emit( |
|
|
|
// clang-format off
|
|
|
|
R"objc( |
|
|
|
"// 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
|
|
|
|
"// imports needed when using CocoaPods.\n" |
|
|
|
// imports needed when using CocoaPods.
|
|
|
|
"#if !defined($cpp_symbol$)\n" |
|
|
|
#if !defined($cpp_symbol$) |
|
|
|
" #define $cpp_symbol$ 0\n" |
|
|
|
#define $cpp_symbol$ 0 |
|
|
|
"#endif\n" |
|
|
|
#endif |
|
|
|
"\n", |
|
|
|
|
|
|
|
// clang-format on
|
|
|
|
)objc"); |
|
|
|
"cpp_symbol", cpp_symbol); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
printer->Print("#if $cpp_symbol$\n", "cpp_symbol", cpp_symbol); |
|
|
|
p->Emit( |
|
|
|
for (const auto& header : header_to_import) { |
|
|
|
{ |
|
|
|
printer->Print(" #import <$framework_name$/$header$>\n", "framework_name", |
|
|
|
{"framework_name", ProtobufLibraryFrameworkName}, |
|
|
|
framework_name, "header", header); |
|
|
|
{"framework_imports", |
|
|
|
} |
|
|
|
[&] { |
|
|
|
printer->Print("#else\n"); |
|
|
|
for (const auto& header : header_to_import) { |
|
|
|
for (const auto& header : header_to_import) { |
|
|
|
p->Emit({{"header", header}}, |
|
|
|
printer->Print(" #import \"$header$\"\n", "header", header); |
|
|
|
R"objc( |
|
|
|
} |
|
|
|
#import <$framework_name$/$header$> |
|
|
|
printer->Print("#endif\n"); |
|
|
|
)objc"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}}, |
|
|
|
|
|
|
|
{"raw_imports", |
|
|
|
|
|
|
|
[&] { |
|
|
|
|
|
|
|
for (const auto& header : header_to_import) { |
|
|
|
|
|
|
|
p->Emit({{"header", header}}, |
|
|
|
|
|
|
|
R"objc( |
|
|
|
|
|
|
|
#import "$header$" |
|
|
|
|
|
|
|
)objc"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}}, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
R"objc( |
|
|
|
|
|
|
|
#if $cpp_symbol$ |
|
|
|
|
|
|
|
$framework_imports$ |
|
|
|
|
|
|
|
#else |
|
|
|
|
|
|
|
$raw_imports$ |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
)objc"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void ImportWriter::ParseFrameworkMappings() { |
|
|
|
void ImportWriter::ParseFrameworkMappings() { |
|
|
|