@@ -306,6 +306,89 @@ fileprivate struct InspectBuildDescriptionTests {
306
306
}
307
307
}
308
308
}
309
+
310
+ @Test ( . requireSDKs( . macOS) )
311
+ func selectConfiguredTargets( ) async throws {
312
+ try await withTemporaryDirectory { ( temporaryDirectory: NamedTemporaryDirectory ) in
313
+ try await withAsyncDeferrable { deferrable in
314
+ let tmpDir = temporaryDirectory. path
315
+ let testSession = try await TestSWBSession ( temporaryDirectory: temporaryDirectory)
316
+ await deferrable. addBlock {
317
+ await #expect( throws: Never . self) {
318
+ try await testSession. close ( )
319
+ }
320
+ }
321
+
322
+ let macOSAppTarget = TestStandardTarget (
323
+ " MyApp1 " ,
324
+ type: . application,
325
+ buildConfigurations: [ TestBuildConfiguration ( " Debug " , buildSettings: [ " SDKROOT " : " macosx " , " SUPPORTED_PLATFORMS " : " macosx " ] ) ] ,
326
+ buildPhases: [ TestSourcesBuildPhase ( [ TestBuildFile ( " MyApp1.swift " ) ] ) ]
327
+ )
328
+
329
+ let iOSAppTarget = TestStandardTarget (
330
+ " MyApp2 " ,
331
+ type: . application,
332
+ buildConfigurations: [ TestBuildConfiguration ( " Debug " , buildSettings: [ " SDKROOT " : " iphoneos " , " SUPPORTED_PLATFORMS " : " macosx iphoneos " ] ) ] ,
333
+ buildPhases: [ TestSourcesBuildPhase ( [ TestBuildFile ( " MyApp2.swift " ) ] ) ] ,
334
+ dependencies: [ TestTargetDependency ( " MyFramework " ) ]
335
+ )
336
+
337
+ let project = TestProject (
338
+ " Test " ,
339
+ groupTree: TestGroup ( " Test " , children: [ TestFile ( " MyFramework.swift " ) , TestFile ( " MyApp1.swift " ) , TestFile ( " MyApp2.swift " ) ] ) ,
340
+ targets: [ macOSAppTarget, iOSAppTarget]
341
+
342
+ )
343
+
344
+ let workspace = TestWorkspace ( " MyWorkspace " , projects: [ project] )
345
+
346
+ try await testSession. sendPIF ( TestWorkspace ( " Test " , sourceRoot: tmpDir, projects: [ project] ) )
347
+
348
+ let buildDescriptionID = try await createIndexBuildDescription ( workspace, session: testSession)
349
+
350
+ func configuredTarget( for target: TestStandardTarget , using runDestination: SWBRunDestinationInfo ? = nil ) async throws -> SWBConfiguredTargetIdentifier {
351
+ let result = try await configuredTargets ( for: [ target] , using: runDestination)
352
+ return try #require( result. only)
353
+ }
354
+
355
+ func configuredTargets( for targets: [ TestStandardTarget ] , using runDestination: SWBRunDestinationInfo ? = nil ) async throws -> [ SWBConfiguredTargetIdentifier ] {
356
+ var request = SWBBuildRequest ( )
357
+ request. parameters. activeRunDestination = runDestination
358
+ request. enableIndexBuildArena = true
359
+
360
+ return try await testSession. session. selectConfiguredTargetsForIndex ( targets: targets. map { SWBTargetGUID ( rawValue: $0. guid) } , buildDescription: . init( buildDescriptionID) , buildRequest: request)
361
+ }
362
+
363
+ let macOSAppForMacOSRef = try await configuredTarget ( for: macOSAppTarget, using: . macOS)
364
+ #expect( macOSAppForMacOSRef. rawGUID. contains ( " macosx " ) )
365
+
366
+ let macOSAppForiOSRef = try await configuredTarget ( for: macOSAppTarget, using: . iOS)
367
+ #expect( macOSAppForiOSRef. rawGUID. contains ( " macosx " ) )
368
+
369
+ let iOSAppRefNoDestination = try await configuredTarget ( for: iOSAppTarget)
370
+ #expect( iOSAppRefNoDestination. rawGUID. contains ( " macosx " ) )
371
+
372
+ let iOSAppForMacOSRef = try await configuredTarget ( for: iOSAppTarget, using: . macOS)
373
+ #expect( iOSAppForMacOSRef. rawGUID. contains ( " macosx " ) )
374
+
375
+ let iOSAppForiOSRef = try await configuredTarget ( for: iOSAppTarget, using: . iOS)
376
+ #expect( iOSAppForiOSRef. rawGUID. contains ( " iphoneos " ) )
377
+
378
+ let iOSAppForUnsupportedRef = try await configuredTarget ( for: iOSAppTarget, using: . watchOS)
379
+ #expect( iOSAppForUnsupportedRef. rawGUID. contains ( " macosx " ) )
380
+
381
+ let multiple = try await configuredTargets ( for: [ macOSAppTarget, iOSAppTarget] , using: . macOS)
382
+ #expect( multiple. count == 2 )
383
+ do {
384
+ let macOSAppGUID = try #require( multiple. first? . targetGUID. rawValue)
385
+ let iOSAppGUID = try #require( multiple. last? . targetGUID. rawValue)
386
+ #expect( macOSAppGUID == macOSAppTarget. guid)
387
+ #expect( iOSAppGUID == iOSAppTarget. guid)
388
+ }
389
+ }
390
+ }
391
+ }
309
392
}
310
393
311
394
fileprivate extension SWBBuildServiceSession {
0 commit comments