Skip to content

Revert "Initial implementation of Command Plugins" #3886

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 6 additions & 6 deletions Sources/Build/BuildOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
let packageGraphLoader: () throws -> PackageGraph

/// The closure for invoking plugins in the package graph.
let pluginInvoker: (PackageGraph) throws -> [ResolvedTarget: [BuildToolPluginInvocationResult]]
let pluginInvoker: (PackageGraph) throws -> [ResolvedTarget: [PluginInvocationResult]]

/// The llbuild build delegate reference.
private var buildSystemDelegate: BuildOperationBuildSystemDelegateHandler?
Expand Down Expand Up @@ -70,7 +70,7 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
buildParameters: BuildParameters,
cacheBuildManifest: Bool,
packageGraphLoader: @escaping () throws -> PackageGraph,
pluginInvoker: @escaping (PackageGraph) throws -> [ResolvedTarget: [BuildToolPluginInvocationResult]],
pluginInvoker: @escaping (PackageGraph) throws -> [ResolvedTarget: [PluginInvocationResult]],
outputStream: OutputByteStream,
logLevel: Basics.Diagnostic.Severity,
fileSystem: TSCBasic.FileSystem,
Expand All @@ -92,7 +92,7 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
}
}

public func getPluginInvocationResults(for graph: PackageGraph) throws -> [ResolvedTarget: [BuildToolPluginInvocationResult]] {
public func getPluginInvocationResults(for graph: PackageGraph) throws -> [ResolvedTarget: [PluginInvocationResult]] {
return try self.pluginInvoker(graph)
}

Expand Down Expand Up @@ -295,20 +295,20 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS

/// Runs any prebuild commands associated with the given list of plugin invocation results, in order, and returns the
/// results of running those prebuild commands.
private func runPrebuildCommands(for pluginResults: [BuildToolPluginInvocationResult]) throws -> [PrebuildCommandResult] {
private func runPrebuildCommands(for pluginResults: [PluginInvocationResult]) throws -> [PrebuildCommandResult] {
// Run through all the commands from all the plugin usages in the target.
return try pluginResults.map { pluginResult in
// As we go we will collect a list of prebuild output directories whose contents should be input to the build,
// and a list of the files in those directories after running the commands.
var derivedSourceFiles: [AbsolutePath] = []
var prebuildOutputDirs: [AbsolutePath] = []
for command in pluginResult.prebuildCommands {
self.observabilityScope.emit(info: "Running" + (command.configuration.displayName ?? command.configuration.executable.basename))
self.observabilityScope.emit(info: "Running" + command.configuration.displayName)

// Run the command configuration as a subshell. This doesn't return until it is done.
// TODO: We need to also use any working directory, but that support isn't yet available on all platforms at a lower level.
// TODO: Invoke it in a sandbox that allows writing to only the temporary location.
let commandLine = [command.configuration.executable.pathString] + command.configuration.arguments
let commandLine = [command.configuration.executable] + command.configuration.arguments
let processResult = try Process.popen(arguments: commandLine, environment: command.configuration.environment)
let output = try processResult.utf8Output() + processResult.utf8stderrOutput()
if processResult.exitStatus != .terminated(code: 0) {
Expand Down
10 changes: 5 additions & 5 deletions Sources/Build/BuildPlan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ public final class SwiftTargetBuildDescription {
private(set) var moduleMap: AbsolutePath?

/// The results of applying any plugins to this target.
public let pluginInvocationResults: [BuildToolPluginInvocationResult]
public let pluginInvocationResults: [PluginInvocationResult]

/// The results of running any prebuild commands for this target.
public let prebuildCommandResults: [PrebuildCommandResult]
Expand All @@ -612,7 +612,7 @@ public final class SwiftTargetBuildDescription {
target: ResolvedTarget,
toolsVersion: ToolsVersion,
buildParameters: BuildParameters,
pluginInvocationResults: [BuildToolPluginInvocationResult] = [],
pluginInvocationResults: [PluginInvocationResult] = [],
prebuildCommandResults: [PrebuildCommandResult] = [],
isTestTarget: Bool? = nil,
testDiscoveryTarget: Bool = false,
Expand Down Expand Up @@ -1424,7 +1424,7 @@ public class BuildPlan {
}

/// The results of invoking any plugins used by targets in this build.
public let pluginInvocationResults: [ResolvedTarget: [BuildToolPluginInvocationResult]]
public let pluginInvocationResults: [ResolvedTarget: [PluginInvocationResult]]

/// The results of running any prebuild commands for the targets in this build. This includes any derived
/// source files as well as directories to which any changes should cause us to reevaluate the build plan.
Expand Down Expand Up @@ -1523,7 +1523,7 @@ public class BuildPlan {
public convenience init(
buildParameters: BuildParameters,
graph: PackageGraph,
pluginInvocationResults: [ResolvedTarget: [BuildToolPluginInvocationResult]] = [:],
pluginInvocationResults: [ResolvedTarget: [PluginInvocationResult]] = [:],
prebuildCommandResults: [ResolvedTarget: [PrebuildCommandResult]] = [:],
diagnostics: DiagnosticsEngine,
fileSystem: FileSystem
Expand All @@ -1541,7 +1541,7 @@ public class BuildPlan {
public init(
buildParameters: BuildParameters,
graph: PackageGraph,
pluginInvocationResults: [ResolvedTarget: [BuildToolPluginInvocationResult]] = [:],
pluginInvocationResults: [ResolvedTarget: [PluginInvocationResult]] = [:],
prebuildCommandResults: [ResolvedTarget: [PrebuildCommandResult]] = [:],
fileSystem: FileSystem,
observabilityScope: ObservabilityScope
Expand Down
7 changes: 3 additions & 4 deletions Sources/Build/LLBuildManifestBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -607,12 +607,11 @@ extension LLBuildManifestBuilder {
// Add any regular build commands created by plugins for the target (prebuild commands are handled separately).
for command in target.pluginInvocationResults.reduce([], { $0 + $1.buildCommands }) {
// Create a shell command to invoke the executable. We include the path of the executable as a dependency, and make sure the name is unique.
let execPath = command.configuration.executable
let execPath = AbsolutePath(command.configuration.executable, relativeTo: buildParameters.buildPath)
let uniquedName = ([execPath.pathString] + command.configuration.arguments).joined(separator: "|")
let displayName = command.configuration.displayName ?? execPath.basename
manifest.addShellCmd(
name: displayName + "-" + ByteString(encodingAsUTF8: uniquedName).sha256Checksum,
description: displayName,
name: command.configuration.displayName + "-" + ByteString(encodingAsUTF8: uniquedName).sha256Checksum,
description: command.configuration.displayName,
inputs: [.file(execPath)] + command.inputFiles.map{ .file($0) },
outputs: command.outputFiles.map{ .file($0) },
arguments: [execPath.pathString] + command.configuration.arguments,
Expand Down
44 changes: 0 additions & 44 deletions Sources/Commands/Describe.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,55 +144,11 @@ struct DescribedPackage: Encodable {
/// Represents a plugin capability for the sole purpose of generating a description.
struct DescribedPluginCapability: Encodable {
let type: String
let intent: CommandIntent?
let permissions: [Permission]?

init(from capability: PluginCapability, in package: Package) {
switch capability {
case .buildTool:
self.type = "buildTool"
self.intent = nil
self.permissions = nil
case .command(let intent, let permissions):
self.type = "command"
self.intent = .init(from: intent)
self.permissions = permissions.map{ .init(from: $0) }
}
}

struct CommandIntent: Encodable {
let type: String
let verb: String?
let description: String?

init(from intent: PackageModel.PluginCommandIntent) {
switch intent {
case .documentationGeneration:
self.type = "documentationGeneration"
self.verb = nil
self.description = nil
case .sourceCodeFormatting:
self.type = "sourceCodeFormatting"
self.verb = nil
self.description = nil
case .custom(let verb, let description):
self.type = "custom"
self.verb = verb
self.description = description
}
}
}

struct Permission: Encodable {
let type: String
let reason: String

init(from permission: PackageModel.PluginPermission) {
switch permission {
case .writeToPackageDirectory(let reason):
self.type = "writeToPackageDirectory"
self.reason = reason
}
}
}
}
Expand Down
Loading