Skip to content

Commit 3aed095

Browse files
authored
Merge pull request #76964 from rmaz/relres
Don't serialize relative resource dir paths in swiftmodules
2 parents f6a0f55 + 7aa9472 commit 3aed095

File tree

6 files changed

+29
-1
lines changed

6 files changed

+29
-1
lines changed

lib/Frontend/ModuleInterfaceBuilder.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ bool ExplicitModuleInterfaceBuilder::collectDepsForSerialization(
105105
path::native(SDKPath);
106106
SmallString<128> ResourcePath(Opts.RuntimeResourcePath);
107107
path::native(ResourcePath);
108+
// When compiling with a relative resource dir, the clang
109+
// importer will track inputs with absolute paths. To avoid
110+
// serializing resource dir inputs we need to check for
111+
// relative _and_ absolute prefixes.
112+
SmallString<128> AbsResourcePath(ResourcePath);
113+
llvm::sys::fs::make_absolute(AbsResourcePath);
108114

109115
auto DTDeps = Instance.getDependencyTracker()->getDependencies();
110116
SmallVector<std::string, 16> InitialDepNames(DTDeps.begin(), DTDeps.end());
@@ -146,7 +152,7 @@ bool ExplicitModuleInterfaceBuilder::collectDepsForSerialization(
146152
}
147153

148154
// Don't serialize compiler-relative deps so the cache is relocatable.
149-
if (DepName.starts_with(ResourcePath))
155+
if (DepName.starts_with(ResourcePath) || DepName.starts_with(AbsResourcePath))
150156
continue;
151157

152158
auto Status = fs.status(DepName);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Name: ClangModule
2+
Globals:
3+
- Name: CMThing
4+
SwiftName: SwiftThing
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
struct CMThing {};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module ClangModule [system] {
2+
header "ClangModuleHeader.h"
3+
}

test/ModuleInterface/Inputs/stdlib_rebuild/usr/lib/swift/OtherModule.swiftmodule/arm64-apple-macos.swiftinterface

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// swift-module-flags: -target arm64-apple-macosx15.0 -module-name OtherModule -O
33

44
import Swift
5+
import ClangModule
56

67
public struct OtherStruct {
78
var x : Int
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// REQUIRES: OS=macosx
2+
3+
// RUN: %empty-directory(%t.relative_resource_path)
4+
// RUN: %empty-directory(%t.mcp)
5+
// RUN: cp -R %S/Inputs/resource_dir %t.relative_resource_path/
6+
// RUN: cd %t.relative_resource_path
7+
8+
// RUN: %target-swift-frontend(mock-sdk: -sdk %S/Inputs/stdlib_rebuild -module-cache-path %t.mcp) -target arm64-apple-macosx15.0 \
9+
// RUN: -resource-dir resource_dir -compile-module-from-interface -o OtherModule.swiftmodule \
10+
// RUN: %S/Inputs/stdlib_rebuild/usr/lib/swift/OtherModule.swiftmodule/arm64-apple-macos.swiftinterface
11+
// RUN: llvm-bcanalyzer -dump OtherModule.swiftmodule | %FileCheck %s
12+
13+
// CHECK-NOT: <DEPENDENCY_DIRECTORY abbrevid=11/> blob data = '/

0 commit comments

Comments
 (0)