DefaultPluginScriptRunner
A plugin script runner that compiles the plugin source files as an executable binary for the host platform, and invokes it as a subprocess.
struct DefaultPluginScriptRunner
A plugin script runner that compiles the plugin source files as an executable binary for the host platform, and invokes it as a subprocess.
struct DefaultPluginScriptRunner
import Workspace
protocol Cancellable
protocol PluginScriptRunner
Implements the mechanics of running and communicating with a plugin (implemented as a set of Swift source files). In most environments this is done by compiling the code to an executable, invoking it as a sandboxed subprocess, and communicating with it using pipes. Specific implementations are free to implement things differently, however.
init(fileSystem: Basics.FileSystem, cacheDir: Basics.AbsolutePath, toolchain: UserToolchain, extraPluginSwiftCFlags: [String] = [], enableSandbox: Bool = true, verboseOutput: Bool = false)
var hostTriple: Triple { get }
func cancel(deadline: DispatchTime) throws
func compilePluginScript(sourceFiles: [Basics.AbsolutePath], pluginName: String, toolsVersion: ToolsVersion, observabilityScope: ObservabilityScope, callbackQueue: DispatchQueue, delegate: PluginScriptCompilerDelegate, completion: @escaping (Result<PluginCompilationResult, Error>) -> Void)
Starts compiling a plugin script asynchronously and when done, calls the completion handler on the callback queue with the results (including the path of the compiled plugin executable and with any emitted diagnostics, etc). Existing compilation results that are still valid are reused, if possible. This function itself returns immediately after starting the compile. Note that the completion handler only receives a .failure
result if the compiler couldn’t be invoked at all; a non-zero exit code from the compiler still returns .success
with a full compilation result that notes the error in the diagnostics (in other words, a .failure
result only means “failure to invoke the compiler”).
func runPluginScript(sourceFiles: [Basics.AbsolutePath], pluginName: String, initialMessage: Data, toolsVersion: ToolsVersion, workingDirectory: Basics.AbsolutePath, writableDirectories: [Basics.AbsolutePath], readOnlyDirectories: [Basics.AbsolutePath], allowNetworkConnections: [SandboxNetworkPermission], fileSystem: FileSystem, observabilityScope: ObservabilityScope, callbackQueue: DispatchQueue, delegate: PluginScriptCompilerDelegate & PluginScriptRunnerDelegate, completion: @escaping (Result<Int32, Error>) -> Void)
Starts evaluating a plugin by compiling it and running it as a subprocess. The name is used as the basename for the executable and auxiliary files. The tools version controls the availability of APIs in PackagePlugin, and should be set to the tools version of the package that defines the plugin (not the package containing the target to which it is being applied). This function returns immediately and then repeated calls the output handler on the given callback queue as plain-text output is received from the plugin, and then eventually calls the completion handler on the given callback queue once the plugin is done.
func compilePluginScript(sourceFiles: [AbsolutePath], pluginName: String, toolsVersion: ToolsVersion, observabilityScope: ObservabilityScope, callbackQueue: DispatchQueue, delegate: PluginScriptCompilerDelegate) async throws -> PluginCompilationResult