@@ -57,6 +57,7 @@ class SWBServiceConsoleBuildCommand: SWBServiceConsoleCommand {
5757 var buildRequestFile : Path ? = nil
5858 var buildParametersFile : Path ? = nil
5959 var derivedDataPath : Path ? = nil
60+ var buildAllTargets : Bool = false
6061
6162 var iterator = invocation. commandLine. makeIterator ( )
6263 _ = iterator. next ( )
@@ -69,6 +70,9 @@ class SWBServiceConsoleBuildCommand: SWBServiceConsoleCommand {
6970
7071 actionName = name
7172
73+ case " --allTargets " :
74+ buildAllTargets = true
75+
7276 case " --target " :
7377 guard let name = iterator. next ( ) else {
7478 return . failure( . invalidCommandError( description: " error: missing argument for \( arg) " ) )
@@ -120,6 +124,10 @@ class SWBServiceConsoleBuildCommand: SWBServiceConsoleCommand {
120124
121125 let containerPath = Path ( positionalArgs [ 0 ] )
122126
127+ if !configuredTargetNames. isEmpty, buildAllTargets {
128+ return . failure( . invalidCommandError( description: " error: pass either --allTargets or --target " ) )
129+ }
130+
123131 return await invocation. console. service. withSession ( sessionName: containerPath. str) { session, diagnostics in
124132 let baseDirectory : AbsolutePath
125133 do {
@@ -165,7 +173,7 @@ class SWBServiceConsoleBuildCommand: SWBServiceConsoleCommand {
165173 let configuredTargets : [ SWBConfiguredTarget ]
166174 do {
167175 let workspaceInfo = try await session. workspaceInfo ( )
168- configuredTargets = try workspaceInfo. configuredTargets ( targetNames: configuredTargetNames, parameters: parameters)
176+ configuredTargets = try workspaceInfo. configuredTargets ( targetNames: configuredTargetNames, parameters: parameters, buildAllTargets : buildAllTargets )
169177 } catch {
170178 return . failure( . failedCommandError( description: error. localizedDescription) )
171179 }
@@ -303,11 +311,11 @@ class SWBServiceConsolePrepareForIndexCommand: SWBServiceConsoleCommand {
303311 var prepareTargets : [ String ] ?
304312 do {
305313 let workspaceInfo = try await session. workspaceInfo ( )
306- configuredTargets = try workspaceInfo. configuredTargets ( targetNames: configuredTargetNames, parameters: parameters)
314+ configuredTargets = try workspaceInfo. configuredTargets ( targetNames: configuredTargetNames, parameters: parameters, buildAllTargets : false )
307315
308316 if !prepareTargetNames. isEmpty {
309317 do {
310- prepareTargets = try workspaceInfo. configuredTargets ( targetNames: configuredTargetNames, parameters: parameters) . map ( \. guid)
318+ prepareTargets = try workspaceInfo. configuredTargets ( targetNames: configuredTargetNames, parameters: parameters, buildAllTargets : false ) . map ( \. guid)
311319 } catch {
312320 return . failure( . failedCommandError( description: error. localizedDescription) )
313321 }
@@ -375,7 +383,17 @@ fileprivate func generateDependencyInfo(startInfo: SwiftBuildMessage.BuildStarte
375383}
376384
377385extension SWBWorkspaceInfo {
378- func configuredTargets( targetNames: [ String ] , parameters: SWBBuildParameters ) throws -> [ SWBConfiguredTarget ] {
386+ func configuredTargets( targetNames: [ String ] , parameters: SWBBuildParameters , buildAllTargets: Bool ) throws -> [ SWBConfiguredTarget ] {
387+ if buildAllTargets {
388+ // Filter all dynamic targets to avoid building the same content multiple times.
389+ let dynamicTargetVariantGuids = targetInfos. compactMap { $0. dynamicTargetVariantGuid }
390+ let targets = targetInfos. filter {
391+ !dynamicTargetVariantGuids. contains ( $0. guid)
392+ } . map {
393+ SWBConfiguredTarget ( guid: $0. guid, parameters: parameters)
394+ }
395+ return targets
396+ }
379397 return try targetNames. map { targetName in
380398 let infos = targetInfos. filter { $0. targetName == targetName }
381399 switch infos. count {
0 commit comments