@@ -986,17 +986,60 @@ final class CachingBuildTests: XCTestCase {
986
986
XCTFail ( " Cached compilation doesn't have a CAS " )
987
987
}
988
988
try checkCASForResults ( jobs: jobs, cas: cas, fs: driver. fileSystem)
989
+ }
990
+ }
989
991
990
- // try replan the job and make sure some key command-line options are generated.
991
- let rebuildJobs = try driver. planBuild ( )
992
- for job in rebuildJobs {
993
- if job. kind == . compile || job. kind == . emitModule {
994
- XCTAssertTrue ( job. commandLine. contains ( . flag( String ( " -disable-implicit-swift-modules " ) ) ) )
995
- XCTAssertTrue ( job. commandLine. contains ( . flag( String ( " -cache-compile-job " ) ) ) )
996
- XCTAssertTrue ( job. commandLine. contains ( . flag( String ( " -cas-path " ) ) ) )
997
- XCTAssertTrue ( job. commandLine. contains ( . flag( String ( " -bridging-header-pch-key " ) ) ) )
998
- }
992
+ func testCacheBatchBuildPlan( ) throws {
993
+ try withTemporaryDirectory { path in
994
+ try localFileSystem. changeCurrentWorkingDirectory ( to: path)
995
+ let moduleCachePath = path. appending ( component: " ModuleCache " )
996
+ let casPath = path. appending ( component: " cas " )
997
+ try localFileSystem. createDirectory ( moduleCachePath)
998
+ let main = path. appending ( component: " testCachingBuild.swift " )
999
+ let mainFileContent = " import C;import E;import G; "
1000
+ try localFileSystem. writeFileContents ( main) {
1001
+ $0. send ( mainFileContent)
999
1002
}
1003
+ let ofm = path. appending ( component: " ofm.json " )
1004
+ let inputPathsAndContents : [ ( AbsolutePath , String ) ] = [ ( main, mainFileContent) ]
1005
+ OutputFileMapCreator . write (
1006
+ module: " Test " , inputPaths: inputPathsAndContents. map { $0. 0 } ,
1007
+ derivedData: path, to: ofm, excludeMainEntry: false )
1008
+
1009
+ let cHeadersPath : AbsolutePath =
1010
+ try testInputsPath. appending ( component: " ExplicitModuleBuilds " )
1011
+ . appending ( component: " CHeaders " )
1012
+ let swiftModuleInterfacesPath : AbsolutePath =
1013
+ try testInputsPath. appending ( component: " ExplicitModuleBuilds " )
1014
+ . appending ( component: " Swift " )
1015
+ let sdkArgumentsForTesting = ( try ? Driver . sdkArgumentsForTesting ( ) ) ?? [ ]
1016
+ let bridgingHeaderpath : AbsolutePath =
1017
+ cHeadersPath. appending ( component: " Bridging.h " )
1018
+ var driver = try Driver ( args: [ " swiftc " ,
1019
+ " -I " , cHeadersPath. nativePathString ( escaped: true ) ,
1020
+ " -I " , swiftModuleInterfacesPath. nativePathString ( escaped: true ) ,
1021
+ " -explicit-module-build " , " -Rcache-compile-job " , " -incremental " ,
1022
+ " -module-cache-path " , moduleCachePath. nativePathString ( escaped: true ) ,
1023
+ " -cache-compile-job " , " -cas-path " , casPath. nativePathString ( escaped: true ) ,
1024
+ " -import-objc-header " , bridgingHeaderpath. nativePathString ( escaped: true ) ,
1025
+ " -output-file-map " , ofm. nativePathString ( escaped: true ) ,
1026
+ " -working-directory " , path. nativePathString ( escaped: true ) ,
1027
+ main. nativePathString ( escaped: true ) ] + sdkArgumentsForTesting,
1028
+ interModuleDependencyOracle: dependencyOracle)
1029
+ let jobs = try driver. planBuild ( )
1030
+ try driver. run ( jobs: jobs)
1031
+ XCTAssertFalse ( driver. diagnosticEngine. hasErrors)
1032
+
1033
+ let scanLibPath = try XCTUnwrap ( driver. getSwiftScanLibPath ( ) )
1034
+ try dependencyOracle. verifyOrCreateScannerInstance ( swiftScanLibPath: scanLibPath)
1035
+
1036
+ let cas = try dependencyOracle. getOrCreateCAS ( pluginPath: nil , onDiskPath: casPath, pluginOptions: [ ] )
1037
+ if let driverCAS = driver. cas {
1038
+ XCTAssertEqual ( cas, driverCAS, " CAS should only be created once " )
1039
+ } else {
1040
+ XCTFail ( " Cached compilation doesn't have a CAS " )
1041
+ }
1042
+ try checkCASForResults ( jobs: jobs, cas: cas, fs: driver. fileSystem)
1000
1043
}
1001
1044
}
1002
1045
0 commit comments