@@ -1541,29 +1541,78 @@ package final class BuildOperationTester {
1541
1541
try await checkBuild ( name, parameters: parameters, runDestination: runDestination, buildRequest: inputBuildRequest, buildCommand: buildCommand, schemeCommand: schemeCommand, persistent: persistent, serial: serial, buildOutputMap: buildOutputMap, signableTargets: signableTargets, signableTargetInputs: signableTargetInputs, clientDelegate: clientDelegate, sourceLocation: sourceLocation, body: body)
1542
1542
}
1543
1543
1544
+ package static func buildRequestForIndexOperation(
1545
+ workspace: Workspace,
1546
+ buildTargets: [ any TestTarget ] ? = nil ,
1547
+ prepareTargets: [ String] ? = nil ,
1548
+ workspaceOperation: Bool? = nil ,
1549
+ runDestination: RunDestinationInfo? = nil ,
1550
+ sourceLocation: SourceLocation = #_sourceLocation
1551
+ ) throws -> BuildRequest {
1552
+ let workspaceOperation = workspaceOperation ?? ( buildTargets == nil )
1553
+
1554
+ // If this is an operation on the entire workspace (rather than for a specific target/package), then
1555
+ // we will end up configuring for all platforms - do not pass a run destination. Use the provided (or a
1556
+ // reasonable default) otherwise.
1557
+ let buildDestination : RunDestinationInfo ?
1558
+ if workspaceOperation {
1559
+ buildDestination = nil
1560
+ } else {
1561
+ buildDestination = runDestination ?? RunDestinationInfo . macOS
1562
+ }
1563
+
1564
+ let arena = ArenaInfo . indexBuildArena ( derivedDataRoot: workspace. path. dirname)
1565
+ let overrides : [ String : String ] = [ " ONLY_ACTIVE_ARCH " : " YES " , " ALWAYS_SEARCH_USER_PATHS " : " NO " ]
1566
+ let buildRequestParameters = BuildParameters ( action: . indexBuild, configuration: " Debug " , activeRunDestination: buildDestination, overrides: overrides, arena: arena)
1567
+
1568
+ let buildRequestTargets : [ BuildRequest . BuildTargetInfo ]
1569
+ if let buildTargets {
1570
+ buildRequestTargets = try buildTargets. map { BuildRequest . BuildTargetInfo ( parameters: buildRequestParameters, target: try #require( workspace. target ( for: $0. guid) , sourceLocation: sourceLocation) ) }
1571
+ } else {
1572
+ buildRequestTargets = workspace. projects. flatMap { project in
1573
+ // The workspace description excludes packages so that we don't end up configuring every target for every
1574
+ // platform.
1575
+ if workspaceOperation && project. isPackage {
1576
+ return [ BuildRequest . BuildTargetInfo] ( )
1577
+ }
1578
+ return project. targets. compactMap { target in
1579
+ if target. type == . aggregate {
1580
+ return nil
1581
+ }
1582
+ return BuildRequest . BuildTargetInfo ( parameters: buildRequestParameters, target: target)
1583
+ }
1584
+ }
1585
+ }
1586
+
1587
+ let targetsToPrepare = try prepareTargets? . map { try #require( workspace. target ( for: $0) ) }
1588
+ return BuildRequest ( parameters: buildRequestParameters, buildTargets: buildRequestTargets, dependencyScope: . workspace, continueBuildingAfterErrors: true , useParallelTargets: true , useImplicitDependencies: true , useDryRun: false , buildCommand: . prepareForIndexing( buildOnlyTheseTargets: targetsToPrepare, enableIndexBuildArena: true ) )
1589
+
1590
+ }
1591
+
1544
1592
/// Construct 'prepare' index build operation, and test the result.
1545
- package func checkIndexBuild(
1593
+ package func checkIndexBuild< T > (
1546
1594
prepareTargets: [ String] ,
1547
- derivedDataRoot : Path ? = nil ,
1595
+ workspaceOperation : Bool = true ,
1548
1596
runDestination: RunDestinationInfo? = nil ,
1549
1597
persistent: Bool = false ,
1550
1598
sourceLocation: SourceLocation = #_sourceLocation,
1551
- body: ( BuildResults) throws -> Void
1552
- ) async throws {
1553
- let arena = ArenaInfo . indexBuildArena ( derivedDataRoot: derivedDataRoot ?? workspace. path. dirname)
1554
- let overrides : [ String : String ] = [ " ONLY_ACTIVE_ARCH " : " YES " , " ALWAYS_SEARCH_USER_PATHS " : " NO " ]
1555
- let targetsToPrepare = prepareTargets. map { workspace. target ( for: $0) ! }
1556
- // Using 'macOS' as default run-destination; run-destination does not matter for an index build description since it configures targets for all supported platforms.
1557
- let parameters = BuildParameters ( action: . indexBuild, configuration: " Debug " , activeRunDestination: . macOS, overrides: overrides, arena: arena)
1558
- let buildTargets = workspace. allTargets. compactMap { $0. type == . aggregate ? nil : BuildRequest . BuildTargetInfo ( parameters: parameters, target: $0) }
1559
- let buildRequest = BuildRequest ( parameters: parameters, buildTargets: buildTargets, dependencyScope: . workspace, continueBuildingAfterErrors: true , useParallelTargets: true , useImplicitDependencies: true , useDryRun: false , buildCommand: . prepareForIndexing( buildOnlyTheseTargets: targetsToPrepare, enableIndexBuildArena: true ) )
1560
-
1561
- // Use the provided run-destination for the build operation.
1599
+ body: ( BuildResults) throws -> T
1600
+ ) async throws -> T {
1601
+ let buildRequest = try Self . buildRequestForIndexOperation (
1602
+ workspace: workspace,
1603
+ prepareTargets: prepareTargets,
1604
+ workspaceOperation: workspaceOperation,
1605
+ runDestination: runDestination,
1606
+ sourceLocation: sourceLocation
1607
+ )
1608
+
1609
+ // The build request may have no run destination (for a workspace description), but we always build for a
1610
+ // specific target.
1562
1611
let runDestination = runDestination ?? RunDestinationInfo . macOS
1563
- let operationParameters = parameters. replacing ( activeRunDestination: runDestination, activeArchitecture: nil )
1612
+ let operationParameters = buildRequest . parameters. replacing ( activeRunDestination: runDestination, activeArchitecture: nil )
1564
1613
let operationBuildRequest = buildRequest. with ( parameters: operationParameters, buildTargets: [ ] )
1565
1614
1566
- try await checkBuild ( buildRequest: buildRequest, operationBuildRequest: operationBuildRequest, persistent: persistent, sourceLocation: sourceLocation, body: body, performBuild: { await $0. buildWithTimeout ( ) } )
1615
+ return try await checkBuild ( buildRequest: buildRequest, operationBuildRequest: operationBuildRequest, persistent: persistent, sourceLocation: sourceLocation, body: body, performBuild: { await $0. buildWithTimeout ( ) } )
1567
1616
}
1568
1617
1569
1618
package struct BuildGraphResult: Sendable {
@@ -1631,15 +1680,23 @@ package final class BuildOperationTester {
1631
1680
}
1632
1681
1633
1682
package func checkIndexBuildGraph(
1634
- targets: [ any TestTarget ] , activeRunDestination: RunDestinationInfo = . macOS,
1683
+ targets: [ any TestTarget ] ? = nil ,
1684
+ workspaceOperation: Bool? = nil ,
1685
+ activeRunDestination: RunDestinationInfo? = nil ,
1635
1686
graphTypes: [ TargetGraphFactory . GraphType] = [ . dependency] ,
1636
1687
sourceLocation: SourceLocation = #_sourceLocation,
1637
1688
body: ( BuildGraphResult) throws -> Void
1638
1689
) async throws {
1639
- // `activeRunDestination` only matters for packages, so a default of `.macOS` is fine everywhere else
1640
- let buildParameters = BuildParameters ( action: . indexBuild, configuration: " Debug " , activeRunDestination: activeRunDestination)
1641
- let buildTargets = try targets. map { BuildRequest . BuildTargetInfo ( parameters: buildParameters, target: try #require( self . workspace. target ( for: $0. guid) , sourceLocation: sourceLocation) ) }
1642
- let buildRequest = BuildRequest ( parameters: buildParameters, buildTargets: buildTargets, dependencyScope: . workspace, continueBuildingAfterErrors: true , useParallelTargets: true , useImplicitDependencies: true , useDryRun: false , buildCommand: . prepareForIndexing( buildOnlyTheseTargets: nil , enableIndexBuildArena: true ) )
1690
+ let workspaceOperation = workspaceOperation ?? ( targets == nil )
1691
+
1692
+ let buildRequest = try Self . buildRequestForIndexOperation (
1693
+ workspace: workspace,
1694
+ buildTargets: targets,
1695
+ workspaceOperation: workspaceOperation,
1696
+ runDestination: activeRunDestination,
1697
+ sourceLocation: sourceLocation
1698
+ )
1699
+
1643
1700
let buildRequestContext = BuildRequestContext ( workspaceContext: workspaceContext)
1644
1701
let delegate = EmptyTargetDependencyResolverDelegate ( workspace: workspaceContext. workspace)
1645
1702
0 commit comments