@@ -15,6 +15,7 @@ import TSCBasic
15
15
@_spi ( Testing) import SwiftDriver
16
16
import SwiftOptions
17
17
18
+ // MARK: - Baseline: nonincremental
18
19
final class NonincrementalCompilationTests : XCTestCase {
19
20
func testBuildRecordReading( ) throws {
20
21
let buildRecord = try XCTUnwrap (
@@ -322,10 +323,11 @@ final class NonincrementalCompilationTests: XCTestCase {
322
323
}
323
324
}
324
325
325
-
326
+ // MARK: - IncrementalCompilation
326
327
final class IncrementalCompilationTests : XCTestCase {
327
328
328
329
var tempDir : AbsolutePath = AbsolutePath ( " /tmp " )
330
+
329
331
var derivedDataDir : AbsolutePath {
330
332
tempDir. appending ( component: " derivedData " )
331
333
}
@@ -360,7 +362,7 @@ final class IncrementalCompilationTests: XCTestCase {
360
362
" Finished Extracting autolink information for module \( module) " ,
361
363
]
362
364
}
363
- var args : [ String ] {
365
+ var commonArgs : [ String ] {
364
366
[
365
367
" swiftc " ,
366
368
" -module-name " , module,
@@ -375,17 +377,14 @@ final class IncrementalCompilationTests: XCTestCase {
375
377
]
376
378
+ inputPathsAndContents. map { $0. 0 . pathString} . sorted ( )
377
379
}
378
- deinit {
379
- try ? localFileSystem. removeFileTree ( tempDir)
380
- }
381
380
382
381
override func setUp( ) {
383
382
self . tempDir = try ! withTemporaryDirectory ( removeTreeOnDeinit: false ) { $0}
384
383
try ! localFileSystem. createDirectory ( derivedDataPath)
385
- writeOutputFileMapData ( module: module,
386
- inputPaths: inputPathsAndContents. map { $0. 0 } ,
387
- derivedData: derivedDataPath,
388
- to: OFM)
384
+ OutputFileMapCreator . write ( module: module,
385
+ inputPaths: inputPathsAndContents. map { $0. 0 } ,
386
+ derivedData: derivedDataPath,
387
+ to: OFM)
389
388
for (base, contents) in baseNamesAndContents {
390
389
let filePath = tempDir. appending ( component: " \( base) .swift " )
391
390
try ! localFileSystem. writeFileContents ( filePath) {
@@ -394,6 +393,63 @@ final class IncrementalCompilationTests: XCTestCase {
394
393
}
395
394
}
396
395
396
+ deinit {
397
+ try ? localFileSystem. removeFileTree ( tempDir)
398
+ }
399
+ }
400
+
401
+ extension IncrementalCompilationTests {
402
+ func doABuild( _ message: String ,
403
+ checkDiagnostics: Bool ,
404
+ extraArguments: [ String ] ,
405
+ expectingRemarks texts: [ String ] ,
406
+ whenAutolinking: [ String ] ) throws {
407
+ try doABuild (
408
+ message,
409
+ checkDiagnostics: checkDiagnostics,
410
+ extraArguments: extraArguments,
411
+ expecting: texts. map { . remark( $0) } ,
412
+ expectingWhenAutolinking: whenAutolinking. map { . remark( $0) } )
413
+ }
414
+
415
+ func doABuild( _ message: String ,
416
+ checkDiagnostics: Bool ,
417
+ extraArguments: [ String ] ,
418
+ expecting expectations: [ Diagnostic . Message ] ,
419
+ expectingWhenAutolinking autolinkExpectations: [ Diagnostic . Message ] ) throws {
420
+ print ( " *** starting build \( message) *** " , to: & stderrStream) ; stderrStream. flush ( )
421
+
422
+ func doIt( _ driver: inout Driver ) {
423
+ let jobs = try ! driver. planBuild ( )
424
+ try ? driver. run ( jobs: jobs)
425
+ }
426
+
427
+ let allArgs = try commonArgs + extraArguments + Driver. sdkArgumentsForTesting ( )
428
+ if checkDiagnostics {
429
+ try assertDriverDiagnostics ( args: allArgs) { driver, verifier in
430
+ verifier. forbidUnexpected ( . error, . warning, . note, . remark, . ignored)
431
+ expectations. forEach { verifier. expect ( $0) }
432
+ if driver. isAutolinkExtractJobNeeded {
433
+ autolinkExpectations. forEach { verifier. expect ( $0) }
434
+ }
435
+ doIt ( & driver)
436
+ }
437
+ }
438
+ else {
439
+ let diagnosticEngine = DiagnosticsEngine ( handlers: [
440
+ { print ( $0, to: & stderrStream) ; stderrStream. flush ( ) }
441
+ ] )
442
+ var driver = try Driver ( args: allArgs, env: ProcessEnv . vars,
443
+ diagnosticsEngine: diagnosticEngine,
444
+ fileSystem: localFileSystem)
445
+ doIt ( & driver)
446
+ }
447
+ print ( " " , to: & stderrStream) ; stderrStream. flush ( )
448
+ }
449
+ }
450
+
451
+ extension IncrementalCompilationTests {
452
+
397
453
func testOptionsParsing( ) throws {
398
454
let optionPairs : [ (
399
455
Option , ( IncrementalCompilationState . InitialStateComputer ) -> Bool
@@ -413,7 +469,7 @@ final class IncrementalCompilationTests: XCTestCase {
413
469
expectingRemarks: [ ] ,
414
470
whenAutolinking: [ ] )
415
471
416
- var driver = try Driver ( args: self . args + [
472
+ var driver = try Driver ( args: self . commonArgs + [
417
473
driverOption. spelling,
418
474
] + Driver. sdkArgumentsForTesting ( ) )
419
475
_ = try driver. planBuild ( )
@@ -422,6 +478,9 @@ final class IncrementalCompilationTests: XCTestCase {
422
478
XCTAssertTrue ( stateOptionFn ( state. moduleDependencyGraph. info) )
423
479
}
424
480
}
481
+ }
482
+
483
+ extension IncrementalCompilationTests {
425
484
426
485
// FIXME: why does it fail on Linux in CI?
427
486
func testIncrementalDiagnostics( ) throws {
@@ -716,53 +775,6 @@ final class IncrementalCompilationTests: XCTestCase {
716
775
XCTAssert ( previousContents != newContents, " \( path. pathString) unchanged after write " )
717
776
XCTAssert ( replacement == newContents, " \( path. pathString) failed to write " )
718
777
}
719
- func doABuild( _ message: String ,
720
- checkDiagnostics: Bool ,
721
- extraArguments: [ String ] ,
722
- expectingRemarks texts: [ String ] ,
723
- whenAutolinking: [ String ] ) throws {
724
- try doABuild (
725
- message,
726
- checkDiagnostics: checkDiagnostics,
727
- extraArguments: extraArguments,
728
- expecting: texts. map { . remark( $0) } ,
729
- expectingWhenAutolinking: whenAutolinking. map { . remark( $0) } )
730
- }
731
-
732
- func doABuild( _ message: String ,
733
- checkDiagnostics: Bool ,
734
- extraArguments: [ String ] ,
735
- expecting expectations: [ Diagnostic . Message ] ,
736
- expectingWhenAutolinking autolinkExpectations: [ Diagnostic . Message ] ) throws {
737
- print ( " *** starting build \( message) *** " , to: & stderrStream) ; stderrStream. flush ( )
738
-
739
- func doIt( _ driver: inout Driver ) {
740
- let jobs = try ! driver. planBuild ( )
741
- try ? driver. run ( jobs: jobs)
742
- }
743
-
744
- let allArgs = try args + extraArguments + Driver. sdkArgumentsForTesting ( )
745
- if checkDiagnostics {
746
- try assertDriverDiagnostics ( args: allArgs) { driver, verifier in
747
- verifier. forbidUnexpected ( . error, . warning, . note, . remark, . ignored)
748
- expectations. forEach { verifier. expect ( $0) }
749
- if driver. isAutolinkExtractJobNeeded {
750
- autolinkExpectations. forEach { verifier. expect ( $0) }
751
- }
752
- doIt ( & driver)
753
- }
754
- }
755
- else {
756
- let diagnosticEngine = DiagnosticsEngine ( handlers: [
757
- { print ( $0, to: & stderrStream) ; stderrStream. flush ( ) }
758
- ] )
759
- var driver = try Driver ( args: allArgs, env: ProcessEnv . vars,
760
- diagnosticsEngine: diagnosticEngine,
761
- fileSystem: localFileSystem)
762
- doIt ( & driver)
763
- }
764
- print ( " " , to: & stderrStream) ; stderrStream. flush ( )
765
- }
766
778
767
779
/// Ensure that autolink output file goes with .o directory, to not prevent incremental omission of
768
780
/// autolink job.
@@ -774,7 +786,7 @@ final class IncrementalCompilationTests: XCTestCase {
774
786
env [ " SWIFT_DRIVER_DSYMUTIL_EXEC " ] = " /garbage/dsymutil "
775
787
776
788
var driver = try ! Driver (
777
- args: args
789
+ args: commonArgs
778
790
+ [ " -emit-library " , " -target " , " x86_64-unknown-linux " ] ,
779
791
env: env)
780
792
let plannedJobs = try ! driver. planBuild ( )
@@ -788,48 +800,6 @@ final class IncrementalCompilationTests: XCTestCase {
788
800
let expected = AbsolutePath ( derivedDataPath, " \( module) .autolink " )
789
801
XCTAssertEqual ( autoOut. file. absolutePath, expected)
790
802
}
791
-
792
- private func generateOutputFileMapDict( module: String , inputPaths: [ AbsolutePath ] ,
793
- derivedData: AbsolutePath
794
- ) -> [ String : [ String : String ] ] {
795
- let master = [ " swift-dependencies " : " \( derivedData. pathString) / \( module) -master.swiftdeps " ]
796
- func baseNameEntry( _ s: AbsolutePath ) -> [ String : String ] {
797
- [
798
- " dependencies " : " .d " ,
799
- " diagnostics " : " .dia " ,
800
- " llvm-bc " : " .bc " ,
801
- " object " : " .o " ,
802
- " swift-dependencies " : " .swiftdeps " ,
803
- " swiftmodule " : " -partial.swiftmodule "
804
- ]
805
- . mapValues { " \( derivedData. appending ( component: s. basenameWithoutExt) ) \( $0) " }
806
- }
807
- return Dictionary ( uniqueKeysWithValues:
808
- inputPaths. map { ( " \( $0) " , baseNameEntry ( $0) ) }
809
- )
810
- . merging ( [ " " : master] ) { _, _ in fatalError ( ) }
811
- }
812
-
813
- private func generateOutputFileMapData( module: String ,
814
- inputPaths: [ AbsolutePath ] ,
815
- derivedData: AbsolutePath
816
- ) -> Data {
817
- let d : [ String : [ String : String ] ] = generateOutputFileMapDict (
818
- module: module,
819
- inputPaths: inputPaths,
820
- derivedData: derivedData)
821
- let enc = JSONEncoder ( )
822
- return try ! enc. encode ( d)
823
- }
824
-
825
- private func writeOutputFileMapData( module: String ,
826
- inputPaths: [ AbsolutePath ] ,
827
- derivedData: AbsolutePath ,
828
- to dst: AbsolutePath ) {
829
- let d : Data = generateOutputFileMapData ( module: module, inputPaths: inputPaths,
830
- derivedData: derivedData)
831
- try ! localFileSystem. writeFileContents ( dst, bytes: ByteString ( d) )
832
- }
833
803
}
834
804
835
805
class CrossModuleIncrementalBuildTests : XCTestCase {
@@ -935,3 +905,4 @@ class CrossModuleIncrementalBuildTests: XCTestCase {
935
905
}
936
906
}
937
907
}
908
+
0 commit comments