Skip to content

Commit 5d80fe4

Browse files
authored
Merge pull request #238 from artemcm/DependenciesInModuleCache
[Explicit Module Builds] Point module dependency modules to be put into the module cache
2 parents 75d4a30 + 896ff5d commit 5d80fe4

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

Sources/SwiftDriver/Explicit Module Builds/ExplicitModuleBuildHandler.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ public typealias ExternalDependencyArtifactMap =
175175
}
176176
}
177177

178+
// Set the output path
179+
commandLine.appendFlag(.o)
180+
commandLine.appendPath(try VirtualPath(path: moduleInfo.modulePath))
181+
178182
swiftModuleBuildCache[moduleId] = Job(
179183
moduleName: moduleId.moduleName,
180184
kind: .emitModule,

Sources/SwiftDriver/Jobs/Planning.swift

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,41 @@ extension Driver {
262262
try dependencyGraph.resolvePlaceholderDependencies(using: externalDependencyArtifactMap!)
263263
}
264264

265-
// Re-scan Clang modules at all the targets they will be built against
265+
// Re-scan Clang modules at all the targets they will be built against.
266266
try resolveVersionedClangDependencies(dependencyGraph: &dependencyGraph)
267+
268+
// Set dependency modules' paths to be saved in the module cache.
269+
try updateDependencyModulesWithModuleCachePath(dependencyGraph: &dependencyGraph)
270+
267271
return dependencyGraph
268272
}
269273

274+
/// Update the given inter-module dependency graph to set module paths to be within the module cache,
275+
/// if one is present.
276+
private mutating func updateDependencyModulesWithModuleCachePath(dependencyGraph:
277+
inout InterModuleDependencyGraph)
278+
throws {
279+
let moduleCachePath = parsedOptions.getLastArgument(.moduleCachePath)?.asSingle
280+
if moduleCachePath != nil {
281+
for (moduleId, moduleInfo) in dependencyGraph.modules {
282+
// Output path on the main module is determined by the invocation arguments.
283+
guard moduleId.moduleName != dependencyGraph.mainModuleName else {
284+
continue
285+
}
286+
let modulePath = moduleInfo.modulePath
287+
// Only update paths on modules which do not already specify a path beyond their module name
288+
// and a file extension.
289+
if modulePath == moduleId.moduleName + ".swiftmodule" ||
290+
modulePath == moduleId.moduleName + ".pcm" {
291+
// Use VirtualPath to get the OS-specific path separators right.
292+
let modulePathInCache =
293+
try VirtualPath(path: moduleCachePath!).appending(component: modulePath).description
294+
dependencyGraph.modules[moduleId]!.modulePath = modulePathInCache
295+
}
296+
}
297+
}
298+
}
299+
270300
/// Create a job if needed for simple requests that can be immediately
271301
/// forwarded to the frontend.
272302
public mutating func immediateForwardingJob() throws -> Job? {

0 commit comments

Comments
 (0)