Skip to content

Commit 4d8cc2a

Browse files
committed
Driver: provide a more suitable default for emit-module.d
Provide a fallback default for the `emit-module.d` file. It has been observed on Windows and Android that builds subsequent to #1056 would emit files into the root of the source tree (specifically, `pwd`). If there is no explicit location specified for the new output, and given that there is no primary output associated with the command, the path that defaults is simply a singular file name component, emitting that file into the location that the driver was executed from (which comes out to the root of the package for commandline invocations), dirtying the source tree. Rather than sinking the knowledge for the default into `existingOutputForSingleInput`, where we have no access to the module name, emit the logic inline and derive a name based on the Swift module and place it as a peer. This should help ensure that the serialized diagnostics do not end up committed accidentally.
1 parent dffa61d commit 4d8cc2a

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3011,10 +3011,21 @@ extension Driver {
30113011

30123012
// Emit-module discovered dependencies are always specified as a single-output
30133013
// file
3014-
if type == .emitModuleDependencies,
3015-
let singleOutputPath = outputFileMap?.existingOutputForSingleInput(
3016-
outputType: type) {
3017-
return singleOutputPath
3014+
if type == .emitModuleDependencies {
3015+
if let path = outputFileMap?.existingOutputForSingleInput(outputType: type) {
3016+
return path
3017+
}
3018+
3019+
// If an explicit path is not provided by the output file map, attempt to
3020+
// synthesize a path from the master swift dependency path. This is
3021+
// important as we may other emit this file at the location where the
3022+
// driver was invoked, which is normally the root of the package.
3023+
if let path = outputFileMap?.existingOutputForSingleInput(outputType: .swiftDeps) {
3024+
return VirtualPath.lookup(path)
3025+
.parentDirectory
3026+
.appending(component: "\(moduleName).\(type.rawValue)")
3027+
.intern()
3028+
}
30183029
}
30193030

30203031
// If there is an output argument, derive the name from there.

0 commit comments

Comments
 (0)