Don't serialize relative resource dir module paths

This commit is contained in:
Richard Howell
2024-09-30 12:58:33 -07:00
parent b5a85ed8dc
commit 7aa94723a6
6 changed files with 29 additions and 1 deletions

View File

@@ -105,6 +105,12 @@ bool ExplicitModuleInterfaceBuilder::collectDepsForSerialization(
path::native(SDKPath);
SmallString<128> ResourcePath(Opts.RuntimeResourcePath);
path::native(ResourcePath);
// When compiling with a relative resource dir, the clang
// importer will track inputs with absolute paths. To avoid
// serializing resource dir inputs we need to check for
// relative _and_ absolute prefixes.
SmallString<128> AbsResourcePath(ResourcePath);
llvm::sys::fs::make_absolute(AbsResourcePath);
auto DTDeps = Instance.getDependencyTracker()->getDependencies();
SmallVector<std::string, 16> InitialDepNames(DTDeps.begin(), DTDeps.end());
@@ -146,7 +152,7 @@ bool ExplicitModuleInterfaceBuilder::collectDepsForSerialization(
}
// Don't serialize compiler-relative deps so the cache is relocatable.
if (DepName.starts_with(ResourcePath))
if (DepName.starts_with(ResourcePath) || DepName.starts_with(AbsResourcePath))
continue;
auto Status = fs.status(DepName);

View File

@@ -0,0 +1,4 @@
Name: ClangModule
Globals:
- Name: CMThing
SwiftName: SwiftThing

View File

@@ -0,0 +1 @@
struct CMThing {};

View File

@@ -0,0 +1,3 @@
module ClangModule [system] {
header "ClangModuleHeader.h"
}

View File

@@ -2,6 +2,7 @@
// swift-module-flags: -target arm64-apple-macosx15.0 -module-name OtherModule -O
import Swift
import ClangModule
public struct OtherStruct {
var x : Int

View File

@@ -0,0 +1,13 @@
// REQUIRES: OS=macosx
// RUN: %empty-directory(%t.relative_resource_path)
// RUN: %empty-directory(%t.mcp)
// RUN: cp -R %S/Inputs/resource_dir %t.relative_resource_path/
// RUN: cd %t.relative_resource_path
// RUN: %target-swift-frontend(mock-sdk: -sdk %S/Inputs/stdlib_rebuild -module-cache-path %t.mcp) -target arm64-apple-macosx15.0 \
// RUN: -resource-dir resource_dir -compile-module-from-interface -o OtherModule.swiftmodule \
// RUN: %S/Inputs/stdlib_rebuild/usr/lib/swift/OtherModule.swiftmodule/arm64-apple-macos.swiftinterface
// RUN: llvm-bcanalyzer -dump OtherModule.swiftmodule | %FileCheck %s
// CHECK-NOT: <DEPENDENCY_DIRECTORY abbrevid=11/> blob data = '/