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
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,35 @@ class SWBServiceConsolePrepareForIndexCommand: SWBServiceConsoleCommand {
}
}

class SWBServiceConsoleDependencyInfoCommand: SWBServiceConsoleCommand {
public static let name = "generateDependencyInfo"

static func usage() -> String {
return name + " [options] <container-path>"
}

static func validate(invocation: SWBServiceConsoleCommandInvocation) -> SWBServiceConsoleError? {
return nil
}

static func perform(invocation: SWBServiceConsoleCommandInvocation) async -> SWBCommandResult {
return await SWBServiceConsoleBuildCommand.perform(invocation: invocation, operationFunc: generateDependencyInfo)
}
}

fileprivate func generateDependencyInfo(startInfo: SwiftBuildMessage.BuildStartedInfo, session: SWBBuildServiceSession, sessionCreationDiagnostics: [SwiftBuildMessage.DiagnosticInfo], request: SWBBuildRequest) async -> SWBCommandResult {
do {
let output = try await withTemporaryDirectory(removeTreeOnDeinit: true) {
let outputPath = $0.join("dump.json")
try await session.dumpBuildDependencyInfo(for: request, to: outputPath.str)
return try String(contentsOf: URL(fileURLWithPath: outputPath.str))
}
return .success(.init(output: output))
} catch {
return .failure(.failedCommandError(description: "\(error)"))
}
}

extension SWBWorkspaceInfo {
func configuredTargets(targetNames: [String], parameters: SWBBuildParameters) throws -> [SWBConfiguredTarget] {
return try targetNames.map { targetName in
Expand Down Expand Up @@ -499,6 +528,7 @@ func registerBuildCommands() {
SWBServiceConsoleBuildCommand.self,
SWBServiceConsolePrepareForIndexCommand.self,
SWBServiceConsoleCreateBuildDescriptionCommand.self,
SWBServiceConsoleDependencyInfoCommand.self,
] as [any SWBServiceConsoleCommand.Type]) { SWBServiceConsoleCommandRegistry.registerCommandClass(commandClass) }
}

Expand Down
12 changes: 12 additions & 0 deletions Sources/SwiftBuild/SWBBuildService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,18 @@ public final class SWBBuildService: Sendable {
}
}

public func dumpBuildDependencyInfo(session: SWBBuildServiceSession, request: SWBBuildRequest, outputPath: String) async {
let (channel, _): (UInt64, Bool) = await withCheckedContinuation { continuation in
Task {
let channel = self.openChannel { channel, message in
}

_ = await send(DumpBuildDependencyInfoRequest(sessionHandle: session.name, responseChannel: channel, request: request.messagePayloadRepresentation, outputPath: outputPath))
}
}
self.connection.close(channel: channel)
}

@available(*, deprecated, message: "Do not use.")
public func appleSystemFrameworkNames(developerPath: String?) async throws -> Set<String> {
try await Set(send(request: AppleSystemFrameworkNamesRequest(developerPath: developerPath.map(Path.init))).value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ fileprivate struct GeneralCommandsTests {
dumpMsgPack\r
dumpPID\r
exit\r
generateDependencyInfo\r
headermap\r
help\r
isAlive\r
Expand Down Expand Up @@ -141,6 +142,7 @@ fileprivate struct GeneralCommandsTests {
"dumpMsgPack",
"dumpPID",
"exit",
"generateDependencyInfo",
"headermap",
"help",
"isAlive",
Expand Down