@@ -205,6 +205,20 @@ private func checkCachingBuildJobDependencies(job: Job,
205205
206206
207207final 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+
208222 private func pathMatchesSwiftModule( path: VirtualPath , _ name: String ) -> Bool {
209223 return path. basenameWithoutExt. starts ( with: " \( name) - " ) &&
210224 path. extension! == FileType . swiftModule. rawValue
@@ -234,9 +248,6 @@ final class CachingBuildTests: XCTestCase {
234248 " -cache-compile-job " , " -cas-path " , casPath. nativePathString ( escaped: true ) ,
235249 " -import-objc-header " , bridgingHeaderpath. nativePathString ( escaped: true ) ,
236250 main. nativePathString ( escaped: true ) ] + sdkArgumentsForTesting)
237- guard driver. isFeatureSupported ( . cache_compile_job) else {
238- throw XCTSkip ( " toolchain does not support caching. " )
239- }
240251
241252 let jobs = try driver. planBuild ( )
242253 let dependencyGraph = try driver. gatherModuleDependencies ( )
@@ -361,9 +372,6 @@ final class CachingBuildTests: XCTestCase {
361372 guard driver. supportExplicitModuleVerifyInterface ( ) else {
362373 throw XCTSkip ( " -typecheck-module-from-interface doesn't support explicit build. " )
363374 }
364- guard driver. isFeatureSupported ( . cache_compile_job) else {
365- throw XCTSkip ( " toolchain does not support caching. " )
366- }
367375
368376 let jobs = try driver. planBuild ( )
369377 // Figure out which Triples to use.
@@ -492,9 +500,6 @@ final class CachingBuildTests: XCTestCase {
492500 " -working-directory " , path. nativePathString ( escaped: true ) ,
493501 main. nativePathString ( escaped: true ) ] + sdkArgumentsForTesting,
494502 env: ProcessEnv . vars)
495- guard driver. isFeatureSupported ( . cache_compile_job) else {
496- throw XCTSkip ( " toolchain does not support caching. " )
497- }
498503 let jobs = try driver. planBuild ( )
499504 try driver. run ( jobs: jobs)
500505 XCTAssertFalse ( driver. diagnosticEngine. hasErrors)
@@ -553,10 +558,6 @@ final class CachingBuildTests: XCTestCase {
553558 + sdkArgumentsForTesting,
554559 env: ProcessEnv . vars)
555560
556- // Ensure this tooling supports this functionality
557- guard fooBuildDriver. isFeatureSupported ( . cache_compile_job) else {
558- throw XCTSkip ( " toolchain does not support caching. " )
559- }
560561 let dependencyOracle = InterModuleDependencyOracle ( )
561562 let scanLibPath = try XCTUnwrap ( fooBuildDriver. toolchain. lookupSwiftScanLib ( ) )
562563 guard try dependencyOracle
@@ -623,9 +624,6 @@ final class CachingBuildTests: XCTestCase {
623624 " -disable-clang-target " ,
624625 main. nativePathString ( escaped: true ) ] + sdkArgumentsForTesting,
625626 env: ProcessEnv . vars)
626- guard driver. isFeatureSupported ( . cache_compile_job) else {
627- throw XCTSkip ( " toolchain does not support caching. " )
628- }
629627 let dependencyOracle = InterModuleDependencyOracle ( )
630628 let scanLibPath = try XCTUnwrap ( driver. toolchain. lookupSwiftScanLib ( ) )
631629 guard try dependencyOracle
@@ -674,38 +672,42 @@ final class CachingBuildTests: XCTestCase {
674672 // FIXME: We need to differentiate the scanning action hash,
675673 // though the module-name above should be sufficient.
676674 " -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 "
704688 }
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) " )
706710 }
707- XCTAssertTrue ( dependencyGraph. modules. count ==
708- adjustedExpectedNumberOfDependencies)
709711 }
710712
711713 // Change CAS path is an error.
@@ -759,9 +761,6 @@ final class CachingBuildTests: XCTestCase {
759761 " -scanner-prefix-map " , path. description + " =/^tmp " ,
760762 main. nativePathString ( escaped: true ) ] + sdkArgumentsForTesting,
761763 env: ProcessEnv . vars)
762- guard driver. isFeatureSupported ( . cache_compile_job) else {
763- throw XCTSkip ( " toolchain does not support caching. " )
764- }
765764 guard driver. isFrontendArgSupported ( . scannerPrefixMap) else {
766765 throw XCTSkip ( " frontend doesn't support prefix map " )
767766 }
@@ -832,9 +831,6 @@ final class CachingBuildTests: XCTestCase {
832831 " -working-directory " , path. nativePathString ( escaped: true ) ,
833832 main. nativePathString ( escaped: true ) ] + sdkArgumentsForTesting,
834833 env: ProcessEnv . vars)
835- guard driver. isFeatureSupported ( . cache_compile_job) else {
836- throw XCTSkip ( " toolchain does not support caching. " )
837- }
838834 let jobs = try driver. planBuild ( )
839835 try driver. run ( jobs: jobs)
840836 XCTAssertFalse ( driver. diagnosticEngine. hasErrors)
0 commit comments