@@ -439,6 +439,181 @@ fileprivate struct HostBuildToolBuildOperationTests: CoreBasedTests {
439
439
}
440
440
}
441
441
442
+ @Test ( . requireSDKs( . macOS) )
443
+ func testHostToolsAndDependenciesAreBuiltDuringIndexingPreparationForPackage( ) async throws {
444
+ try await withTemporaryDirectory { tmpDirPath async throws -> Void in
445
+ let depPackage = try await TestPackageProject (
446
+ " DepPackage " ,
447
+ groupTree: TestGroup ( " Foo " , children: [
448
+ TestFile ( " transitivedep.swift " ) ,
449
+ TestFile ( " dep.swift " ) ,
450
+ ] ) ,
451
+ buildConfigurations: [
452
+ TestBuildConfiguration (
453
+ " Debug " ,
454
+ buildSettings: [
455
+ " SWIFT_VERSION " : swiftVersion,
456
+ " GENERATE_INFOPLIST_FILE " : " YES " ,
457
+ " PRODUCT_NAME " : " $(TARGET_NAME) " ,
458
+ " CODE_SIGNING_ALLOWED " : " NO " ,
459
+ ] ) ,
460
+ ] ,
461
+ targets: [
462
+ TestStandardTarget ( " TransitivePackageDep " , type: . objectFile, buildConfigurations: [
463
+ TestBuildConfiguration (
464
+ " Debug " ,
465
+ buildSettings: [
466
+ " SDKROOT " : " auto " ,
467
+ " SUPPORTED_PLATFORMS " : " macosx iphoneos iphonesimulator " ,
468
+ ] ,
469
+ impartedBuildProperties:
470
+ TestImpartedBuildProperties (
471
+ buildSettings: [
472
+ " SWIFT_ACTIVE_COMPILATION_CONDITIONS " : " IMPARTED_SETTINGS "
473
+ ] )
474
+ ) ,
475
+ ] , buildPhases: [
476
+ TestSourcesBuildPhase ( [ " transitivedep.swift " ] )
477
+ ] ) ,
478
+ TestStandardTarget ( " PackageDep " , type: . staticLibrary, buildConfigurations: [
479
+ TestBuildConfiguration (
480
+ " Debug " ,
481
+ buildSettings: [
482
+ " SDKROOT " : " auto " ,
483
+ " SUPPORTED_PLATFORMS " : " macosx iphoneos iphonesimulator " ,
484
+ ] ) ,
485
+ ] , buildPhases: [
486
+ TestSourcesBuildPhase ( [ " dep.swift " ] ) ,
487
+ TestFrameworksBuildPhase ( [
488
+ TestBuildFile ( . target( " TransitivePackageDep " ) )
489
+ ] )
490
+ ] , dependencies: [
491
+ " TransitivePackageDep "
492
+ ] ) ,
493
+ TestPackageProductTarget ( " PackageDepProduct " , frameworksBuildPhase:
494
+ TestFrameworksBuildPhase ( [
495
+ TestBuildFile ( . target( " PackageDep " ) ) ,
496
+ ]
497
+ ) , buildConfigurations: [
498
+ TestBuildConfiguration (
499
+ " Debug " ,
500
+ buildSettings: [
501
+ " SDKROOT " : " auto " ,
502
+ " SUPPORTED_PLATFORMS " : " macosx iphoneos iphonesimulator " ,
503
+ ] ) ,
504
+ ] , dependencies: [
505
+ " PackageDep "
506
+ ] ) ,
507
+ ] )
508
+
509
+ let hostToolsPackage = try await TestPackageProject (
510
+ " HostToolsPackage " ,
511
+ groupTree: TestGroup ( " Foo " , children: [
512
+ TestFile ( " tool.swift " ) ,
513
+ TestFile ( " lib.swift " ) ,
514
+ ] ) ,
515
+ buildConfigurations: [
516
+ TestBuildConfiguration (
517
+ " Debug " ,
518
+ buildSettings: [
519
+ " SWIFT_VERSION " : swiftVersion,
520
+ " GENERATE_INFOPLIST_FILE " : " YES " ,
521
+ " PRODUCT_NAME " : " $(TARGET_NAME) " ,
522
+ " CODE_SIGNING_ALLOWED " : " NO " ,
523
+ ] ) ,
524
+ ] ,
525
+ targets: [
526
+ TestStandardTarget ( " HostTool " , type: . hostBuildTool, buildConfigurations: [
527
+ TestBuildConfiguration (
528
+ " Debug " ,
529
+ buildSettings: [
530
+ " SDKROOT " : " auto " ,
531
+ ] )
532
+ ] , buildPhases: [
533
+ TestSourcesBuildPhase ( [ " tool.swift " ] ) ,
534
+ TestFrameworksBuildPhase ( [ TestBuildFile ( . target( " PackageDepProduct " ) ) ] )
535
+ ] , dependencies: [
536
+ " PackageDepProduct "
537
+ ] ) ,
538
+ TestStandardTarget ( " HostToolClientLib " , type: . objectFile, buildConfigurations: [
539
+ TestBuildConfiguration (
540
+ " Debug " ,
541
+ buildSettings: [
542
+ " SDKROOT " : " auto " ,
543
+ " SUPPORTED_PLATFORMS " : " macosx iphoneos iphonesimulator " ,
544
+ ] ) ,
545
+ ] , buildPhases: [
546
+ TestSourcesBuildPhase ( [ " lib.swift " ] ) ,
547
+ ] , dependencies: [
548
+ " HostTool "
549
+ ] ) ,
550
+ TestPackageProductTarget ( " HostToolClientLibProduct " , frameworksBuildPhase:
551
+ TestFrameworksBuildPhase ( [ TestBuildFile ( . target( " HostToolClientLib " ) ) ]
552
+ ) , buildConfigurations: [
553
+ TestBuildConfiguration (
554
+ " Debug " ,
555
+ buildSettings: [
556
+ " SDKROOT " : " auto " ,
557
+ " SUPPORTED_PLATFORMS " : " macosx iphoneos iphonesimulator " ,
558
+ ] ) ,
559
+ ] , dependencies: [
560
+ " HostToolClientLib "
561
+ ] ) ,
562
+ ] )
563
+
564
+ let testWorkspace = TestWorkspace ( " aWorkspace " , sourceRoot: tmpDirPath. join ( " Test " ) , projects: [ depPackage, hostToolsPackage] )
565
+ let tester = try await BuildOperationTester ( getCore ( ) , testWorkspace, simulated: false , systemInfo: . init( operatingSystemVersion: Version ( 99 , 98 , 97 ) , productBuildVersion: " 99A98 " , nativeArchitecture: Architecture . host. stringValue ?? " undefined_arch " ) )
566
+
567
+ try await tester. fs. writeFileContents ( testWorkspace. sourceRoot. join ( " DepPackage/transitivedep.swift " ) ) { stream in
568
+ stream <<<
569
+ """
570
+ public let transitiveDependencyMessage = " Hello from host tool transitive dependency! "
571
+ """
572
+ }
573
+
574
+ try await tester. fs. writeFileContents ( testWorkspace. sourceRoot. join ( " DepPackage/dep.swift " ) ) { stream in
575
+ stream <<<
576
+ """
577
+ import TransitivePackageDep
578
+
579
+ public let dependencyMessage = " Hello from host tool dependency! " + transitiveDependencyMessage
580
+ #if !IMPARTED_SETTINGS
581
+ #error( " settings not imparted " )
582
+ #endif
583
+ """
584
+ }
585
+
586
+ try await tester. fs. writeFileContents ( testWorkspace. sourceRoot. join ( " HostToolsPackage/tool.swift " ) ) { stream in
587
+ stream <<<
588
+ """
589
+ import PackageDep
590
+
591
+ @main struct Foo {
592
+ static func main() {
593
+ print( " Hello from host tool! " + dependencyMessage)
594
+ }
595
+ }
596
+ """
597
+ }
598
+
599
+ try await tester. fs. writeFileContents ( testWorkspace. sourceRoot. join ( " HostToolsPackage/lib.swift " ) ) { stream in
600
+ stream <<<
601
+ """
602
+ public class MyClass {}
603
+ """
604
+ }
605
+
606
+ try await tester. checkIndexBuild ( prepareTargets: hostToolsPackage. targets. map ( \. guid) , workspaceOperation: false , runDestination: . anyMac, persistent: true ) { results in
607
+ results. checkNoDiagnostics ( )
608
+
609
+ results. checkTaskExists ( . matchTargetName( " HostTool " ) , . matchRuleType( " Ld " ) )
610
+ try results. checkTask ( . matchTargetName( " HostTool " ) , . matchRuleType( ProductPlan . preparedForIndexPreCompilationRuleName) ) { task in
611
+ try results. checkTaskFollows ( task, . matchTargetName( " PackageDep " ) , . matchRuleType( " Libtool " ) )
612
+ }
613
+ }
614
+ }
615
+ }
616
+
442
617
@Test ( . requireSDKs( . macOS) )
443
618
func hostToolsAreSkippedDuringIndexingPreparationWhenUnapproved( ) async throws {
444
619
try await withTemporaryDirectory { tmpDirPath async throws -> Void in
0 commit comments