@@ -205,6 +205,20 @@ private func checkCachingBuildJobDependencies(job: Job,
205
205
206
206
207
207
final class CachingBuildTests : XCTestCase {
208
+ override func setUpWithError( ) throws {
209
+ try super. setUpWithError ( )
210
+
211
+ // If the toolchain doesn't support caching, skip directly.
212
+ let driver = try Driver ( args: [ " swiftc " , " -v " ] )
213
+ #if os(Windows)
214
+ throw XCTSkip ( " caching not supported on windows " )
215
+ #else
216
+ guard driver. isFeatureSupported ( . cache_compile_job) else {
217
+ throw XCTSkip ( " caching not supported " )
218
+ }
219
+ #endif
220
+ }
221
+
208
222
private func pathMatchesSwiftModule( path: VirtualPath , _ name: String ) -> Bool {
209
223
return path. basenameWithoutExt. starts ( with: " \( name) - " ) &&
210
224
path. extension! == FileType . swiftModule. rawValue
@@ -234,9 +248,6 @@ final class CachingBuildTests: XCTestCase {
234
248
" -cache-compile-job " , " -cas-path " , casPath. nativePathString ( escaped: true ) ,
235
249
" -import-objc-header " , bridgingHeaderpath. nativePathString ( escaped: true ) ,
236
250
main. nativePathString ( escaped: true ) ] + sdkArgumentsForTesting)
237
- guard driver. isFeatureSupported ( . cache_compile_job) else {
238
- throw XCTSkip ( " toolchain does not support caching. " )
239
- }
240
251
241
252
let jobs = try driver. planBuild ( )
242
253
let dependencyGraph = try driver. gatherModuleDependencies ( )
@@ -361,9 +372,6 @@ final class CachingBuildTests: XCTestCase {
361
372
guard driver. supportExplicitModuleVerifyInterface ( ) else {
362
373
throw XCTSkip ( " -typecheck-module-from-interface doesn't support explicit build. " )
363
374
}
364
- guard driver. isFeatureSupported ( . cache_compile_job) else {
365
- throw XCTSkip ( " toolchain does not support caching. " )
366
- }
367
375
368
376
let jobs = try driver. planBuild ( )
369
377
// Figure out which Triples to use.
@@ -492,9 +500,6 @@ final class CachingBuildTests: XCTestCase {
492
500
" -working-directory " , path. nativePathString ( escaped: true ) ,
493
501
main. nativePathString ( escaped: true ) ] + sdkArgumentsForTesting,
494
502
env: ProcessEnv . vars)
495
- guard driver. isFeatureSupported ( . cache_compile_job) else {
496
- throw XCTSkip ( " toolchain does not support caching. " )
497
- }
498
503
let jobs = try driver. planBuild ( )
499
504
try driver. run ( jobs: jobs)
500
505
XCTAssertFalse ( driver. diagnosticEngine. hasErrors)
@@ -553,10 +558,6 @@ final class CachingBuildTests: XCTestCase {
553
558
+ sdkArgumentsForTesting,
554
559
env: ProcessEnv . vars)
555
560
556
- // Ensure this tooling supports this functionality
557
- guard fooBuildDriver. isFeatureSupported ( . cache_compile_job) else {
558
- throw XCTSkip ( " toolchain does not support caching. " )
559
- }
560
561
let dependencyOracle = InterModuleDependencyOracle ( )
561
562
let scanLibPath = try XCTUnwrap ( fooBuildDriver. toolchain. lookupSwiftScanLib ( ) )
562
563
guard try dependencyOracle
@@ -623,9 +624,6 @@ final class CachingBuildTests: XCTestCase {
623
624
" -disable-clang-target " ,
624
625
main. nativePathString ( escaped: true ) ] + sdkArgumentsForTesting,
625
626
env: ProcessEnv . vars)
626
- guard driver. isFeatureSupported ( . cache_compile_job) else {
627
- throw XCTSkip ( " toolchain does not support caching. " )
628
- }
629
627
let dependencyOracle = InterModuleDependencyOracle ( )
630
628
let scanLibPath = try XCTUnwrap ( driver. toolchain. lookupSwiftScanLib ( ) )
631
629
guard try dependencyOracle
@@ -674,38 +672,42 @@ final class CachingBuildTests: XCTestCase {
674
672
// FIXME: We need to differentiate the scanning action hash,
675
673
// though the module-name above should be sufficient.
676
674
" -I/tmp/foo/bar/ \( index) " ]
677
- let dependencyGraph =
678
- try ! dependencyOracle. getDependencies ( workingDirectory: path,
679
- commandLine: iterationCommand)
680
-
681
- // The _Concurrency and _StringProcessing modules are automatically
682
- // imported in newer versions of the Swift compiler. If they happened to
683
- // be provided, adjust our expectations accordingly.
684
- let hasConcurrencyModule = dependencyGraph. modules. keys. contains {
685
- $0. moduleName == " _Concurrency "
686
- }
687
- let hasConcurrencyShimsModule = dependencyGraph. modules. keys. contains {
688
- $0. moduleName == " _SwiftConcurrencyShims "
689
- }
690
- let hasStringProcessingModule = dependencyGraph. modules. keys. contains {
691
- $0. moduleName == " _StringProcessing "
692
- }
693
- let adjustedExpectedNumberOfDependencies =
694
- expectedNumberOfDependencies +
695
- ( hasConcurrencyModule ? 1 : 0 ) +
696
- ( hasConcurrencyShimsModule ? 1 : 0 ) +
697
- ( hasStringProcessingModule ? 1 : 0 )
698
-
699
- if ( dependencyGraph. modules. count != adjustedExpectedNumberOfDependencies) {
700
- lock. lock ( )
701
- print ( " Unexpected Dependency Scanning Result ( \( dependencyGraph. modules. count) modules): " )
702
- dependencyGraph. modules. forEach {
703
- print ( $0. key. moduleName)
675
+ do {
676
+ let dependencyGraph =
677
+ try dependencyOracle. getDependencies ( workingDirectory: path,
678
+ commandLine: iterationCommand)
679
+
680
+ // The _Concurrency and _StringProcessing modules are automatically
681
+ // imported in newer versions of the Swift compiler. If they happened to
682
+ // be provided, adjust our expectations accordingly.
683
+ let hasConcurrencyModule = dependencyGraph. modules. keys. contains {
684
+ $0. moduleName == " _Concurrency "
685
+ }
686
+ let hasConcurrencyShimsModule = dependencyGraph. modules. keys. contains {
687
+ $0. moduleName == " _SwiftConcurrencyShims "
704
688
}
705
- lock. unlock ( )
689
+ let hasStringProcessingModule = dependencyGraph. modules. keys. contains {
690
+ $0. moduleName == " _StringProcessing "
691
+ }
692
+ let adjustedExpectedNumberOfDependencies =
693
+ expectedNumberOfDependencies +
694
+ ( hasConcurrencyModule ? 1 : 0 ) +
695
+ ( hasConcurrencyShimsModule ? 1 : 0 ) +
696
+ ( hasStringProcessingModule ? 1 : 0 )
697
+
698
+ if ( dependencyGraph. modules. count != adjustedExpectedNumberOfDependencies) {
699
+ lock. lock ( )
700
+ print ( " Unexpected Dependency Scanning Result ( \( dependencyGraph. modules. count) modules): " )
701
+ dependencyGraph. modules. forEach {
702
+ print ( $0. key. moduleName)
703
+ }
704
+ lock. unlock ( )
705
+ }
706
+ XCTAssertTrue ( dependencyGraph. modules. count ==
707
+ adjustedExpectedNumberOfDependencies)
708
+ } catch {
709
+ XCTFail ( " Unexpected error: \( error) " )
706
710
}
707
- XCTAssertTrue ( dependencyGraph. modules. count ==
708
- adjustedExpectedNumberOfDependencies)
709
711
}
710
712
711
713
// Change CAS path is an error.
@@ -759,9 +761,6 @@ final class CachingBuildTests: XCTestCase {
759
761
" -scanner-prefix-map " , path. description + " =/^tmp " ,
760
762
main. nativePathString ( escaped: true ) ] + sdkArgumentsForTesting,
761
763
env: ProcessEnv . vars)
762
- guard driver. isFeatureSupported ( . cache_compile_job) else {
763
- throw XCTSkip ( " toolchain does not support caching. " )
764
- }
765
764
guard driver. isFrontendArgSupported ( . scannerPrefixMap) else {
766
765
throw XCTSkip ( " frontend doesn't support prefix map " )
767
766
}
@@ -832,9 +831,6 @@ final class CachingBuildTests: XCTestCase {
832
831
" -working-directory " , path. nativePathString ( escaped: true ) ,
833
832
main. nativePathString ( escaped: true ) ] + sdkArgumentsForTesting,
834
833
env: ProcessEnv . vars)
835
- guard driver. isFeatureSupported ( . cache_compile_job) else {
836
- throw XCTSkip ( " toolchain does not support caching. " )
837
- }
838
834
let jobs = try driver. planBuild ( )
839
835
try driver. run ( jobs: jobs)
840
836
XCTAssertFalse ( driver. diagnosticEngine. hasErrors)
0 commit comments