Skip to content

Commit 70d7871

Browse files
committed
PrebuiltModuleGen: add support for -module-cache-path
1 parent b37003c commit 70d7871

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

Sources/SwiftDriver/Jobs/PrebuiltModulesJob.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,11 @@ extension Driver {
261261
commandLine.appendFlag(.Fsystem)
262262
commandLine.append(.path(iosMacFrameworksSearchPath))
263263
}
264+
// Use the specified module cache dir
265+
if let mcp = parsedOptions.getLastArgument(.moduleCachePath)?.asSingle {
266+
commandLine.appendFlag(.moduleCachePath)
267+
commandLine.append(.path(try VirtualPath(path: mcp)))
268+
}
264269
commandLine.appendFlag(.serializeParseableModuleInterfaceDependencyHashes)
265270
return Job(
266271
moduleName: moduleName,

Sources/swift-build-sdk-interfaces/main.swift

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,17 @@ guard let sdkPathRaw = ProcessEnv.vars["SDKROOT"] else {
2222
exit(1)
2323
}
2424

25-
var rawOutputDir = ""
26-
if let oid = CommandLine.arguments.firstIndex(of: "-o") {
27-
let dirId = oid.advanced(by: 1)
28-
if dirId < CommandLine.arguments.count {
29-
rawOutputDir = CommandLine.arguments[dirId]
25+
func getArgument(_ flag: String) -> String? {
26+
if let id = CommandLine.arguments.firstIndex(of: flag) {
27+
let nextId = id.advanced(by: 1)
28+
if nextId < CommandLine.arguments.count {
29+
return CommandLine.arguments[nextId]
30+
}
3031
}
32+
return nil
3133
}
32-
if rawOutputDir.isEmpty {
34+
35+
guard let rawOutputDir = getArgument("-o") else {
3336
diagnosticsEngine.emit(.error("need to specify -o"))
3437
exit(1)
3538
}
@@ -99,10 +102,17 @@ do {
99102
processSet: processSet,
100103
fileSystem: localFileSystem,
101104
env: ProcessEnv.vars)
102-
var driver = try Driver(args: ["swiftc",
103-
"-target", collector.targetTriple,
104-
tempPath.description,
105-
"-sdk", sdkPathRaw],
105+
var args = ["swiftc",
106+
"-target", collector.targetTriple,
107+
tempPath.description,
108+
"-sdk", sdkPathRaw]
109+
let mcpFlag = "-module-cache-path"
110+
// Append module cache path if given by the client
111+
if let mcp = getArgument(mcpFlag) {
112+
args.append(mcpFlag)
113+
args.append(mcp)
114+
}
115+
var driver = try Driver(args: args,
106116
diagnosticsEngine: diagnosticsEngine,
107117
executor: executor,
108118
compilerExecutableDir: swiftcPath.parentDirectory)

Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,8 +818,10 @@ final class ExplicitModuleBuildTests: XCTestCase {
818818
$0 <<< "import H\n"
819819
$0 <<< "import Swift\n"
820820
}
821+
let moduleCachePath = "/tmp/module-cache"
821822
var driver = try Driver(args: ["swiftc", main.pathString,
822823
"-sdk", mockSDKPath,
824+
"-module-cache-path", moduleCachePath
823825
])
824826

825827
let (jobs, danglingJobs) = try driver.generatePrebuitModuleGenerationJobs(with: interfaceMap,
@@ -834,6 +836,8 @@ final class ExplicitModuleBuildTests: XCTestCase {
834836
XCTAssertTrue(jobs.allSatisfy {$0.outputs.count == 1})
835837
XCTAssertTrue(jobs.allSatisfy {$0.kind == .compile})
836838
XCTAssertTrue(jobs.allSatisfy {$0.commandLine.contains(.flag("-compile-module-from-interface"))})
839+
XCTAssertTrue(jobs.allSatisfy {$0.commandLine.contains(.flag("-module-cache-path"))})
840+
XCTAssertTrue(try jobs.allSatisfy {$0.commandLine.contains(.path(try VirtualPath(path: moduleCachePath)))})
837841
let HJobs = jobs.filter { $0.moduleName == "H"}
838842
XCTAssertTrue(HJobs.count == 2)
839843
XCTAssertTrue(getInputModules(HJobs[0]) == ["A", "E", "F", "G", "Swift"])

0 commit comments

Comments
 (0)