Skip to content

Commit 3bb5424

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 e298fb5 commit 3bb5424

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
@@ -53,6 +53,8 @@
5353
#include "swift/Serialization/SerializationOptions.h"
5454
#include "swift/Strings.h"
5555
#include "clang/AST/DeclTemplate.h"
56+
#include "clang/Frontend/CompilerInstance.h"
57+
#include "clang/Serialization/ASTReader.h"
5658
#include "llvm/ADT/SmallSet.h"
5759
#include "llvm/ADT/SmallString.h"
5860
#include "llvm/ADT/StringExtras.h"
@@ -1297,15 +1299,27 @@ void Serializer::writeInputBlock() {
12971299
off_t importedHeaderSize = 0;
12981300
time_t importedHeaderModTime = 0;
12991301
std::string contents;
1300-
if (!Options.ImportedHeader.empty()) {
1302+
auto importedHeaderPath = Options.ImportedHeader;
1303+
// We do not want to serialize the explicitly-specified .pch path if one was
1304+
// provided. Instead we write out the path to the original header source so
1305+
// that clients can consume it.
1306+
if (llvm::sys::path::extension(importedHeaderPath)
1307+
.endswith(file_types::getExtension(file_types::TY_PCH)))
1308+
importedHeaderPath = clangImporter->getClangInstance()
1309+
.getASTReader()
1310+
->getModuleManager()
1311+
.lookupByFileName(importedHeaderPath)
1312+
->OriginalSourceFileName;
1313+
1314+
if (!importedHeaderPath.empty()) {
13011315
contents = clangImporter->getBridgingHeaderContents(
1302-
Options.ImportedHeader, importedHeaderSize, importedHeaderModTime);
1316+
importedHeaderPath, importedHeaderSize, importedHeaderModTime);
13031317
}
13041318
assert(publicImportSet.count(bridgingHeaderImport));
13051319
ImportedHeader.emit(ScratchRecord,
13061320
publicImportSet.count(bridgingHeaderImport),
13071321
importedHeaderSize, importedHeaderModTime,
1308-
Options.ImportedHeader);
1322+
importedHeaderPath);
13091323
if (!contents.empty()) {
13101324
contents.push_back('\0');
13111325
ImportedHeaderContents.emit(ScratchRecord, contents);

0 commit comments

Comments
 (0)