@@ -407,11 +407,13 @@ final class IncrementalCompilationTests: XCTestCase {
407
407
}
408
408
409
409
extension IncrementalCompilationTests {
410
+ @discardableResult
410
411
func doABuild( _ message: String ,
411
412
checkDiagnostics: Bool ,
412
413
extraArguments: [ String ] ,
413
414
expectingRemarks texts: [ String ] ,
414
- whenAutolinking: [ String ] ) throws {
415
+ whenAutolinking: [ String ]
416
+ ) throws -> Driver ? {
415
417
try doABuild (
416
418
message,
417
419
checkDiagnostics: checkDiagnostics,
@@ -420,14 +422,16 @@ extension IncrementalCompilationTests {
420
422
expectingWhenAutolinking: whenAutolinking. map { . remark( $0) } )
421
423
}
422
424
425
+ @discardableResult
423
426
func doABuild( _ message: String ,
424
427
checkDiagnostics: Bool ,
425
428
extraArguments: [ String ] ,
426
429
expecting expectations: [ Diagnostic . Message ] ,
427
- expectingWhenAutolinking autolinkExpectations: [ Diagnostic . Message ] ) throws {
430
+ expectingWhenAutolinking autolinkExpectations: [ Diagnostic . Message ]
431
+ ) throws -> Driver ? {
428
432
print ( " *** starting build \( message) *** " , to: & stderrStream) ; stderrStream. flush ( )
429
433
430
- func doIt ( _ driver: inout Driver ) {
434
+ func doTheCompile ( _ driver: inout Driver ) {
431
435
let jobs = try ! driver. planBuild ( )
432
436
try ? driver. run ( jobs: jobs)
433
437
}
@@ -437,14 +441,16 @@ extension IncrementalCompilationTests {
437
441
throw XCTSkip ( " Cannot perform this test on this host " )
438
442
}
439
443
let allArgs = commonArgs + extraArguments + sdkArgumentsForTesting
444
+ let postMortemDriver : Driver ?
440
445
if checkDiagnostics {
441
- try assertDriverDiagnostics ( args: allArgs) { driver, verifier in
446
+ postMortemDriver = try assertDriverDiagnostics ( args: allArgs) { driver, verifier in
442
447
verifier. forbidUnexpected ( . error, . warning, . note, . remark, . ignored)
443
448
expectations. forEach { verifier. expect ( $0) }
444
449
if driver. isAutolinkExtractJobNeeded {
445
450
autolinkExpectations. forEach { verifier. expect ( $0) }
446
451
}
447
- doIt ( & driver)
452
+ doTheCompile ( & driver)
453
+ return driver
448
454
}
449
455
}
450
456
else {
@@ -454,9 +460,11 @@ extension IncrementalCompilationTests {
454
460
var driver = try Driver ( args: allArgs, env: ProcessEnv . vars,
455
461
diagnosticsEngine: diagnosticEngine,
456
462
fileSystem: localFileSystem)
457
- doIt ( & driver)
463
+ doTheCompile ( & driver)
464
+ postMortemDriver = driver
458
465
}
459
466
print ( " " , to: & stderrStream) ; stderrStream. flush ( )
467
+ return postMortemDriver
460
468
}
461
469
}
462
470
@@ -587,6 +595,22 @@ extension IncrementalCompilationTests {
587
595
}
588
596
}
589
597
598
+ /// Ensure that if an output of post-compile job is missing, the job gets rerun.
599
+ func testIncrementalPostCompileJob( ) throws {
600
+ let driver = try XCTUnwrap ( tryInitial ( checkDiagnostics: true ) )
601
+ for postCompileOutput in try driver. postCompileOutputs ( ) {
602
+ let absPostCompileOutput = try XCTUnwrap ( postCompileOutput. file. absolutePath)
603
+ try localFileSystem. removeFileTree ( absPostCompileOutput)
604
+ XCTAssertFalse ( localFileSystem. exists ( absPostCompileOutput) )
605
+ tryNoChange ( )
606
+ XCTAssertTrue ( localFileSystem. exists ( absPostCompileOutput) )
607
+ }
608
+ }
609
+
610
+ private func postCompileOutputs( ) -> [ AbsolutePath ] {
611
+ abort ( )
612
+ }
613
+
590
614
func testIncremental( checkDiagnostics: Bool ) throws {
591
615
try tryInitial ( checkDiagnostics: checkDiagnostics)
592
616
#if true // sometimes want to skip for debugging
@@ -597,10 +621,10 @@ extension IncrementalCompilationTests {
597
621
tryReplacingMain ( checkDiagnostics: checkDiagnostics)
598
622
}
599
623
600
-
624
+ @ discardableResult
601
625
func tryInitial( checkDiagnostics: Bool = false ,
602
626
extraArguments: [ String ] = [ ]
603
- ) throws {
627
+ ) throws -> Driver ? {
604
628
try doABuild (
605
629
" initial " ,
606
630
checkDiagnostics: checkDiagnostics,
@@ -919,3 +943,8 @@ class CrossModuleIncrementalBuildTests: XCTestCase {
919
943
}
920
944
}
921
945
946
+ fileprivate extension Driver {
947
+ func postCompileOutputs( ) throws -> [ TypedVirtualPath ] {
948
+ try XCTUnwrap ( incrementalCompilationState) . jobsAfterCompiles. flatMap { $0. outputs}
949
+ }
950
+ }
0 commit comments