Skip to content

Commit 1e49c3b

Browse files
authored
Merge pull request swiftlang#63735 from artemcm/PrivatePeerCandidateDiscovery
[Dependency Scanning] Detect candidate files for `.private` interface files also
2 parents 6fd7762 + 6d59868 commit 1e49c3b

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
@@ -1214,12 +1214,22 @@ std::error_code ModuleInterfaceLoader::findModuleFilesInDirectory(
12141214
}
12151215

12161216
std::vector<std::string>
1217-
ModuleInterfaceCheckerImpl::getCompiledModuleCandidatesForInterface(
1218-
StringRef moduleName, StringRef interfacePath) {
1217+
ModuleInterfaceCheckerImpl::getCompiledModuleCandidatesForInterface(StringRef moduleName, StringRef interfacePath) {
12191218
// Derive .swiftmodule path from the .swiftinterface path.
1219+
auto interfaceExt = file_types::getExtension(file_types::TY_SwiftModuleInterfaceFile);
12201220
auto newExt = file_types::getExtension(file_types::TY_SwiftModuleFile);
1221-
llvm::SmallString<32> modulePath = interfacePath;
1222-
llvm::sys::path::replace_extension(modulePath, newExt);
1221+
llvm::SmallString<32> modulePath;
1222+
1223+
// When looking up the module for a private interface, strip the '.private.' section of the base name
1224+
if (interfacePath.endswith(".private." + interfaceExt.str())) {
1225+
auto newBaseName = llvm::sys::path::stem(llvm::sys::path::stem(interfacePath));
1226+
modulePath = llvm::sys::path::parent_path(interfacePath);
1227+
llvm::sys::path::append(modulePath, newBaseName + "." + newExt.str());
1228+
} else {
1229+
modulePath = interfacePath;
1230+
llvm::sys::path::replace_extension(modulePath, newExt);
1231+
}
1232+
12231233
ModuleInterfaceLoaderImpl Impl(Ctx, modulePath, interfacePath, moduleName,
12241234
CacheDir, PrebuiltCacheDir, BackupInterfaceDir,
12251235
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)