Skip to content

Commit 12b7df8

Browse files
committed
[Prebuilt Module Cache] Add an environment variable overload to specify location of the prebuilt module cache
Useful for allowing e.g. CI systems to share this parameter without needing to plumb through a new compiler flag everywhere Resolves rdar://135033114
1 parent 7a54784 commit 12b7df8

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

lib/Frontend/ArgsToFrontendOptionsConverter.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "llvm/Option/Arg.h"
3030
#include "llvm/Option/ArgList.h"
3131
#include "llvm/Option/Option.h"
32+
#include "llvm/Support/Process.h"
3233
#include "llvm/Support/FileSystem.h"
3334
#include "llvm/Support/LineIterator.h"
3435
#include "llvm/Support/Path.h"
@@ -66,6 +67,11 @@ bool ArgsToFrontendOptionsConverter::convert(
6667
if (const Arg *A = Args.getLastArg(OPT_prebuilt_module_cache_path)) {
6768
Opts.PrebuiltModuleCachePath = A->getValue();
6869
}
70+
if (auto envPrebuiltModuleCachePath =
71+
llvm::sys::Process::GetEnv("SWIFT_OVERLOAD_PREBUILT_MODULE_CACHE_PATH")) {
72+
Opts.PrebuiltModuleCachePath = *envPrebuiltModuleCachePath;
73+
}
74+
6975
if (const Arg *A = Args.getLastArg(OPT_module_cache_path)) {
7076
Opts.ExplicitModulesOutputPath = A->getValue();
7177
} else {
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: mkdir -p %t/sdk/usr/lib/swift/Normal.swiftmodule
3+
// RUN: mkdir -p %t/sdk/System/Library/Frameworks/FMWK.framework/Modules/FMWK.swiftmodule
4+
5+
// RUN: echo 'public func normal() {}' | %target-swift-frontend - -emit-module-interface-path %t/sdk/usr/lib/swift/Normal.swiftmodule/%target-swiftinterface-name -emit-module -o /dev/null -module-name Normal
6+
// RUN: echo 'public func flat() {}' | %target-swift-frontend - -emit-module-interface-path %t/sdk/usr/lib/swift/Flat.swiftinterface -emit-module -o /dev/null -module-name Flat
7+
// RUN: echo 'public func fmwk() {}' | %target-swift-frontend - -emit-module-interface-path %t/sdk/System/Library/Frameworks/FMWK.framework/Modules/FMWK.swiftmodule/%target-swiftinterface-name -emit-module -o /dev/null -module-name FMWK
8+
9+
// RUN: %swift_build_sdk_interfaces -sdk %t/sdk -Fsystem %t/sdk/System/Library/Frameworks -v -o %t/prebuilt
10+
// RUN: ls %t/prebuilt | %FileCheck %s
11+
// CHECK-DAG: Normal.swiftmodule
12+
// CHECK-DAG: Flat.swiftmodule
13+
// CHECK-DAG: FMWK.swiftmodule
14+
15+
// RUN: env SWIFT_OVERLOAD_PREBUILT_MODULE_CACHE_PATH=%t/prebuilt %target-typecheck-verify-swift -sdk %t/sdk -Fsystem %t/sdk/System/Library/Frameworks -I %t/sdk/usr/lib/swift/ -module-cache-path %t/MCP
16+
// RUN: %{python} %S/../ModuleCache/Inputs/check-is-forwarding-module.py %t/MCP/*.swiftmodule
17+
18+
// Touch a file in the SDK (to make it look like it changed) and try again.
19+
// This should still be able to use the prebuilt modules because they track
20+
// content hashes, not just size+mtime.
21+
// RUN: rm -rf %t/MCP
22+
// RUN: %{python} %S/../ModuleCache/Inputs/make-old.py %t/sdk/usr/lib/swift/Normal.swiftmodule/%target-swiftinterface-name
23+
// RUN: env SWIFT_OVERLOAD_PREBUILT_MODULE_CACHE_PATH=%t/prebuilt %target-typecheck-verify-swift -sdk %t/sdk -Fsystem %t/sdk/System/Library/Frameworks -I %t/sdk/usr/lib/swift/ -module-cache-path %t/MCP
24+
// RUN: ls %t/MCP/*.swiftmodule | %FileCheck -check-prefix CHECK-CACHE %s
25+
// RUN: %{python} %S/../ModuleCache/Inputs/check-is-forwarding-module.py %t/MCP/*.swiftmodule
26+
27+
// CHECK-CACHE-DAG: Normal-{{.+}}.swiftmodule
28+
// CHECK-CACHE-DAG: Flat-{{.+}}.swiftmodule
29+
// CHECK-CACHE-DAG: FMWK-{{.+}}.swiftmodule
30+
31+
// Actually change a file in the SDK, to check that we're tracking dependencies
32+
// at all.
33+
// RUN: rm -rf %t/MCP
34+
// RUN: echo "public func another()" >> %t/sdk/usr/lib/swift/Normal.swiftmodule/%target-swiftinterface-name
35+
// RUN: env SWIFT_OVERLOAD_PREBUILT_MODULE_CACHE_PATH=%t/prebuilt %target-typecheck-verify-swift -sdk %t/sdk -Fsystem %t/sdk/System/Library/Frameworks -I %t/sdk/usr/lib/swift/ -module-cache-path %t/MCP
36+
// RUN: ls %t/MCP/*.swiftmodule | %FileCheck -check-prefix CHECK-CACHE %s
37+
// RUN: not %{python} %S/../ModuleCache/Inputs/check-is-forwarding-module.py %t/MCP/Normal-*.swiftmodule
38+
// RUN: %{python} %S/../ModuleCache/Inputs/check-is-forwarding-module.py %t/MCP/Flat-*.swiftmodule
39+
// RUN: %{python} %S/../ModuleCache/Inputs/check-is-forwarding-module.py %t/MCP/FMWK-*.swiftmodule
40+
41+
// Without the prebuilt cache everything should still work; it'll just take time
42+
// because we have to build the interfaces.
43+
// RUN: rm -rf %t/MCP
44+
// RUN: %target-typecheck-verify-swift -sdk %t/sdk -Fsystem %t/sdk/System/Library/Frameworks -I %t/sdk/usr/lib/swift/ -module-cache-path %t/MCP
45+
// RUN: ls %t/MCP/*.swiftmodule | %FileCheck -check-prefix CHECK-CACHE %s
46+
// RUN: not %{python} %S/../ModuleCache/Inputs/check-is-forwarding-module.py %t/MCP/Normal-*.swiftmodule
47+
// RUN: not %{python} %S/../ModuleCache/Inputs/check-is-forwarding-module.py %t/MCP/Flat-*.swiftmodule
48+
// RUN: not %{python} %S/../ModuleCache/Inputs/check-is-forwarding-module.py %t/MCP/FMWK-*.swiftmodule
49+
50+
51+
import Normal
52+
import Flat
53+
import FMWK
54+
55+
func test() {
56+
normal()
57+
flat()
58+
fmwk()
59+
}

0 commit comments

Comments
 (0)