Skip to content

Clean up remaining uses of "extension" terminology (it's now "plugin") #3329

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

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
6 changes: 3 additions & 3 deletions Sources/PackageGraph/PackageGraph+Loading.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
This source file is part of the Swift.org open source project

Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See http://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -30,7 +30,7 @@ extension PackageGraph {
diagnostics: DiagnosticsEngine,
fileSystem: FileSystem = localFileSystem,
shouldCreateMultipleTestProducts: Bool = false,
allowExtensionTargets: Bool = false,
allowPluginTargets: Bool = false,
createREPLProduct: Bool = false
) throws -> PackageGraph {

Expand Down Expand Up @@ -114,7 +114,7 @@ extension PackageGraph {
fileSystem: fileSystem,
diagnostics: diagnostics,
shouldCreateMultipleTestProducts: shouldCreateMultipleTestProducts,
allowPluginTargets: allowExtensionTargets,
allowPluginTargets: allowPluginTargets,
createREPLProduct: manifest.packageKind == .root ? createREPLProduct : false
)
let package = try builder.construct()
Expand Down
74 changes: 7 additions & 67 deletions Sources/SPMBuildCore/PluginInvocation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ extension PackageGraph {
// Evaluate each plugin in turn, creating a list of results (one for each plugin used by the target).
var evalResults: [PluginInvocationResult] = []
for pluginTarget in pluginTargets {
// Give each invocation of an extension a separate output directory.
let extOutputDir = outputDir.appending(components: package.name, target.name, pluginTarget.name)
// Give each invocation of a plugin a separate output directory.
let pluginOutputDir = outputDir.appending(components: package.name, target.name, pluginTarget.name)
do {
try fileSystem.createDirectory(extOutputDir, recursive: true)
try fileSystem.createDirectory(pluginOutputDir, recursive: true)
}
catch {
throw PluginEvaluationError.outputDirectoryCouldNotBeCreated(path: extOutputDir, underlyingError: error)
throw PluginEvaluationError.outputDirectoryCouldNotBeCreated(path: pluginOutputDir, underlyingError: error)
}

// Create the input context to pass to the plugin.
Expand All @@ -81,7 +81,7 @@ extension PackageGraph {
dependencies: dependencyTargets.map {
.init(targetName: $0.name, moduleName: $0.c99name, targetDir: $0.sources.root.pathString)
},
outputDir: extOutputDir.pathString,
outputDir: pluginOutputDir.pathString,
toolsDir: execsDir.pathString
)

Expand Down Expand Up @@ -165,24 +165,6 @@ extension PackageGraph {
return evalResultsByTarget
}

@available(*, deprecated, message: "used evaluationPlugins() instead")
public func evaluateExtensions(
buildEnvironment: BuildEnvironment,
execsDir: AbsolutePath,
outputDir: AbsolutePath,
extensionRunner: PluginScriptRunner,
diagnostics: DiagnosticsEngine,
fileSystem: FileSystem
) throws -> [ResolvedTarget: [PluginInvocationResult]] {
return try self.invokePlugins(
buildEnvironment: buildEnvironment,
execsDir: execsDir,
outputDir: outputDir,
pluginScriptRunner: extensionRunner,
diagnostics: diagnostics,
fileSystem: fileSystem)
}


/// Private helper function that serializes a PluginEvaluationInput as input JSON, calls the plugin runner to invoke the plugin, and finally deserializes the output JSON it emits to a PluginEvaluationOutput. Adds any errors or warnings to `diagnostics`, and throws an error if there was a failure.
/// FIXME: This should be asynchronous, taking a queue and a completion closure.
Expand Down Expand Up @@ -282,7 +264,6 @@ public struct PluginInvocationResult {
/// Any textual output emitted by the plugin.
public var textOutput: String
}
public typealias ExtensionEvaluationResult = PluginInvocationResult


/// An error in plugin evaluation.
Expand All @@ -291,7 +272,6 @@ public enum PluginEvaluationError: Swift.Error {
case runningPluginFailed(underlyingError: Error)
case decodingPluginOutputFailed(json: Data, underlyingError: Error)
}
public typealias ExtensionEvaluationError = PluginEvaluationError


/// Implements the mechanics of running a plugin script (implemented as a set of Swift source files) as a process.
Expand All @@ -315,50 +295,10 @@ public protocol PluginScriptRunner {
diagnostics: DiagnosticsEngine,
fileSystem: FileSystem
) throws -> (outputJSON: Data, stdoutText: Data)

@available(*, deprecated, message: "use runPluginScript() instead")
func runExtension(
sources: Sources,
inputJSON: Data,
toolsVersion: ToolsVersion,
diagnostics: DiagnosticsEngine,
fileSystem: FileSystem
) throws -> (outputJSON: Data, stdoutText: Data)
}
extension PluginScriptRunner {
public func runPluginScript(
sources: Sources,
inputJSON: Data,
toolsVersion: ToolsVersion,
diagnostics: DiagnosticsEngine,
fileSystem: FileSystem
) throws -> (outputJSON: Data, stdoutText: Data) {
return try self.runExtension(
sources: sources,
inputJSON: inputJSON,
toolsVersion: toolsVersion,
diagnostics: diagnostics,
fileSystem: fileSystem)
}
public func runExtension(
sources: Sources,
inputJSON: Data,
toolsVersion: ToolsVersion,
diagnostics: DiagnosticsEngine,
fileSystem: FileSystem
) throws -> (outputJSON: Data, stdoutText: Data) {
return try self.runPluginScript(
sources: sources,
inputJSON: inputJSON,
toolsVersion: toolsVersion,
diagnostics: diagnostics,
fileSystem: fileSystem)
}
}
public typealias ExtensionRunner = PluginScriptRunner


/// Serializable context that's passed as input to the evaluation of the extension.
/// Serializable context that's passed as input to the invocation of the plugin.
struct PluginScriptRunnerInput: Codable {
var targetName: String
var moduleName: String
Expand All @@ -378,7 +318,7 @@ struct PluginScriptRunnerInput: Codable {
}


/// Deserializable result that's received as output from the evaluation of the extension.
/// Deserializable result that's received as output from the invocation of the plugin.
struct PluginScriptRunnerOutput: Codable {
var version: Int
var diagnostics: [Diagnostic]
Expand Down
4 changes: 2 additions & 2 deletions Sources/SPMTestSupport/misc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public func loadPackageGraph(
binaryArtifacts: [BinaryArtifact] = [],
explicitProduct: String? = nil,
shouldCreateMultipleTestProducts: Bool = false,
allowExtensionTargets: Bool = false,
allowPluginTargets: Bool = false,
createREPLProduct: Bool = false
) throws -> PackageGraph {
let rootManifests = manifests.filter { $0.packageKind == .root }
Expand All @@ -243,7 +243,7 @@ public func loadPackageGraph(
diagnostics: diagnostics,
fileSystem: fs,
shouldCreateMultipleTestProducts: shouldCreateMultipleTestProducts,
allowExtensionTargets: allowExtensionTargets,
allowPluginTargets: allowPluginTargets,
createREPLProduct: createREPLProduct
)
}
4 changes: 2 additions & 2 deletions Sources/Workspace/Workspace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ extension Workspace {
createREPLProduct: Bool = false,
forceResolvedVersions: Bool = false,
diagnostics: DiagnosticsEngine,
allowExtensionTargets: Bool = false,
allowPluginTargets: Bool = false,
xcTestMinimumDeploymentTargets: [PackageModel.Platform:PlatformVersion]? = nil
) throws -> PackageGraph {

Expand Down Expand Up @@ -685,7 +685,7 @@ extension Workspace {
diagnostics: diagnostics,
fileSystem: fileSystem,
shouldCreateMultipleTestProducts: createMultipleTestProducts,
allowExtensionTargets: allowExtensionTargets,
allowPluginTargets: allowPluginTargets,
createREPLProduct: createREPLProduct
)
}
Expand Down
16 changes: 8 additions & 8 deletions Tests/SPMBuildCoreTests/PluginInvocationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import SPMTestSupport
class PluginInvocationTests: XCTestCase {

func testBasics() throws {
// Construct a canned file system and package graph with a single package and a library that uses an extension that uses a tool.
// Construct a canned file system and package graph with a single package and a library that uses a plugin that uses a tool.
let fileSystem = InMemoryFileSystem(emptyFiles:
"/Foo/Sources/Foo/source.swift",
"/Foo/Sources/Foo/SomeFile.abc",
Expand Down Expand Up @@ -62,7 +62,7 @@ class PluginInvocationTests: XCTestCase {
]
)
],
allowExtensionTargets: true
allowPluginTargets: true
)

// Check the basic integrity before running plugins.
Expand All @@ -82,9 +82,9 @@ class PluginInvocationTests: XCTestCase {
}
}

// A fake ExtensionRunner that just checks the input conditions and returns canned output.
struct MockExtensionRunner: ExtensionRunner {
func runExtension(
// A fake PluginScriptRunner that just checks the input conditions and returns canned output.
struct MockPluginScriptRunner: PluginScriptRunner {
func runPluginScript(
sources: Sources,
inputJSON: Data,
toolsVersion: ToolsVersion,
Expand Down Expand Up @@ -130,12 +130,12 @@ class PluginInvocationTests: XCTestCase {
}
}

// Construct a canned input and run plugins using our MockExtensionRunner().
// Construct a canned input and run plugins using our MockPluginScriptRunner().
let buildEnv = BuildEnvironment(platform: .macOS, configuration: .debug)
let execsDir = AbsolutePath("/Foo/.build/debug")
let outputDir = AbsolutePath("/Foo/.build")
let extRunner = MockExtensionRunner()
let results = try graph.evaluateExtensions(buildEnvironment: buildEnv, execsDir: execsDir, outputDir: outputDir, extensionRunner: extRunner, diagnostics: diagnostics, fileSystem: fileSystem)
let pluginRunner = MockPluginScriptRunner()
let results = try graph.invokePlugins(buildEnvironment: buildEnv, execsDir: execsDir, outputDir: outputDir, pluginScriptRunner: pluginRunner, diagnostics: diagnostics, fileSystem: fileSystem)

// Check the canned output to make sure nothing was lost in transport.
XCTAssertNoDiagnostics(diagnostics)
Expand Down