[Serialization] Always serialize module-defining '.swiftinterface', even if SDK-relative.

The clients, upon loading, will resolve the SDK-relative path to their SDK location.

Resolves rdar://120673684
This commit is contained in:
Artem Chikin
2024-01-10 10:02:45 -08:00
parent e37ecac163
commit de626abf71
6 changed files with 106 additions and 4 deletions

View File

@@ -91,6 +91,19 @@ static bool isTargetTooNew(const llvm::Triple &moduleTarget,
return ctxTarget.isOSVersionLT(moduleTarget);
}
std::string ModuleFile::resolveModuleDefiningFilename(const ASTContext &ctx) {
if (!Core->ModuleInterfacePath.empty()) {
std::string interfacePath = Core->ModuleInterfacePath.str();
if (llvm::sys::path::is_relative(interfacePath)) {
SmallString<128> absoluteInterfacePath(ctx.SearchPathOpts.getSDKPath());
llvm::sys::path::append(absoluteInterfacePath, interfacePath);
return absoluteInterfacePath.str().str();
} else
return interfacePath;
} else
return getModuleLoadedFilename().str();
}
namespace swift {
namespace serialization {
bool areCompatible(const llvm::Triple &moduleTarget,
@@ -257,6 +270,8 @@ Status ModuleFile::associateWithFileContext(FileUnit *file, SourceLoc diagLoc,
}
ASTContext &ctx = getContext();
// Resolve potentially-SDK-relative module-defining .swiftinterface path
ResolvedModuleDefiningFilename = resolveModuleDefiningFilename(ctx);
llvm::Triple moduleTarget(llvm::Triple::normalize(Core->TargetTriple));
if (!areCompatible(moduleTarget, ctx.LangOpts.Target)) {