Skip to content

Commit 3d1fc0d

Browse files
committed
WIP: Rename Extension to Plugin and separate out the use of plugins from dependencies
1 parent 6814c34 commit 3d1fc0d

File tree

34 files changed

+654
-263
lines changed

34 files changed

+654
-263
lines changed

Fixtures/Miscellaneous/Extensions/MySourceGenClient/Package.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@ import PackageDescription
44
let package = Package(
55
name: "MySourceGenClient",
66
dependencies: [
7-
.package(path: "../MySourceGenExtension")
7+
.package(path: "../MySourceGenPlugin")
88
],
99
targets: [
10-
// A tool that uses an extension.
10+
// A tool that uses an plugin.
1111
.executableTarget(
1212
name: "MyTool",
1313
dependencies: [
14-
.product(name: "MySourceGenExt", package: "MySourceGenExtension")
14+
.product(name: "MySourceGenPlugin", package: "MySourceGenPlugin")
1515
]
1616
),
17-
// A unit that uses the extension.
17+
// A unit that uses the plugin.
1818
.testTarget(
1919
name: "MyTests",
2020
dependencies: [
21-
.product(name: "MySourceGenExt", package: "MySourceGenExtension")
21+
.product(name: "MySourceGenPlugin", package: "MySourceGenPlugin")
2222
]
2323
)
2424
]

Fixtures/Miscellaneous/Extensions/MySourceGenExtension/Package.swift renamed to Fixtures/Miscellaneous/Extensions/MySourceGenPlugin/Package.swift

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,29 @@
22
import PackageDescription
33

44
let package = Package(
5-
name: "MySourceGenExtension",
5+
name: "MySourceGenPlugin",
66
products: [
7-
// The product that vends MySourceGenExt to client packages.
8-
.extension(
9-
name: "MySourceGenExt",
10-
targets: ["MySourceGenExt"]
7+
// The product that vends MySourceGenPlugin to client packages.
8+
.plugin(
9+
name: "MySourceGenPlugin",
10+
targets: ["MySourceGenPlugin"]
1111
),
1212
.executable(
1313
name: "MySourceGenTool",
1414
targets: ["MySourceGenTool"]
1515
)
1616
],
1717
targets: [
18-
// A local tool that uses an extension.
18+
// A local tool that uses a plugin.
1919
.executableTarget(
2020
name: "MyLocalTool",
21-
dependencies: [
22-
"MySourceGenExt",
21+
plugins: [
22+
"MySourceGenPlugin",
2323
]
2424
),
25-
// The target that implements the extension and generates commands to invoke MySourceGenTool.
26-
.extension(
27-
name: "MySourceGenExt",
25+
// The target that implements the plugin and generates commands to invoke MySourceGenTool.
26+
.plugin(
27+
name: "MySourceGenPlugin",
2828
capability: .buildTool(),
2929
dependencies: [
3030
"MySourceGenTool"
@@ -45,12 +45,14 @@ let package = Package(
4545
.target(
4646
name: "MySourceGenRuntimeLib"
4747
),
48-
// Unit tests for the extension.
48+
// Unit tests for the plugin.
4949
.testTarget(
50-
name: "MySourceGenExtTests",
50+
name: "MySourceGenPluginTests",
5151
dependencies: [
52-
"MySourceGenExt",
5352
"MySourceGenRuntimeLib"
53+
],
54+
plugins: [
55+
"MySourceGenPlugin",
5456
]
5557
)
5658
]

Sources/Build/BuildPlan.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ public final class SwiftTargetBuildDescription {
717717
case .library, .test:
718718
result.append("-parse-as-library")
719719

720-
case .executable, .systemModule, .binary, .extension:
720+
case .executable, .systemModule, .binary, .plugin:
721721
do { }
722722
}
723723

@@ -1133,8 +1133,8 @@ public final class ProductBuildDescription {
11331133
}
11341134
}
11351135
args += ["-emit-executable"]
1136-
case .extension:
1137-
throw InternalError("unexpectedly asked to generate linker arguments for an extension product")
1136+
case .plugin:
1137+
throw InternalError("unexpectedly asked to generate linker arguments for a plugin product")
11381138
}
11391139

11401140
// Set rpath such that dynamic libraries are looked up
@@ -1150,7 +1150,7 @@ public final class ProductBuildDescription {
11501150
// Embed the swift stdlib library path inside tests and executables on Darwin.
11511151
if containsSwiftTargets {
11521152
switch product.type {
1153-
case .library, .extension: break
1153+
case .library, .plugin: break
11541154
case .test, .executable:
11551155
if buildParameters.triple.isDarwin() {
11561156
let stdlib = buildParameters.toolchain.macosSwiftStdlib
@@ -1396,7 +1396,7 @@ public class BuildPlan {
13961396
buildParameters: buildParameters,
13971397
fileSystem: fileSystem,
13981398
diagnostics: diagnostics))
1399-
case is SystemLibraryTarget, is BinaryTarget, is ExtensionTarget:
1399+
case is SystemLibraryTarget, is BinaryTarget, is PluginTarget:
14001400
break
14011401
default:
14021402
fatalError("unhandled \(target.underlyingTarget)")
@@ -1425,7 +1425,7 @@ public class BuildPlan {
14251425
var productMap: [ResolvedProduct: ProductBuildDescription] = [:]
14261426
// Create product description for each product we have in the package graph except
14271427
// for automatic libraries and extension because they don't produce any output.
1428-
for product in graph.allProducts where product.type != .library(.automatic) && product.type != .extension {
1428+
for product in graph.allProducts where product.type != .library(.automatic) && product.type != .plugin {
14291429
productMap[product] = ProductBuildDescription(
14301430
product: product, buildParameters: buildParameters,
14311431
fs: fileSystem,
@@ -1594,7 +1594,7 @@ public class BuildPlan {
15941594
// need to statically link it or if it's an extension.
15951595
case .product(let product, _):
15961596
switch product.type {
1597-
case .library(.automatic), .library(.static), .extension:
1597+
case .library(.automatic), .library(.static), .plugin:
15981598
return product.targets.map { .target($0, conditions: []) }
15991599
case .library(.dynamic), .test, .executable:
16001600
return []
@@ -1640,7 +1640,7 @@ public class BuildPlan {
16401640
let tools = try self.parseArtifactsArchive(for: binaryTarget)
16411641
tools.forEach { availableTools[$0.name] = $0.executablePath }
16421642
}
1643-
case .extension:
1643+
case .plugin:
16441644
continue
16451645
}
16461646

Sources/Build/ManifestBuilder.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ extension LLBuildManifestBuilder {
511511
// Ignore Binary Modules.
512512
if target.underlyingTarget is BinaryTarget { return }
513513
// Ignore Extension Targets.
514-
if target.underlyingTarget is ExtensionTarget { return }
514+
if target.underlyingTarget is PluginTarget { return }
515515

516516
// Depend on the binary for executable targets.
517517
if target.type == .executable {
@@ -554,8 +554,8 @@ extension LLBuildManifestBuilder {
554554
// Establish a dependency on binary of the product.
555555
inputs.append(file: planProduct.binary)
556556

557-
// For automatic and static libraries, and extensions, add their targets as static input.
558-
case .library(.automatic), .library(.static), .extension:
557+
// For automatic and static libraries, and plugins, add their targets as static input.
558+
case .library(.automatic), .library(.static), .plugin:
559559
for target in product.targets {
560560
try addStaticTargetInputs(target)
561561
}
@@ -575,7 +575,7 @@ extension LLBuildManifestBuilder {
575575
}
576576
}
577577

578-
// Add any build tool commands created by extensions for the target (prebuild and postbuild commands are handled outside the build).
578+
// Add any build tool commands created by plugins for the target (prebuild and postbuild commands are handled outside the build).
579579
for command in target.extensionEvaluationResults.reduce([], { $0 + $1.commands }) {
580580
if case .buildToolCommand(let displayName, let executable, let arguments, _, _, let inputPaths, let outputPaths, _) = command {
581581
// Create a shell command to invoke the executable. We include the path of the executable as a dependency.
@@ -674,7 +674,7 @@ extension LLBuildManifestBuilder {
674674
let binary = planProduct.binary
675675
inputs.append(file: binary)
676676

677-
case .library(.automatic), .library(.static), .extension:
677+
case .library(.automatic), .library(.static), .plugin:
678678
for target in product.targets {
679679
addStaticTargetInputs(target)
680680
}
@@ -847,8 +847,8 @@ extension ResolvedProduct {
847847
throw InternalError("automatic library not supported")
848848
case .executable:
849849
return "\(name)-\(config).exe"
850-
case .extension:
851-
throw InternalError("unexpectedly asked for the llbuild target name of an extension product")
850+
case .plugin:
851+
throw InternalError("unexpectedly asked for the llbuild target name of a plugin product")
852852
}
853853
}
854854

Sources/Commands/Describe.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,11 @@ fileprivate struct DescribedPackage: Encodable {
132132
}
133133
}
134134

135-
/// Represents a extension capability for the sole purpose of generating a description.
136-
struct DescribedExtensionCapability: Encodable {
135+
/// Represents a plugin capability for the sole purpose of generating a description.
136+
struct DescribedPluginCapability: Encodable {
137137
let type: String
138138

139-
init(from capability: ExtensionCapability, in package: Package) {
139+
init(from capability: PluginCapability, in package: Package) {
140140
switch capability {
141141
case .prebuild:
142142
self.type = "prebuild"
@@ -154,7 +154,7 @@ fileprivate struct DescribedPackage: Encodable {
154154
let type: String
155155
let c99name: String?
156156
let moduleType: String?
157-
let extensionCapability: DescribedExtensionCapability?
157+
let pluginCapability: DescribedPluginCapability?
158158
let path: String
159159
let sources: [String]
160160
let resources: [PackageModel.Resource]?
@@ -166,7 +166,7 @@ fileprivate struct DescribedPackage: Encodable {
166166
self.type = target.type.rawValue
167167
self.c99name = target.c99name
168168
self.moduleType = String(describing: Swift.type(of: target))
169-
self.extensionCapability = (target as? ExtensionTarget).map{ DescribedExtensionCapability(from: $0.capability, in: package) }
169+
self.pluginCapability = (target as? PluginTarget).map{ DescribedPluginCapability(from: $0.capability, in: package) }
170170
self.path = target.sources.root.relative(to: package.path).pathString
171171
self.sources = target.sources.relativePaths.map{ $0.pathString }
172172
self.resources = target.resources.isEmpty ? nil : target.resources

Sources/PackageCollections/Providers/JSONPackageCollectionProvider.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ extension PackageModel.ProductType {
350350
case .executable:
351351
self = .executable
352352
case .extension:
353-
self = .extension
353+
self = .plugin
354354
case .test:
355355
self = .test
356356
}

Sources/PackageDescription/PackageDescription.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ extension SystemPackageProvider: Encodable {
592592
}
593593
}
594594

595-
extension Target.ExtensionCapability: Encodable {
595+
extension Target.PluginCapability: Encodable {
596596
private enum CodingKeys: CodingKey {
597597
case type
598598
}

Sources/PackageDescription/Product.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,13 @@ public class Product: Encodable {
128128
}
129129
}
130130

131-
/// The extension product of a Swift package.
132-
public final class Extension: Product {
133-
private enum ExtensionCodingKeys: CodingKey {
131+
/// The plugin product of a Swift package.
132+
public final class Plugin: Product {
133+
private enum PluginCodingKeys: CodingKey {
134134
case targets
135135
}
136136

137-
/// The name of the extension target to vend as a product.
137+
/// The name of the plugin target to vend as a product.
138138
public let targets: [String]
139139

140140
init(name: String, targets: [String]) {
@@ -145,9 +145,9 @@ public class Product: Encodable {
145145
public override func encode(to encoder: Encoder) throws {
146146
try super.encode(to: encoder)
147147
var productContainer = encoder.container(keyedBy: ProductCodingKeys.self)
148-
try productContainer.encode("extension", forKey: .type)
149-
var extensionContainer = encoder.container(keyedBy: ExtensionCodingKeys.self)
150-
try extensionContainer.encode(targets, forKey: .targets)
148+
try productContainer.encode("plugin", forKey: .type)
149+
var pluginContainer = encoder.container(keyedBy: PluginCodingKeys.self)
150+
try pluginContainer.encode(targets, forKey: .targets)
151151
}
152152
}
153153

@@ -185,17 +185,17 @@ public class Product: Encodable {
185185
return Executable(name: name, targets: targets)
186186
}
187187

188-
/// Creates an extension package product.
188+
/// Creates an plugin package product.
189189
///
190190
/// - Parameters:
191-
/// - name: The name of the extension product.
192-
/// - targets: The extension targets to vend as a product.
191+
/// - name: The name of the plugin product.
192+
/// - targets: The plugin targets to vend as a product.
193193
@available(_PackageDescription, introduced: 999.0)
194-
public static func `extension`(
194+
public static func plugin(
195195
name: String,
196196
targets: [String]
197197
) -> Product {
198-
return Extension(name: name, targets: targets)
198+
return Plugin(name: name, targets: targets)
199199
}
200200

201201
public func encode(to encoder: Encoder) throws {

0 commit comments

Comments
 (0)