Skip to content

Commit 68a78a6

Browse files
committed
[Serialization] Serialize source '.h' path when an explicit '.pch' bridging header is provided
In explicit module builds, bridging header is passed directly as a '.pch' input. Loading clients may not be able to directly import this PCH because it was built against mis-matched dependencies with a different context hash. So instead they should directly injest the '.h' depndency and build it against their own set of dependencies.
1 parent a66f28e commit 68a78a6

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

lib/Serialization/Serialization.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
#include "swift/Serialization/SerializationOptions.h"
5353
#include "swift/Strings.h"
5454
#include "clang/AST/DeclTemplate.h"
55+
#include "clang/Frontend/CompilerInstance.h"
56+
#include "clang/Serialization/ASTReader.h"
5557
#include "llvm/ADT/SmallSet.h"
5658
#include "llvm/ADT/SmallString.h"
5759
#include "llvm/ADT/StringExtras.h"
@@ -1296,15 +1298,27 @@ void Serializer::writeInputBlock() {
12961298
off_t importedHeaderSize = 0;
12971299
time_t importedHeaderModTime = 0;
12981300
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()) {
13001314
contents = clangImporter->getBridgingHeaderContents(
1301-
Options.ImportedHeader, importedHeaderSize, importedHeaderModTime);
1315+
importedHeaderPath, importedHeaderSize, importedHeaderModTime);
13021316
}
13031317
assert(publicImportSet.count(bridgingHeaderImport));
13041318
ImportedHeader.emit(ScratchRecord,
13051319
publicImportSet.count(bridgingHeaderImport),
13061320
importedHeaderSize, importedHeaderModTime,
1307-
Options.ImportedHeader);
1321+
importedHeaderPath);
13081322
if (!contents.empty()) {
13091323
contents.push_back('\0');
13101324
ImportedHeaderContents.emit(ScratchRecord, contents);

0 commit comments

Comments
 (0)