Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/SWBBuildService/Messages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ private struct WorkspaceInfoMsg: MessageHandler {

return WorkspaceInfoResponse(sessionHandle: session.UID, workspaceInfo: .init(targetInfos: workspaceContext.workspace.projects.flatMap { project in
return project.targets.map { target in
return .init(guid: target.guid, targetName: target.name, projectName: project.name)
return .init(guid: target.guid, targetName: target.name, projectName: project.name, dynamicTargetVariantGuid: target.dynamicTargetVariantGuid)
}
}))
}
Expand Down
4 changes: 3 additions & 1 deletion Sources/SWBProtocol/Message.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1049,11 +1049,13 @@ public struct WorkspaceInfoResponse: Message, Equatable {
public let guid: String
public let targetName: String
public let projectName: String
public let dynamicTargetVariantGuid: String?

public init(guid: String, targetName: String, projectName: String) {
public init(guid: String, targetName: String, projectName: String, dynamicTargetVariantGuid: String?) {
self.guid = guid
self.targetName = targetName
self.projectName = projectName
self.dynamicTargetVariantGuid = dynamicTargetVariantGuid
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class SWBServiceConsoleBuildCommand: SWBServiceConsoleCommand {
var buildRequestFile: Path? = nil
var buildParametersFile: Path? = nil
var derivedDataPath: Path? = nil
var buildAllTargets: Bool = false

var iterator = invocation.commandLine.makeIterator()
_ = iterator.next()
Expand All @@ -69,6 +70,9 @@ class SWBServiceConsoleBuildCommand: SWBServiceConsoleCommand {

actionName = name

case "--allTargets":
buildAllTargets = true

case "--target":
guard let name = iterator.next() else {
return .failure(.invalidCommandError(description: "error: missing argument for \(arg)"))
Expand Down Expand Up @@ -120,6 +124,10 @@ class SWBServiceConsoleBuildCommand: SWBServiceConsoleCommand {

let containerPath = Path(positionalArgs[0])

if !configuredTargetNames.isEmpty, buildAllTargets {
return .failure(.invalidCommandError(description: "error: pass either --allTargets or --target"))
}

return await invocation.console.service.withSession(sessionName: containerPath.str) { session, diagnostics in
let baseDirectory: AbsolutePath
do {
Expand Down Expand Up @@ -165,7 +173,7 @@ class SWBServiceConsoleBuildCommand: SWBServiceConsoleCommand {
let configuredTargets: [SWBConfiguredTarget]
do {
let workspaceInfo = try await session.workspaceInfo()
configuredTargets = try workspaceInfo.configuredTargets(targetNames: configuredTargetNames, parameters: parameters)
configuredTargets = try workspaceInfo.configuredTargets(targetNames: configuredTargetNames, parameters: parameters, buildAllTargets: buildAllTargets)
} catch {
return .failure(.failedCommandError(description: error.localizedDescription))
}
Expand Down Expand Up @@ -303,11 +311,11 @@ class SWBServiceConsolePrepareForIndexCommand: SWBServiceConsoleCommand {
var prepareTargets: [String]?
do {
let workspaceInfo = try await session.workspaceInfo()
configuredTargets = try workspaceInfo.configuredTargets(targetNames: configuredTargetNames, parameters: parameters)
configuredTargets = try workspaceInfo.configuredTargets(targetNames: configuredTargetNames, parameters: parameters, buildAllTargets: false)

if !prepareTargetNames.isEmpty {
do {
prepareTargets = try workspaceInfo.configuredTargets(targetNames: configuredTargetNames, parameters: parameters).map(\.guid)
prepareTargets = try workspaceInfo.configuredTargets(targetNames: configuredTargetNames, parameters: parameters, buildAllTargets: false).map(\.guid)
} catch {
return .failure(.failedCommandError(description: error.localizedDescription))
}
Expand Down Expand Up @@ -375,7 +383,17 @@ fileprivate func generateDependencyInfo(startInfo: SwiftBuildMessage.BuildStarte
}

extension SWBWorkspaceInfo {
func configuredTargets(targetNames: [String], parameters: SWBBuildParameters) throws -> [SWBConfiguredTarget] {
func configuredTargets(targetNames: [String], parameters: SWBBuildParameters, buildAllTargets: Bool) throws -> [SWBConfiguredTarget] {
if buildAllTargets {
// Filter all dynamic targets to avoid building the same content multiple times.
let dynamicTargetVariantGuids = targetInfos.compactMap { $0.dynamicTargetVariantGuid }
let targets = targetInfos.filter {
!dynamicTargetVariantGuids.contains($0.guid)
}.map {
SWBConfiguredTarget(guid: $0.guid, parameters: parameters)
}
return targets
}
return try targetNames.map { targetName in
let infos = targetInfos.filter { $0.targetName == targetName }
switch infos.count {
Expand Down
3 changes: 2 additions & 1 deletion Sources/SwiftBuild/SWBWorkspaceInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ public struct SWBTargetInfo: Sendable {
public let guid: String
public let targetName: String
public let projectName: String
public let dynamicTargetVariantGuid: String?
}

extension SWBWorkspaceInfo {
init(_ workspaceInfo: WorkspaceInfoResponse.WorkspaceInfo) {
self = .init(targetInfos: workspaceInfo.targetInfos.map { .init(guid: $0.guid, targetName: $0.targetName, projectName: $0.projectName) })
self = .init(targetInfos: workspaceInfo.targetInfos.map { .init(guid: $0.guid, targetName: $0.targetName, projectName: $0.projectName, dynamicTargetVariantGuid: $0.dynamicTargetVariantGuid) })
}
}
2 changes: 1 addition & 1 deletion Tests/SWBProtocolTests/MessageSerializationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ import Testing
assertMsgPackMessageRoundTrip(AuditSessionPIFRequest(sessionHandle: "theSession", pifContents: [4, 7, 9, 13]))
assertMsgPackMessageRoundTrip(IncrementalPIFLookupFailureRequest(sessionHandle: "theSession", diagnostic: "everything went wrong"))
assertMsgPackMessageRoundTrip(WorkspaceInfoRequest(sessionHandle: "theSession"))
assertMsgPackMessageRoundTrip(WorkspaceInfoResponse(sessionHandle: "theSession", workspaceInfo: .init(targetInfos: [.init(guid: "theGuid", targetName: "aTarget", projectName: "aProject")])))
assertMsgPackMessageRoundTrip(WorkspaceInfoResponse(sessionHandle: "theSession", workspaceInfo: .init(targetInfos: [.init(guid: "theGuid", targetName: "aTarget", projectName: "aProject", dynamicTargetVariantGuid: nil)])))

assertMsgPackMessageRoundTrip(ErrorResponse("everything went wrong"))
assertMsgPackMessageRoundTrip(BoolResponse(true))
Expand Down
Loading