Skip to content

Commit c93a4a4

Browse files
authored
Merge pull request #42486 from xymus/ignore-adjacent-public-swiftmodule
[ModuleInterface] Ignore adjacent swiftmodules under the Frameworks folder
2 parents fa3ff89 + 3aebf28 commit c93a4a4

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -651,10 +651,20 @@ class ModuleInterfaceLoaderImpl {
651651

652652
std::pair<std::string, std::string> getCompiledModuleCandidates() {
653653
std::pair<std::string, std::string> result;
654-
// Keep track of whether we should attempt to load a .swiftmodule adjacent
655-
// to the .swiftinterface.
654+
// Should we attempt to load a swiftmodule adjacent to the swiftinterface?
656655
bool shouldLoadAdjacentModule = true;
657656

657+
// Don't use the adjacent swiftmodule for frameworks from the public
658+
// Frameworks folder of the SDK.
659+
SmallString<128> publicFrameworksPath;
660+
llvm::sys::path::append(publicFrameworksPath,
661+
ctx.SearchPathOpts.getSDKPath(),
662+
"System", "Library", "Frameworks");
663+
if (!ctx.SearchPathOpts.getSDKPath().empty() &&
664+
modulePath.startswith(publicFrameworksPath)) {
665+
shouldLoadAdjacentModule = false;
666+
}
667+
658668
switch (loadMode) {
659669
case ModuleLoadingMode::OnlyInterface:
660670
// Always skip both the caches and adjacent modules, and always build the
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %empty-directory(%t/cache)
3+
// REQUIRES: VENDOR=apple
4+
5+
/// Prepare the SDK.
6+
// RUN: cp -r %S/../Sema/Inputs/public-private-sdk %t/sdk
7+
// RUN: %target-swift-frontend -emit-module -module-name PublicSwift -enable-library-evolution -swift-version 5 \
8+
// RUN: %t/sdk/System/Library/Frameworks/PublicSwift.framework/Modules/PublicSwift.swiftmodule/source.swift \
9+
// RUN: -o %t/sdk/System/Library/Frameworks/PublicSwift.framework/Modules/PublicSwift.swiftmodule/%target-swiftmodule-name \
10+
// RUN: -emit-module-interface-path %t/sdk/System/Library/Frameworks/PublicSwift.framework/Modules/PublicSwift.swiftmodule/%target-swiftinterface-name
11+
// RUN: %target-swift-typecheck-module-from-interface(%t/sdk/System/Library/Frameworks/PublicSwift.framework/Modules/PublicSwift.swiftmodule/%target-swiftinterface-name) -module-name PublicSwift
12+
// RUN: %target-swift-frontend -emit-module -module-name PrivateSwift -enable-library-evolution -swift-version 5 \
13+
// RUN: %t/sdk/System/Library/PrivateFrameworks/PrivateSwift.framework/Modules/PrivateSwift.swiftmodule/source.swift \
14+
// RUN: -o %t/sdk/System/Library/PrivateFrameworks/PrivateSwift.framework/Modules/PrivateSwift.swiftmodule/%target-swiftmodule-name \
15+
// RUN: -emit-module-interface-path %t/sdk/System/Library/PrivateFrameworks/PrivateSwift.framework/Modules/PrivateSwift.swiftmodule/%target-swiftinterface-name
16+
// RUN: %target-swift-typecheck-module-from-interface(%t/sdk/System/Library/PrivateFrameworks/PrivateSwift.framework/Modules/PrivateSwift.swiftmodule/%target-swiftinterface-name) -module-name PrivateSwift
17+
18+
/// Break the swiftmodules.
19+
// RUN: echo "This is a malformed swiftmodule" > %t/sdk/System/Library/Frameworks/PublicSwift.framework/Modules/PublicSwift.swiftmodule/%target-swiftmodule-name
20+
// RUN: echo "This is a malformed swiftmodule" > %t/sdk/System/Library/PrivateFrameworks/PrivateSwift.framework/Modules/PrivateSwift.swiftmodule/%target-swiftmodule-name
21+
22+
/// There should be no attempt at loading the malformed PublicSwift swiftmodule.
23+
/// This means no notes about:
24+
/// * compiled module is out of date
25+
/// * unable to load compiled module '*': malformed
26+
// RUN: %target-swift-frontend -typecheck %s -sdk %t/sdk \
27+
// RUN: -module-name Main -module-cache-path %t/cache \
28+
// RUN: -F %t/sdk/System/Library/PrivateFrameworks/ \
29+
// RUN: -verify -Rmodule-interface-rebuild
30+
31+
import PublicSwift // expected-remark {{rebuilding module 'PublicSwift' from interface}}
32+
33+
// The private adjacent module under PrivateFrameworks should still be tried first, and then rebuilt.
34+
import PrivateSwift
35+
// expected-remark @-1 {{rebuilding module 'PrivateSwift' from interface}}
36+
// expected-note @-2 {{compiled module is out of date}}
37+
// expected-note @-3 {{: malformed}}

0 commit comments

Comments
 (0)