Skip to content

Commit 8501f99

Browse files
committed
[Dependency Scanning] Add option to specify a separate Clang Dependency scanner module cache.
Clang dependency scanning produces scanner PCMs which we may want to live in a different filesystem location than the main build module cache. Resolves rdar://113222853
1 parent f905b28 commit 8501f99

File tree

6 files changed

+39
-1
lines changed

6 files changed

+39
-1
lines changed

include/swift/Basic/LangOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,9 @@ namespace swift {
811811
/// The module cache path which the Clang importer should use.
812812
std::string ModuleCachePath;
813813

814+
/// The Scanning module cache path which the Clang Dependency Scanner should use.
815+
std::string ClangScannerModuleCachePath;
816+
814817
/// Extra arguments which should be passed to the Clang importer.
815818
std::vector<std::string> ExtraArgs;
816819

include/swift/Frontend/Frontend.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,18 @@ class CompilerInvocation {
168168
ClangImporterOpts.ModuleCachePath = Path.str();
169169
}
170170

171+
void setClangScannerModuleCachePath(StringRef Path) {
172+
ClangImporterOpts.ClangScannerModuleCachePath = Path.str();
173+
}
174+
171175
StringRef getClangModuleCachePath() const {
172176
return ClangImporterOpts.ModuleCachePath;
173177
}
174178

179+
StringRef getClangScannerModuleCachePath() const {
180+
return ClangImporterOpts.ClangScannerModuleCachePath;
181+
}
182+
175183
void setImportSearchPaths(const std::vector<std::string> &Paths) {
176184
SearchPathOpts.setImportSearchPaths(Paths);
177185
}

include/swift/Option/Options.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1838,6 +1838,9 @@ def cas_plugin_option: Separate<["-"], "cas-plugin-option">,
18381838
Flags<[FrontendOption, NewDriverOnlyOption]>,
18391839
HelpText<"Option pass to CAS Plugin">, MetaVarName<"<name>=<option>">;
18401840

1841+
def clang_scanner_module_cache_path : Separate<["-"], "clang-scanner-module-cache-path">,
1842+
Flags<[FrontendOption, DoesNotAffectIncrementalBuild, ArgumentIsPath]>,
1843+
HelpText<"Specifies the Clang dependency scanner module cache path">;
18411844

18421845
// END ONLY SUPPORTED IN NEW DRIVER
18431846

lib/ClangImporter/ClangImporter.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,13 @@ importer::getNormalInvocationArguments(
667667
}
668668

669669
const std::string &moduleCachePath = importerOpts.ModuleCachePath;
670-
if (!moduleCachePath.empty() && !importerOpts.DisableImplicitClangModules) {
670+
const std::string &scannerCachePath = importerOpts.ClangScannerModuleCachePath;
671+
// If a scanner cache is specified, this must be a scanning action. Prefer this
672+
// path for the Clang scanner to cache its Scanning PCMs.
673+
if (!scannerCachePath.empty()) {
674+
invocationArgStrs.push_back("-fmodules-cache-path=");
675+
invocationArgStrs.back().append(scannerCachePath);
676+
} else if (!moduleCachePath.empty() && !importerOpts.DisableImplicitClangModules) {
671677
invocationArgStrs.push_back("-fmodules-cache-path=");
672678
invocationArgStrs.back().append(moduleCachePath);
673679
}

lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,6 +1461,9 @@ static bool ParseClangImporterArgs(ClangImporterOptions &Opts,
14611461
if (const Arg *A = Args.getLastArg(OPT_module_cache_path)) {
14621462
Opts.ModuleCachePath = A->getValue();
14631463
}
1464+
if (const Arg *A = Args.getLastArg(OPT_clang_scanner_module_cache_path)) {
1465+
Opts.ClangScannerModuleCachePath = A->getValue();
1466+
}
14641467

14651468
if (const Arg *A = Args.getLastArg(OPT_target_cpu))
14661469
Opts.TargetCPU = A->getValue();
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %empty-directory(%t.module-cache)
2+
// RUN: %empty-directory(%t.scanner-cache)
3+
4+
// RUN: %target-swift-frontend -scan-dependencies -module-cache-path %t.module-cache -clang-scanner-module-cache-path %t.scanner-cache %s -o %t.deps.json -I %S/Inputs/SwiftDifferent -dump-clang-diagnostics 2>&1 | %FileCheck %s --check-prefix=CHECK-CLANG-COMMAND
5+
// RUN: %validate-json %t.deps.json | %FileCheck %s --check-prefix=CHECK-DEPS
6+
7+
// CHECK-CLANG-COMMAND: '-fmodules-cache-path={{.*}}.scanner-cache'
8+
9+
// CHECK-DEPS: "swift": "A"
10+
// CHECK-DEPS: "swift": "A"
11+
// CHECK-DEPS-NEXT: },
12+
// CHECK-DEPS-NEXT: {
13+
// CHECK-DEPS-NEXT: "modulePath": "{{.*}}.module-cache/A-{{.*}}.swiftmodule",
14+
// CHECK-DEPS-NEXT: "sourceFiles": [
15+
import A

0 commit comments

Comments
 (0)