Skip to content

Commit b510621

Browse files
committed
Verify module interfaces generated from emit-module jobs
The Verify job was previously only added after merge-module jobs.
1 parent e9f4a0a commit b510621

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

Sources/SwiftDriver/Jobs/Planning.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ extension Driver {
104104

105105
try addPrecompileModuleDependenciesJobs(addJob: addJobBeforeCompiles)
106106
try addPrecompileBridgingHeaderJob(addJob: addJobBeforeCompiles)
107-
try addEmitModuleJob(addJob: addJobBeforeCompiles)
107+
try addEmitModuleJob(addJobBeforeCompiles: addJobBeforeCompiles, addJobAfterCompiles: addJobAfterCompiles)
108108
let linkerInputs = try addJobsFeedingLinker(
109109
addJobBeforeCompiles: addJobBeforeCompiles,
110110
addCompileJobGroup: addCompileJobGroup,
@@ -183,9 +183,11 @@ extension Driver {
183183
)
184184
}
185185

186-
private mutating func addEmitModuleJob(addJob: (Job) -> Void) throws {
186+
private mutating func addEmitModuleJob(addJobBeforeCompiles: (Job) -> Void, addJobAfterCompiles: (Job) -> Void) throws {
187187
if shouldCreateEmitModuleJob {
188-
addJob( try emitModuleJob() )
188+
let emitModuleJob = try emitModuleJob()
189+
addJobBeforeCompiles(emitModuleJob)
190+
try addVerifyJobs(mergeJob: emitModuleJob, addJob: addJobAfterCompiles)
189191
}
190192
}
191193

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3518,13 +3518,56 @@ final class SwiftDriverTests: XCTestCase {
35183518
XCTAssertTrue(verifyJob.inputs[0] == mergeInterfaceOutputs[0])
35193519
XCTAssertTrue(verifyJob.commandLine.contains(.path(mergeInterfaceOutputs[0].file)))
35203520
}
3521+
35213522
// No Evolution
35223523
do {
35233524
var driver = try Driver(args: ["swiftc", "foo.swift", "-emit-module", "-module-name",
35243525
"foo", "-emit-module-interface", "-verify-emitted-module-interface"])
35253526
let plannedJobs = try driver.planBuild()
35263527
XCTAssertEqual(plannedJobs.count, 2)
35273528
}
3529+
3530+
// Emit-module separately
3531+
do {
3532+
var driver = try Driver(args: ["swiftc", "foo.swift", "-emit-module", "-module-name",
3533+
"foo", "-emit-module-interface",
3534+
"-verify-emitted-module-interface",
3535+
"-enable-library-evolution",
3536+
"-experimental-emit-module-separately"])
3537+
let plannedJobs = try driver.planBuild()
3538+
XCTAssertEqual(plannedJobs.count, 2)
3539+
let emitJob = plannedJobs[0]
3540+
let verifyJob = plannedJobs[1]
3541+
XCTAssertEqual(emitJob.kind, .emitModule)
3542+
let emitInterfaceOutput = emitJob.outputs.filter { $0.type == .swiftInterface }
3543+
XCTAssertTrue(emitInterfaceOutput.count == 1,
3544+
"Emit module job should only have one swiftinterface output")
3545+
XCTAssertEqual(verifyJob.kind, .verifyModuleInterface)
3546+
XCTAssertTrue(verifyJob.inputs.count == 1)
3547+
XCTAssertTrue(verifyJob.inputs[0] == emitInterfaceOutput[0])
3548+
XCTAssertTrue(verifyJob.commandLine.contains(.path(emitInterfaceOutput[0].file)))
3549+
}
3550+
3551+
// Whole-module
3552+
do {
3553+
var driver = try Driver(args: ["swiftc", "foo.swift", "-emit-module", "-module-name",
3554+
"foo", "-emit-module-interface",
3555+
"-verify-emitted-module-interface",
3556+
"-enable-library-evolution",
3557+
"-whole-module-optimization"])
3558+
let plannedJobs = try driver.planBuild()
3559+
XCTAssertEqual(plannedJobs.count, 2)
3560+
let emitJob = plannedJobs[0]
3561+
let verifyJob = plannedJobs[1]
3562+
XCTAssertEqual(emitJob.kind, .emitModule)
3563+
let emitInterfaceOutput = emitJob.outputs.filter { $0.type == .swiftInterface }
3564+
XCTAssertTrue(emitInterfaceOutput.count == 1,
3565+
"Emit module job should only have one swiftinterface output")
3566+
XCTAssertEqual(verifyJob.kind, .verifyModuleInterface)
3567+
XCTAssertTrue(verifyJob.inputs.count == 1)
3568+
XCTAssertTrue(verifyJob.inputs[0] == emitInterfaceOutput[0])
3569+
XCTAssertTrue(verifyJob.commandLine.contains(.path(emitInterfaceOutput[0].file)))
3570+
}
35283571
}
35293572

35303573
func testPCHGeneration() throws {

0 commit comments

Comments
 (0)