Skip to content

Commit 1eab3b5

Browse files
[ModuleCache] Prefer module cache passed on the command-line for checker
When setting up the ModuleInterfaceChecker, prefer using the module cache path from command-line invocation `-module-cache-path` before falling back to clang options. Usually those two yield the same result, except for LLDB under direct cc1 argument mode and explicit module build. Under such mode, the cc1 option for module cache path will be stripped since the output PCMs are explicit passed as output. When LLDB attempted to do an implicit module compilation for the swift interface, it will not be able to locate the module cache path from cc1 arguments. On the other hand, the module cache option has already be inherited by the sub-instance so it can just directly be located there. rdar://137610484
1 parent 844d103 commit 1eab3b5

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

lib/Frontend/Frontend.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,8 +818,11 @@ bool CompilerInstance::setUpModuleLoaders() {
818818
}
819819

820820
// Configure ModuleInterfaceChecker for the ASTContext.
821+
auto CacheFromInvocation = getInvocation().getClangModuleCachePath();
821822
auto const &Clang = clangImporter->getClangInstance();
822-
std::string ModuleCachePath = getModuleCachePathFromClang(Clang);
823+
std::string ModuleCachePath = CacheFromInvocation.empty()
824+
? getModuleCachePathFromClang(Clang)
825+
: CacheFromInvocation.str();
823826
auto &FEOpts = Invocation.getFrontendOptions();
824827
ModuleInterfaceLoaderOptions LoaderOpts(FEOpts);
825828
Context->addModuleInterfaceChecker(
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// UNSUPPORTED: OS=windows-msvc
2+
// RUN: %empty-directory(%t)
3+
// RUN: split-file %s %t
4+
5+
// RUN: %target-swift-frontend -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import -parse-stdlib -I %t -emit-module-interface-path %t/LeafModule.swiftinterface -module-name LeafModule %t/leaf.swift -emit-module -o /dev/null
6+
// RUN: %target-swift-frontend -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import -parse-stdlib -I %t -module-cache-path %t/swiftcache -emit-module-interface-path %t/OtherModule.swiftinterface -module-name OtherModule %t/other.swift -emit-module -o /dev/null
7+
// RUN: %target-swift-frontend -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import -parse-stdlib -I %t -module-cache-path %t/swiftcache -Xcc -fmodules-cache-path=%t/clangcache -emit-module -o %t/TestModule.swiftmodule -module-name TestModule %t/main.swift
8+
9+
// RUN: NUM_SWIFT_MODULES=$(find %t/swiftcache -type f -name '*.swiftmodule' | wc -l)
10+
// RUN: NUM_CLANG_MODULES=$(find %t/clangcache -type f -name '*.pcm' | wc -l)
11+
/// Two swift modules, Leaf and Other
12+
// RUN: if [ ! $NUM_SWIFT_MODULES -eq 2 ]; then echo "Should only be 2 Swift Modules, found $NUM_SWIFT_MODULES"; exit 1; fi
13+
/// Two clang modules, shim and A
14+
// RUN: if [ ! $NUM_CLANG_MODULES -eq 2 ]; then echo "Should only be 2 Clang Modules, found $NUM_CLANG_MODULES"; exit 1; fi
15+
16+
//--- leaf.swift
17+
public func LeafFunc() {}
18+
19+
//--- other.swift
20+
import LeafModule
21+
public func OtherFunc() {}
22+
23+
//--- module.modulemap
24+
module A {
25+
header "A.h"
26+
export *
27+
}
28+
29+
//--- A.h
30+
void a(void);
31+
32+
//--- main.swift
33+
import OtherModule
34+
import A
35+
36+
public func TestFunc() {
37+
OtherFunc()
38+
a()
39+
}

0 commit comments

Comments
 (0)