@@ -336,6 +336,114 @@ final class CachingBuildTests: XCTestCase {
336
336
}
337
337
}
338
338
339
+ func testModuleOnlyJob( ) throws {
340
+ try withTemporaryDirectory { path in
341
+ let main = path. appending ( component: " testModuleOnlyJob.swift " )
342
+ try localFileSystem. writeFileContents ( main) {
343
+ $0. send ( " import C;import E; " )
344
+ }
345
+ let other = path. appending ( component: " testModuleOnlyJob2.swift " )
346
+ try localFileSystem. writeFileContents ( other) {
347
+ $0. send ( " import G; " )
348
+ }
349
+ let swiftModuleInterfacesPath : AbsolutePath =
350
+ try testInputsPath. appending ( component: " ExplicitModuleBuilds " )
351
+ . appending ( component: " Swift " )
352
+ let cHeadersPath : AbsolutePath =
353
+ try testInputsPath. appending ( component: " ExplicitModuleBuilds " )
354
+ . appending ( component: " CHeaders " )
355
+ let casPath = path. appending ( component: " cas " )
356
+ let swiftInterfacePath : AbsolutePath = path. appending ( component: " testModuleOnlyJob.swiftinterface " )
357
+ let privateSwiftInterfacePath : AbsolutePath = path. appending ( component: " testModuleOnlyJob.private.swiftinterface " )
358
+ let modulePath : AbsolutePath = path. appending ( component: " testModuleOnlyJob.swiftmodule " )
359
+ let sdkArgumentsForTesting = ( try ? Driver . sdkArgumentsForTesting ( ) ) ?? [ ]
360
+ var driver = try Driver ( args: [ " swiftc " ,
361
+ " -target " , " x86_64-apple-macosx11.0 " ,
362
+ " -module-name " , " Test " ,
363
+ " -I " , cHeadersPath. nativePathString ( escaped: true ) ,
364
+ " -I " , swiftModuleInterfacesPath. nativePathString ( escaped: true ) ,
365
+ " -emit-module-interface-path " , swiftInterfacePath. nativePathString ( escaped: true ) ,
366
+ " -emit-private-module-interface-path " , privateSwiftInterfacePath. nativePathString ( escaped: true ) ,
367
+ " -explicit-module-build " , " -emit-module-separately-wmo " , " -disable-cmo " , " -Rcache-compile-job " ,
368
+ " -enable-library-evolution " , " -O " , " -whole-module-optimization " ,
369
+ " -cache-compile-job " , " -cas-path " , casPath. nativePathString ( escaped: true ) ,
370
+ " -emit-module " , " -o " , modulePath. nativePathString ( escaped: true ) ,
371
+ main. nativePathString ( escaped: true ) , other. nativePathString ( escaped: true ) ] + sdkArgumentsForTesting,
372
+ env: ProcessEnv . vars,
373
+ interModuleDependencyOracle: dependencyOracle)
374
+ let jobs = try driver. planBuild ( )
375
+ try driver. run ( jobs: jobs)
376
+ for job in jobs {
377
+ XCTAssertFalse ( job. outputCacheKeys. isEmpty)
378
+ }
379
+ XCTAssertFalse ( driver. diagnosticEngine. hasErrors)
380
+
381
+ let scanLibPath = try XCTUnwrap ( driver. getSwiftScanLibPath ( ) )
382
+ try dependencyOracle. verifyOrCreateScannerInstance ( fileSystem: localFileSystem,
383
+ swiftScanLibPath: scanLibPath)
384
+
385
+ let cas = try dependencyOracle. getOrCreateCAS ( pluginPath: nil , onDiskPath: casPath, pluginOptions: [ ] )
386
+ if let driverCAS = driver. cas {
387
+ XCTAssertEqual ( cas, driverCAS, " CAS should only be created once " )
388
+ } else {
389
+ XCTFail ( " Cached compilation doesn't have a CAS " )
390
+ }
391
+ try checkCASForResults ( jobs: jobs, cas: cas, fs: driver. fileSystem)
392
+ }
393
+ }
394
+
395
+ func testSeparateModuleJob( ) throws {
396
+ try withTemporaryDirectory { path in
397
+ let main = path. appending ( component: " testSeparateModuleJob.swift " )
398
+ try localFileSystem. writeFileContents ( main) {
399
+ $0. send ( " import C;import E; " )
400
+ }
401
+ let swiftModuleInterfacesPath : AbsolutePath =
402
+ try testInputsPath. appending ( component: " ExplicitModuleBuilds " )
403
+ . appending ( component: " Swift " )
404
+ let cHeadersPath : AbsolutePath =
405
+ try testInputsPath. appending ( component: " ExplicitModuleBuilds " )
406
+ . appending ( component: " CHeaders " )
407
+ let casPath = path. appending ( component: " cas " )
408
+ let swiftInterfacePath : AbsolutePath = path. appending ( component: " testSeparateModuleJob.swiftinterface " )
409
+ let privateSwiftInterfacePath : AbsolutePath = path. appending ( component: " testSeparateModuleJob.private.swiftinterface " )
410
+ let modulePath : AbsolutePath = path. appending ( component: " testSeparateModuleJob.swiftmodule " )
411
+ let sdkArgumentsForTesting = ( try ? Driver . sdkArgumentsForTesting ( ) ) ?? [ ]
412
+ var driver = try Driver ( args: [ " swiftc " ,
413
+ " -target " , " x86_64-apple-macosx11.0 " ,
414
+ " -module-name " , " Test " ,
415
+ " -I " , cHeadersPath. nativePathString ( escaped: true ) ,
416
+ " -I " , swiftModuleInterfacesPath. nativePathString ( escaped: true ) ,
417
+ " -emit-module-path " , modulePath. nativePathString ( escaped: true ) ,
418
+ " -emit-module-interface-path " , swiftInterfacePath. nativePathString ( escaped: true ) ,
419
+ " -emit-private-module-interface-path " , privateSwiftInterfacePath. nativePathString ( escaped: true ) ,
420
+ " -explicit-module-build " , " -experimental-emit-module-separately " , " -Rcache-compile-job " ,
421
+ " -enable-library-evolution " , " -O " ,
422
+ " -cache-compile-job " , " -cas-path " , casPath. nativePathString ( escaped: true ) ,
423
+ main. nativePathString ( escaped: true ) ] + sdkArgumentsForTesting,
424
+ env: ProcessEnv . vars,
425
+ interModuleDependencyOracle: dependencyOracle)
426
+ let jobs = try driver. planBuild ( )
427
+ for job in jobs {
428
+ XCTAssertFalse ( job. outputCacheKeys. isEmpty)
429
+ }
430
+ try driver. run ( jobs: jobs)
431
+ XCTAssertFalse ( driver. diagnosticEngine. hasErrors)
432
+
433
+ let scanLibPath = try XCTUnwrap ( driver. getSwiftScanLibPath ( ) )
434
+ try dependencyOracle. verifyOrCreateScannerInstance ( fileSystem: localFileSystem,
435
+ swiftScanLibPath: scanLibPath)
436
+
437
+ let cas = try dependencyOracle. getOrCreateCAS ( pluginPath: nil , onDiskPath: casPath, pluginOptions: [ ] )
438
+ if let driverCAS = driver. cas {
439
+ XCTAssertEqual ( cas, driverCAS, " CAS should only be created once " )
440
+ } else {
441
+ XCTFail ( " Cached compilation doesn't have a CAS " )
442
+ }
443
+ try checkCASForResults ( jobs: jobs, cas: cas, fs: driver. fileSystem)
444
+ }
445
+ }
446
+
339
447
/// Test generation of explicit module build jobs for dependency modules when the driver
340
448
/// is invoked with -explicit-module-build, -verify-emitted-module-interface and -enable-library-evolution.
341
449
func testExplicitModuleVerifyInterfaceJobs( ) throws {
0 commit comments