Skip to content

Commit bb7c128

Browse files
committed
Respect the single-input output-file-map entries when emit-module is the sole job.
When the driver is invoked with the primary output of a swift module and we are in the `emit-module-separtely` mode, there will only be a single `emit-module` job, for which we need to respect module-wide supplementary output paths specified in the output file map. Resolves rdar://84262412
1 parent 0e39f4f commit bb7c128

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2745,6 +2745,16 @@ extension Driver {
27452745
return singleOutputPath
27462746
}
27472747

2748+
// The driver lacks a compilerMode for *only* emitting a Swift module, but if the
2749+
// primary output type is a .swiftmodule and we are using the emit-module-separately
2750+
// flow, then also consider single output paths specified in the output file-map.
2751+
if compilerOutputType == .swiftModule &&
2752+
Driver.shouldEmitModuleSeparately(parsedOptions: &parsedOptions),
2753+
let singleOutputPath = outputFileMap?.existingOutputForSingleInput(
2754+
outputType: type) {
2755+
return singleOutputPath
2756+
}
2757+
27482758
// If there is an output argument, derive the name from there.
27492759
if let outputPathArg = parsedOptions.getLastArgument(.o) {
27502760
let path = try VirtualPath(path: outputPathArg.asSingle)

Sources/SwiftDriver/Jobs/EmitModuleJob.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1010
//
1111
//===----------------------------------------------------------------------===//
12+
13+
import SwiftOptions
1214
extension Driver {
1315
/// Add options that are common to command lines that emit modules, e.g.,
1416
/// options for the paths of various module files.
@@ -117,13 +119,17 @@ extension Driver {
117119
}
118120
}
119121

120-
/// Returns true if the -emit-module-separately is active.
121-
mutating func shouldEmitModuleSeparately() -> Bool {
122+
static func shouldEmitModuleSeparately(parsedOptions: inout ParsedOptions) -> Bool {
122123
return parsedOptions.hasFlag(positive: .emitModuleSeparately,
123124
negative: .noEmitModuleSeparately,
124125
default: true)
125-
&& !parsedOptions.hasFlag(positive: .wholeModuleOptimization,
126-
negative: .noWholeModuleOptimization,
127-
default: false)
126+
&& !parsedOptions.hasFlag(positive: .wholeModuleOptimization,
127+
negative: .noWholeModuleOptimization,
128+
default: false)
129+
}
130+
131+
/// Returns true if the -emit-module-separately is active.
132+
mutating func shouldEmitModuleSeparately() -> Bool {
133+
return Self.shouldEmitModuleSeparately(parsedOptions: &self.parsedOptions)
128134
}
129135
}

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,29 @@ final class SwiftDriverTests: XCTestCase {
807807
XCTAssertTrue(plannedJobs[0].commandLine.contains(.flag("-serialize-diagnostics-path")))
808808
}
809809

810+
func testEmitModuleSepratelyEmittingDiagnosticsWithOutputFileMap() throws {
811+
try withTemporaryDirectory { path in
812+
let outputFileMap = path.appending(component: "outputFileMap.json")
813+
try localFileSystem.writeFileContents(outputFileMap) {
814+
$0 <<< """
815+
{
816+
"": {
817+
"diagnostics": "/build/Foo-test.dia"
818+
}
819+
}
820+
"""
821+
}
822+
var driver = try Driver(args: ["swiftc", "foo.swift", "bar.swift", "-module-name", "Foo", "-emit-module",
823+
"-serialize-diagnostics", "-experimental-emit-module-separately",
824+
"-output-file-map", outputFileMap.description])
825+
let plannedJobs = try driver.planBuild().removingAutolinkExtractJobs()
826+
827+
XCTAssertEqual(plannedJobs.count, 1)
828+
XCTAssertTrue(plannedJobs[0].kind == .emitModule)
829+
XCTAssertTrue(plannedJobs[0].commandLine.contains(subsequence: [.flag("-serialize-diagnostics-path"), .path(.absolute(.init("/build/Foo-test.dia")))]))
830+
}
831+
}
832+
810833
func testReferenceDependencies() throws {
811834
var driver = try Driver(args: ["swiftc", "foo.swift", "-incremental"])
812835
let plannedJobs = try driver.planBuild()

0 commit comments

Comments
 (0)