Skip to content

Commit ed67c4b

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 340d260 commit ed67c4b

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

Sources/SwiftDriver/ExplicitModuleBuilds/ModuleDependencyScanning.swift

+1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ public extension Driver {
121121
}
122122

123123
try commandLine.appendLast(.clangIncludeTree, from: &parsedOptions)
124+
try commandLine.appendLast(.clangScannerModuleCachePath, from: &parsedOptions)
124125

125126
// Pass on the input files
126127
commandLine.append(contentsOf: inputFiles.filter { $0.type == .swift }.map { .path($0.file) })

Sources/SwiftOptions/Options.swift

+2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ extension Option {
7575
public static let clangHeaderExposeModule: Option = Option("-clang-header-expose-module", .separate, attributes: [.helpHidden, .frontend, .noDriver], metaVar: "<imported-module-name>=<generated-header-name>", helpText: "Allow the compiler to assume that APIs from the specified module are exposed to C/C++/Objective-C in another generated header, so that APIs in the current module that depend on declarations from the specified module can be exposed in the generated header.")
7676
public static let clangIncludeTreeRoot: Option = Option("-clang-include-tree-root", .separate, attributes: [.helpHidden, .frontend, .noDriver], metaVar: "<cas-id>", helpText: "Clang Include Tree CASID")
7777
public static let clangIncludeTree: Option = Option("-clang-include-tree", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Use clang include tree")
78+
public static let clangScannerModuleCachePath: Option = Option("-clang-scanner-module-cache-path", .separate, attributes: [.frontend, .doesNotAffectIncrementalBuild, .argumentIsPath], helpText: "Specifies the Clang dependency scanner module cache path")
7879
public static let clangTarget: Option = Option("-clang-target", .separate, attributes: [.frontend], helpText: "Separately set the target we should use for internal Clang instance")
7980
public static let codeCompleteCallPatternHeuristics: Option = Option("-code-complete-call-pattern-heuristics", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Use heuristics to guess whether we want call pattern completions")
8081
public static let codeCompleteInitsInPostfixExpr: Option = Option("-code-complete-inits-in-postfix-expr", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Include initializers when completing a postfix expression")
@@ -869,6 +870,7 @@ extension Option {
869870
Option.clangHeaderExposeModule,
870871
Option.clangIncludeTreeRoot,
871872
Option.clangIncludeTree,
873+
Option.clangScannerModuleCachePath,
872874
Option.clangTarget,
873875
Option.codeCompleteCallPatternHeuristics,
874876
Option.codeCompleteInitsInPostfixExpr,

Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift

+22
Original file line numberDiff line numberDiff line change
@@ -1365,6 +1365,28 @@ final class ExplicitModuleBuildTests: XCTestCase {
13651365
}
13661366
}
13671367

1368+
/// Test that the scanner invocation does not rely in response files
1369+
func testDependencyScanningSeparateClangScanCache() throws {
1370+
try withTemporaryDirectory { path in
1371+
let scannerCachePath: AbsolutePath = path.appending(component: "ClangScannerCache")
1372+
let moduleCachePath: AbsolutePath = path.appending(component: "ModuleCache")
1373+
let main = path.appending(component: "testDependencyScanningSeparateClangScanCache.swift")
1374+
let sdkArgumentsForTesting = (try? Driver.sdkArgumentsForTesting()) ?? []
1375+
var driver = try Driver(args: ["swiftc",
1376+
"-explicit-module-build",
1377+
"-clang-scanner-module-cache-path",
1378+
scannerCachePath.nativePathString(escaped: true),
1379+
"-module-cache-path",
1380+
moduleCachePath.nativePathString(escaped: true),
1381+
"-working-directory", path.nativePathString(escaped: true),
1382+
main.nativePathString(escaped: true)] + sdkArgumentsForTesting,
1383+
env: ProcessEnv.vars)
1384+
let scannerJob = try driver.dependencyScanningJob()
1385+
XCTAssertTrue(scannerJob.commandLine.contains(subsequence: [.flag("-clang-scanner-module-cache-path"),
1386+
.path(.absolute(scannerCachePath))]))
1387+
}
1388+
}
1389+
13681390
func testDependencyScanningFailure() throws {
13691391
let (stdlibPath, shimsPath, toolchain, _) = try getDriverArtifactsForScanning()
13701392

0 commit comments

Comments
 (0)