|
52 | 52 | #include "swift/Serialization/SerializationOptions.h"
|
53 | 53 | #include "swift/Strings.h"
|
54 | 54 | #include "clang/AST/DeclTemplate.h"
|
| 55 | +#include "clang/Frontend/CompilerInstance.h" |
| 56 | +#include "clang/Serialization/ASTReader.h" |
55 | 57 | #include "llvm/ADT/SmallSet.h"
|
56 | 58 | #include "llvm/ADT/SmallString.h"
|
57 | 59 | #include "llvm/ADT/StringExtras.h"
|
@@ -1296,15 +1298,27 @@ void Serializer::writeInputBlock() {
|
1296 | 1298 | off_t importedHeaderSize = 0;
|
1297 | 1299 | time_t importedHeaderModTime = 0;
|
1298 | 1300 | std::string contents;
|
1299 |
| - if (!Options.ImportedHeader.empty()) { |
| 1301 | + auto importedHeaderPath = Options.ImportedHeader; |
| 1302 | + // We do not want to serialize the explicitly-specified .pch path if one was |
| 1303 | + // provided. Instead we write out the path to the original header source so |
| 1304 | + // that clients can consume it. |
| 1305 | + if (llvm::sys::path::extension(importedHeaderPath) |
| 1306 | + .endswith(file_types::getExtension(file_types::TY_PCH))) |
| 1307 | + importedHeaderPath = clangImporter->getClangInstance() |
| 1308 | + .getASTReader() |
| 1309 | + ->getModuleManager() |
| 1310 | + .lookupByFileName(importedHeaderPath) |
| 1311 | + ->OriginalSourceFileName; |
| 1312 | + |
| 1313 | + if (!importedHeaderPath.empty()) { |
1300 | 1314 | contents = clangImporter->getBridgingHeaderContents(
|
1301 |
| - Options.ImportedHeader, importedHeaderSize, importedHeaderModTime); |
| 1315 | + importedHeaderPath, importedHeaderSize, importedHeaderModTime); |
1302 | 1316 | }
|
1303 | 1317 | assert(publicImportSet.count(bridgingHeaderImport));
|
1304 | 1318 | ImportedHeader.emit(ScratchRecord,
|
1305 | 1319 | publicImportSet.count(bridgingHeaderImport),
|
1306 | 1320 | importedHeaderSize, importedHeaderModTime,
|
1307 |
| - Options.ImportedHeader); |
| 1321 | + importedHeaderPath); |
1308 | 1322 | if (!contents.empty()) {
|
1309 | 1323 | contents.push_back('\0');
|
1310 | 1324 | ImportedHeaderContents.emit(ScratchRecord, contents);
|
|
0 commit comments