@@ -214,6 +214,7 @@ fileprivate struct HostBuildToolBuildOperationTests: CoreBasedTests {
214
214
let hostToolsPackage = try await TestPackageProject (
215
215
" HostToolsPackage " ,
216
216
groupTree: TestGroup ( " Foo " , children: [
217
+ TestFile ( " tooldep.swift " ) ,
217
218
TestFile ( " tool.swift " ) ,
218
219
TestFile ( " lib.swift " ) ,
219
220
] ) ,
@@ -230,11 +231,18 @@ fileprivate struct HostBuildToolBuildOperationTests: CoreBasedTests {
230
231
] ) ,
231
232
] ,
232
233
targets: [
234
+ TestStandardTarget ( " HostToolDep " , type: . objectFile, buildPhases: [
235
+ TestSourcesBuildPhase ( [ " tooldep.swift " ] ) ,
236
+ ] ) ,
233
237
TestStandardTarget ( " HostTool " , type: . hostBuildTool, buildPhases: [
234
238
TestSourcesBuildPhase ( [ " tool.swift " ] ) ,
235
- TestFrameworksBuildPhase ( [ TestBuildFile ( . target( " PackageDepProduct " ) ) ] )
239
+ TestFrameworksBuildPhase ( [
240
+ TestBuildFile ( . target( " PackageDepProduct " ) ) ,
241
+ TestBuildFile ( . target( " HostToolDep " ) ) ,
242
+ ] ) ,
236
243
] , dependencies: [
237
- " PackageDepProduct "
244
+ " PackageDepProduct " ,
245
+ " HostToolDep " ,
238
246
] ) ,
239
247
TestStandardTarget ( " HostToolClientLib " , type: . objectFile, buildPhases: [
240
248
TestSourcesBuildPhase ( [ " lib.swift " ] ) ,
@@ -274,14 +282,22 @@ fileprivate struct HostBuildToolBuildOperationTests: CoreBasedTests {
274
282
"""
275
283
}
276
284
285
+ try await fs. writeFileContents ( root. join ( " HostToolsPackage/tooldep.swift " ) ) { stream in
286
+ stream <<<
287
+ """
288
+ public let samePackageMsg = " Hello from host tool same-package dependency! "
289
+ """
290
+ }
291
+
277
292
try await fs. writeFileContents ( root. join ( " HostToolsPackage/tool.swift " ) ) { stream in
278
293
stream <<<
279
294
"""
280
295
import PackageDep
296
+ import HostToolDep
281
297
282
298
@main struct Foo {
283
299
static func main() {
284
- print( " Hello from host tool! " + dependencyMessage)
300
+ print( " Hello from host tool! " + dependencyMessage + samePackageMsg )
285
301
}
286
302
}
287
303
"""
@@ -405,15 +421,57 @@ fileprivate struct HostBuildToolBuildOperationTests: CoreBasedTests {
405
421
}
406
422
}
407
423
408
- @Test ( . requireSDKs( . macOS, . iOS) , arguments: [ RunDestinationInfo . anyMac, . anyMacCatalyst, . anyiOSDevice] )
409
- func testHostToolsAndDependenciesAreBuiltDuringIndexingPreparationForPackage( destination: RunDestinationInfo ) async throws {
410
- try await withHostToolsPackages { tester, testWorkspace in
411
- try await tester. checkIndexBuild ( prepareTargets: testWorkspace. projects [ 1 ] . targets. map ( \. guid) , workspaceOperation: false , runDestination: destination, persistent: true ) { results in
424
+ @Test ( . requireSDKs( . macOS, . iOS) , arguments: [ RunDestinationInfo . anyMac, . anyMacCatalyst, . anyiOSDevice] , [ true , false ] )
425
+ func testHostToolsAndDependenciesAreBuiltDuringIndexingPreparationForPackage(
426
+ destination: RunDestinationInfo , targetBuild: Bool
427
+ ) async throws {
428
+ let clientPackage = try await TestPackageProject (
429
+ " ClientPackage " ,
430
+ groupTree: TestGroup ( " Client " , children: [
431
+ TestFile ( " main.swift " ) ,
432
+ ] ) ,
433
+ buildConfigurations: [
434
+ TestBuildConfiguration (
435
+ " Debug " ,
436
+ buildSettings: [
437
+ " SWIFT_VERSION " : swiftVersion,
438
+ " GENERATE_INFOPLIST_FILE " : " YES " ,
439
+ " PRODUCT_NAME " : " $(TARGET_NAME) " ,
440
+ " CODE_SIGNING_ALLOWED " : " NO " ,
441
+ " SDKROOT " : " auto " ,
442
+ " SUPPORTED_PLATFORMS " : " $(AVAILABLE_PLATFORMS) " ,
443
+ ] ) ,
444
+ ] ,
445
+ targets: [
446
+ TestStandardTarget ( " HostToolClient " , type: . objectFile, buildPhases: [
447
+ TestSourcesBuildPhase ( [ " main.swift " ] ) ,
448
+ TestFrameworksBuildPhase ( [ TestBuildFile ( . target( " HostToolClientLibProduct " ) ) ] ) ,
449
+ ] , dependencies: [
450
+ " HostToolClientLibProduct "
451
+ ] ) ,
452
+ ] )
453
+
454
+ try await withHostToolsPackages ( clients: clientPackage) { tester, testWorkspace in
455
+ try await tester. fs. writeFileContents ( testWorkspace. sourceRoot. join ( " ClientPackage/main.swift " ) ) { stream in
456
+ stream <<<
457
+ """
458
+ print( " Hello, world! " )
459
+ """
460
+ }
461
+
462
+ let clientTarget = try #require( clientPackage. targets. first)
463
+ try await tester. checkIndexBuild (
464
+ prepareTargets: [ clientTarget. guid] ,
465
+ buildTargets: targetBuild ? [ clientTarget] : nil ,
466
+ workspaceOperation: false , runDestination: destination,
467
+ persistent: true
468
+ ) { results in
412
469
results. checkNoDiagnostics ( )
413
470
414
471
results. checkTaskExists ( . matchTargetName( " HostTool " ) , . matchRuleType( " Ld " ) )
415
472
try results. checkTask ( . matchTargetName( " HostTool " ) , . matchRuleType( ProductPlan . preparedForIndexPreCompilationRuleName) ) { task in
416
473
try results. checkTaskFollows ( task, . matchTargetName( " PackageDep " ) , . matchRuleType( " Libtool " ) )
474
+ try results. checkTaskFollows ( task, . matchTargetName( " HostToolDep " ) , . matchRuleType( " SwiftDriver Compilation " ) )
417
475
}
418
476
}
419
477
}
0 commit comments