Add IsSDKRelative field to ModuleInterfaceLayout

When serializing the module interface path of an interface that
is part of the SDK, we serialize relative to the SDK path. During
deserialization we need to know if a path was serialized relative
to the SDK or not. The existing logic assumes any relative path
has been serialized relative to the SDK, which makes it impossible
to compile modules from relative swiftinterface paths that are not
part of the SDK.

Update the swiftmodule file to include an attribute to show if the
path was serialized relative to the SDK or not, which is used
during deserialization to correctly reconstruct the interface path.
This commit is contained in:
Richard Howell
2024-11-27 08:42:29 -08:00
parent 9e7fa1a023
commit a007833cc0
10 changed files with 50 additions and 11 deletions

View File

@@ -1615,6 +1615,8 @@ ModuleFileSharedCore::ModuleFileSharedCore(
break;
}
case input_block::MODULE_INTERFACE_PATH: {
input_block::ModuleInterfaceLayout::readRecord(
scratch, IsModuleInterfaceSDKRelative);
ModuleInterfacePath = blobData;
break;
}
@@ -1837,10 +1839,12 @@ bool ModuleFileSharedCore::hasSourceInfo() const {
std::string ModuleFileSharedCore::resolveModuleDefiningFilePath(const StringRef SDKPath) const {
if (!ModuleInterfacePath.empty()) {
std::string interfacePath = ModuleInterfacePath.str();
if (llvm::sys::path::is_relative(interfacePath) && !ModuleInterfacePath.starts_with(SDKPath)) {
SmallString<128> absoluteInterfacePath(SDKPath);
llvm::sys::path::append(absoluteInterfacePath, interfacePath);
return absoluteInterfacePath.str().str();
if (IsModuleInterfaceSDKRelative &&
!ModuleInterfacePath.starts_with(SDKPath) &&
llvm::sys::path::is_relative(interfacePath)) {
SmallString<128> resolvedPath(SDKPath);
llvm::sys::path::append(resolvedPath, interfacePath);
return resolvedPath.str().str();
} else
return interfacePath;
} else