[Caching] Embed bridging header in binary module correctly when caching

When caching is enabled with include-tree, the bridging header PCH is
created from the include tree directly. Setup the rewriter correctly
when embedding the bridging header into swift binary module.

rdar://125719747
This commit is contained in:
Steven Wu
2024-04-03 08:50:34 -07:00
parent 01d891ad99
commit 7a68d364f4
6 changed files with 137 additions and 17 deletions

View File

@@ -1321,21 +1321,25 @@ void Serializer::writeInputBlock() {
time_t importedHeaderModTime = 0;
std::string contents;
auto importedHeaderPath = Options.ImportedHeader;
std::string pchIncludeTree;
// We do not want to serialize the explicitly-specified .pch path if one was
// provided. Instead we write out the path to the original header source so
// that clients can consume it.
if (Options.ExplicitModuleBuild &&
llvm::sys::path::extension(importedHeaderPath)
.ends_with(file_types::getExtension(file_types::TY_PCH)))
importedHeaderPath = clangImporter->getClangInstance()
.getASTReader()
->getModuleManager()
.lookupByFileName(importedHeaderPath)
->OriginalSourceFileName;
.ends_with(file_types::getExtension(file_types::TY_PCH))) {
auto *pch = clangImporter->getClangInstance()
.getASTReader()
->getModuleManager()
.lookupByFileName(importedHeaderPath);
pchIncludeTree = pch->IncludeTreeID;
importedHeaderPath = pch->OriginalSourceFileName;
}
if (!importedHeaderPath.empty()) {
contents = clangImporter->getBridgingHeaderContents(
importedHeaderPath, importedHeaderSize, importedHeaderModTime);
importedHeaderPath, importedHeaderSize, importedHeaderModTime,
pchIncludeTree);
}
assert(publicImportSet.count(bridgingHeaderImport));
ImportedHeader.emit(ScratchRecord,