@@ -761,4 +761,73 @@ final class CachingBuildTests: XCTestCase {
761
761
}
762
762
}
763
763
}
764
+
765
+ func testCacheIncrementalBuildPlan( ) throws {
766
+ try withTemporaryDirectory { path in
767
+ try localFileSystem. changeCurrentWorkingDirectory ( to: path)
768
+ let moduleCachePath = path. appending ( component: " ModuleCache " )
769
+ let casPath = path. appending ( component: " cas " )
770
+ try localFileSystem. createDirectory ( moduleCachePath)
771
+ let main = path. appending ( component: " testCachingBuild.swift " )
772
+ let mainFileContent = " import C;import E;import G; "
773
+ try localFileSystem. writeFileContents ( main) {
774
+ $0. send ( mainFileContent)
775
+ }
776
+ let ofm = path. appending ( component: " ofm.json " )
777
+ let inputPathsAndContents : [ ( AbsolutePath , String ) ] = [ ( main, mainFileContent) ]
778
+ OutputFileMapCreator . write (
779
+ module: " Test " , inputPaths: inputPathsAndContents. map { $0. 0 } ,
780
+ derivedData: path, to: ofm, excludeMainEntry: false )
781
+
782
+ let cHeadersPath : AbsolutePath =
783
+ try testInputsPath. appending ( component: " ExplicitModuleBuilds " )
784
+ . appending ( component: " CHeaders " )
785
+ let swiftModuleInterfacesPath : AbsolutePath =
786
+ try testInputsPath. appending ( component: " ExplicitModuleBuilds " )
787
+ . appending ( component: " Swift " )
788
+ let sdkArgumentsForTesting = ( try ? Driver . sdkArgumentsForTesting ( ) ) ?? [ ]
789
+ let bridgingHeaderpath : AbsolutePath =
790
+ cHeadersPath. appending ( component: " Bridging.h " )
791
+ var driver = try Driver ( args: [ " swiftc " ,
792
+ " -I " , cHeadersPath. nativePathString ( escaped: true ) ,
793
+ " -I " , swiftModuleInterfacesPath. nativePathString ( escaped: true ) ,
794
+ " -explicit-module-build " , " -v " , " -Rcache-compile-job " , " -incremental " ,
795
+ " -module-cache-path " , moduleCachePath. nativePathString ( escaped: true ) ,
796
+ " -cache-compile-job " , " -cas-path " , casPath. nativePathString ( escaped: true ) ,
797
+ " -import-objc-header " , bridgingHeaderpath. nativePathString ( escaped: true ) ,
798
+ " -output-file-map " , ofm. nativePathString ( escaped: true ) ,
799
+ " -working-directory " , path. nativePathString ( escaped: true ) ,
800
+ main. nativePathString ( escaped: true ) ] + sdkArgumentsForTesting,
801
+ env: ProcessEnv . vars)
802
+ guard driver. isFeatureSupported ( . cache_compile_job) else {
803
+ throw XCTSkip ( " toolchain does not support caching. " )
804
+ }
805
+ let jobs = try driver. planBuild ( )
806
+ try driver. run ( jobs: jobs)
807
+ XCTAssertFalse ( driver. diagnosticEngine. hasErrors)
808
+
809
+ let dependencyOracle = InterModuleDependencyOracle ( )
810
+ let scanLibPath = try XCTUnwrap ( driver. toolchain. lookupSwiftScanLib ( ) )
811
+ guard try dependencyOracle
812
+ . verifyOrCreateScannerInstance ( fileSystem: localFileSystem,
813
+ swiftScanLibPath: scanLibPath) else {
814
+ XCTFail ( " Dependency scanner library not found " )
815
+ return
816
+ }
817
+
818
+ let cas = try dependencyOracle. createCAS ( pluginPath: nil , onDiskPath: casPath, pluginOptions: [ ] )
819
+ try checkCASForResults ( jobs: jobs, cas: cas, fs: driver. fileSystem)
820
+
821
+ // try replan the job and make sure some key command-line options are generated.
822
+ let rebuildJobs = try driver. planBuild ( )
823
+ for job in rebuildJobs {
824
+ if job. kind == . compile || job. kind == . emitModule {
825
+ XCTAssertTrue ( job. commandLine. contains ( . flag( String ( " -disable-implicit-swift-modules " ) ) ) )
826
+ XCTAssertTrue ( job. commandLine. contains ( . flag( String ( " -cache-compile-job " ) ) ) )
827
+ XCTAssertTrue ( job. commandLine. contains ( . flag( String ( " -cas-path " ) ) ) )
828
+ XCTAssertTrue ( job. commandLine. contains ( . flag( String ( " -bridging-header-pch-key " ) ) ) )
829
+ }
830
+ }
831
+ }
832
+ }
764
833
}
0 commit comments