Skip to content

Commit 6d59868

Browse files
committed
[Dependency Scanning] Detect candidate files for .private interface files also
1 parent e851856 commit 6d59868

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,12 +1185,22 @@ std::error_code ModuleInterfaceLoader::findModuleFilesInDirectory(
11851185
}
11861186

11871187
std::vector<std::string>
1188-
ModuleInterfaceCheckerImpl::getCompiledModuleCandidatesForInterface(
1189-
StringRef moduleName, StringRef interfacePath) {
1188+
ModuleInterfaceCheckerImpl::getCompiledModuleCandidatesForInterface(StringRef moduleName, StringRef interfacePath) {
11901189
// Derive .swiftmodule path from the .swiftinterface path.
1190+
auto interfaceExt = file_types::getExtension(file_types::TY_SwiftModuleInterfaceFile);
11911191
auto newExt = file_types::getExtension(file_types::TY_SwiftModuleFile);
1192-
llvm::SmallString<32> modulePath = interfacePath;
1193-
llvm::sys::path::replace_extension(modulePath, newExt);
1192+
llvm::SmallString<32> modulePath;
1193+
1194+
// When looking up the module for a private interface, strip the '.private.' section of the base name
1195+
if (interfacePath.endswith(".private." + interfaceExt.str())) {
1196+
auto newBaseName = llvm::sys::path::stem(llvm::sys::path::stem(interfacePath));
1197+
modulePath = llvm::sys::path::parent_path(interfacePath);
1198+
llvm::sys::path::append(modulePath, newBaseName + "." + newExt.str());
1199+
} else {
1200+
modulePath = interfacePath;
1201+
llvm::sys::path::replace_extension(modulePath, newExt);
1202+
}
1203+
11941204
ModuleInterfaceLoaderImpl Impl(Ctx, modulePath, interfacePath, moduleName,
11951205
CacheDir, PrebuiltCacheDir, BackupInterfaceDir,
11961206
SourceLoc(), Opts,
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// REQUIRES: objc_interop
2+
// RUN: %empty-directory(%t)
3+
// RUN: mkdir -p %t/clang-module-cache
4+
// RUN: mkdir -p %t/Frameworks
5+
// RUN: mkdir -p %t/Frameworks/E.framework/
6+
// RUN: mkdir -p %t/Frameworks/E.framework/Modules
7+
// RUN: mkdir -p %t/Frameworks/E.framework/Modules/E.swiftmodule
8+
9+
// Copy over the interface
10+
// RUN: cp %S/Inputs/Swift/E.swiftinterface %t/Frameworks/E.framework/Modules/E.swiftmodule/%module-target-triple.private.swiftinterface
11+
// RUN: cp %S/Inputs/Swift/E.swiftinterface %t/Frameworks/E.framework/Modules/E.swiftmodule/%module-target-triple.swiftinterface
12+
13+
// Build a dependency into a binary module
14+
// RUN: echo "public func foo() {}" >> %t/foo.swift
15+
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/Frameworks/E.framework/Modules/E.swiftmodule/%module-target-triple.swiftmodule -module-cache-path %t.module-cache %t/foo.swift -module-name E
16+
17+
// Run the scan
18+
// RUN: %target-swift-frontend -scan-dependencies %s -o %t/deps.json -F %t/Frameworks/ -sdk %t
19+
// RUN: %FileCheck %s < %t/deps.json
20+
21+
import E
22+
23+
// Ensure the private interface is the canonical one
24+
// CHECK: "moduleInterfacePath": {{.*}}{{/|\\}}E.framework{{/|\\}}Modules{{/|\\}}E.swiftmodule{{/|\\}}{{.*}}.private.swiftinterface
25+
// Ensure the adjacent binary module is a candidate
26+
// CHECK: "compiledModuleCandidates": [
27+
// CHECK-NEXT: {{.*}}{{/|\\}}E.framework{{/|\\}}Modules{{/|\\}}E.swiftmodule{{/|\\}}{{.*}}.swiftmodule

0 commit comments

Comments
 (0)