Skip to content

Commit dc8c3d4

Browse files
authored
Mark package plugins as being available in 5.5 (albeit with the preliminary API) so that package manifests don't need to set 5.6 just in order to include plugins (#3738)
1 parent ac5d561 commit dc8c3d4

File tree

10 files changed

+47
-47
lines changed

10 files changed

+47
-47
lines changed

Diff for: Fixtures/Miscellaneous/Plugins/ContrivedTestPlugin/Package.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version: 5.6
1+
// swift-tools-version: 5.5
22
import PackageDescription
33

44
let package = Package(

Diff for: Fixtures/Miscellaneous/Plugins/MyBinaryToolPlugin/Package.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version: 5.6
1+
// swift-tools-version: 5.5
22
import PackageDescription
33

44
let package = Package(

Diff for: Fixtures/Miscellaneous/Plugins/MySourceGenClient/Package.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version: 5.6
1+
// swift-tools-version: 5.5
22
import PackageDescription
33

44
let package = Package(

Diff for: Fixtures/Miscellaneous/Plugins/MySourceGenPlugin/Package.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version: 5.6
1+
// swift-tools-version: 5.5
22
import PackageDescription
33

44
let package = Package(

Diff for: Fixtures/Miscellaneous/Plugins/SandboxTesterPlugin/Package.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version: 5.6
1+
// swift-tools-version: 5.5
22
import PackageDescription
33

44
let package = Package(

Diff for: Sources/PackageDescription/Product.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public class Product: Encodable {
190190
/// - Parameters:
191191
/// - name: The name of the plugin product.
192192
/// - targets: The plugin targets to vend as a product.
193-
@available(_PackageDescription, introduced: 5.6)
193+
@available(_PackageDescription, introduced: 5.5)
194194
public static func plugin(
195195
name: String,
196196
targets: [String]

Diff for: Sources/PackageDescription/Target.swift

+12-12
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public final class Target {
119119
public let providers: [SystemPackageProvider]?
120120

121121
/// The capability provided by a package plugin target.
122-
@available(_PackageDescription, introduced: 5.6)
122+
@available(_PackageDescription, introduced: 5.5)
123123
public var pluginCapability: PluginCapability? {
124124
get { return _pluginCapability }
125125
set { _pluginCapability = newValue }
@@ -174,7 +174,7 @@ public final class Target {
174174
private var _checksum: String?
175175

176176
/// The usages of package plugins by the target.
177-
@available(_PackageDescription, introduced: 5.6)
177+
@available(_PackageDescription, introduced: 5.5)
178178
public var plugins: [PluginUsage]? {
179179
get { return _pluginUsages }
180180
set { _pluginUsages = newValue }
@@ -394,7 +394,7 @@ public final class Target {
394394
/// - cxxSettings: The C++ settings for this target.
395395
/// - swiftSettings: The Swift settings for this target.
396396
/// - linkerSettings: The linker settings for this target.
397-
@available(_PackageDescription, introduced: 5.3, obsoleted: 5.6)
397+
@available(_PackageDescription, introduced: 5.3, obsoleted: 5.5)
398398
public static func target(
399399
name: String,
400400
dependencies: [Dependency] = [],
@@ -448,7 +448,7 @@ public final class Target {
448448
/// - swiftSettings: The Swift settings for this target.
449449
/// - linkerSettings: The linker settings for this target.
450450
/// - plugins: The plugins used by this target.
451-
@available(_PackageDescription, introduced: 5.6)
451+
@available(_PackageDescription, introduced: 5.5)
452452
public static func target(
453453
name: String,
454454
dependencies: [Dependency] = [],
@@ -504,7 +504,7 @@ public final class Target {
504504
/// - cxxSettings: The C++ settings for this target.
505505
/// - swiftSettings: The Swift settings for this target.
506506
/// - linkerSettings: The linker settings for this target.
507-
@available(_PackageDescription, introduced: 5.4, obsoleted: 5.6)
507+
@available(_PackageDescription, introduced: 5.4, obsoleted: 5.5)
508508
public static func executableTarget(
509509
name: String,
510510
dependencies: [Dependency] = [],
@@ -559,7 +559,7 @@ public final class Target {
559559
/// - swiftSettings: The Swift settings for this target.
560560
/// - linkerSettings: The linker settings for this target.
561561
/// - plugins: The plugins used by this target.
562-
@available(_PackageDescription, introduced: 5.6)
562+
@available(_PackageDescription, introduced: 5.5)
563563
public static func executableTarget(
564564
name: String,
565565
dependencies: [Dependency] = [],
@@ -694,7 +694,7 @@ public final class Target {
694694
/// - cxxSettings: The C++ settings for this target.
695695
/// - swiftSettings: The Swift settings for this target.
696696
/// - linkerSettings: The linker settings for this target.
697-
@available(_PackageDescription, introduced: 5.3, obsoleted: 5.6)
697+
@available(_PackageDescription, introduced: 5.3, obsoleted: 5.5)
698698
public static func testTarget(
699699
name: String,
700700
dependencies: [Dependency] = [],
@@ -745,7 +745,7 @@ public final class Target {
745745
/// - swiftSettings: The Swift settings for this target.
746746
/// - linkerSettings: The linker settings for this target.
747747
/// - plugins: The plugins used by this target.
748-
@available(_PackageDescription, introduced: 5.6)
748+
@available(_PackageDescription, introduced: 5.5)
749749
public static func testTarget(
750750
name: String,
751751
dependencies: [Dependency] = [],
@@ -896,7 +896,7 @@ public final class Target {
896896
/// on executables as well as binary targets. This is because of limitations
897897
/// in how SwiftPM constructs its build plan, and the goal is to remove this
898898
/// restriction in a future release.
899-
@available(_PackageDescription, introduced: 5.6)
899+
@available(_PackageDescription, introduced: 5.5)
900900
public static func plugin(
901901
name: String,
902902
capability: PluginCapability,
@@ -1006,7 +1006,7 @@ extension Target.PluginCapability {
10061006
/// Specifies that the plugin provides a build tool capability. The plugin
10071007
/// will be applied to each target that uses it and should create commands
10081008
/// that will run before or during the build of the target.
1009-
@available(_PackageDescription, introduced: 5.6)
1009+
@available(_PackageDescription, introduced: 5.5)
10101010
public static func buildTool() -> Target.PluginCapability {
10111011
return ._buildTool
10121012
}
@@ -1017,7 +1017,7 @@ extension Target.PluginUsage {
10171017
///
10181018
/// - parameters:
10191019
/// - name: The name of the plugin target.
1020-
@available(_PackageDescription, introduced: 5.6)
1020+
@available(_PackageDescription, introduced: 5.5)
10211021
public static func plugin(name: String) -> Target.PluginUsage {
10221022
return ._pluginItem(name: name, package: nil)
10231023
}
@@ -1027,7 +1027,7 @@ extension Target.PluginUsage {
10271027
/// - parameters:
10281028
/// - name: The name of the plugin product.
10291029
/// - package: The name of the package in which it is defined.
1030-
@available(_PackageDescription, introduced: 5.6)
1030+
@available(_PackageDescription, introduced: 5.5)
10311031
public static func plugin(name: String, package: String) -> Target.PluginUsage {
10321032
return ._pluginItem(name: name, package: package)
10331033
}

Diff for: Tests/PackageLoadingTests/PD_5_4_LoadingTests.swift

+28
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,32 @@ class PackageDescription5_4LoadingTests: PackageDescriptionLoadingTests {
3939
XCTAssertEqual(manifest.targets[0].type, .executable)
4040
}
4141
}
42+
43+
func testPluginsAreUnavailable() throws {
44+
let stream = BufferedOutputByteStream()
45+
stream <<< """
46+
import PackageDescription
47+
let package = Package(
48+
name: "Foo",
49+
targets: [
50+
.plugin(
51+
name: "Foo",
52+
capability: .buildTool()
53+
),
54+
]
55+
)
56+
"""
57+
do {
58+
try loadManifestThrowing(stream.bytes) { _ in }
59+
XCTFail("expected manifest loading to fail, but it succeeded")
60+
}
61+
catch {
62+
guard case let ManifestParseError.invalidManifestFormat(message, _) = error else {
63+
return XCTFail("expected an invalidManifestFormat error, but got: \(error)")
64+
}
65+
66+
XCTAssertMatch(message, .contains("is unavailable"))
67+
XCTAssertMatch(message, .contains("was introduced in PackageDescription 5.5"))
68+
}
69+
}
4270
}

Diff for: Tests/PackageLoadingTests/PD_5_5_LoadingTests.swift

-28
Original file line numberDiff line numberDiff line change
@@ -64,32 +64,4 @@ class PackageDescription5_5LoadingTests: PackageDescriptionLoadingTests {
6464
])
6565
}
6666
}
67-
68-
func testPluginsAreUnavailable() throws {
69-
let stream = BufferedOutputByteStream()
70-
stream <<< """
71-
import PackageDescription
72-
let package = Package(
73-
name: "Foo",
74-
targets: [
75-
.plugin(
76-
name: "Foo",
77-
capability: .buildTool()
78-
),
79-
]
80-
)
81-
"""
82-
do {
83-
try loadManifestThrowing(stream.bytes) { _ in }
84-
XCTFail("expected manifest loading to fail, but it succeeded")
85-
}
86-
catch {
87-
guard case let ManifestParseError.invalidManifestFormat(message, _) = error else {
88-
return XCTFail("expected an invalidManifestFormat error, but got: \(error)")
89-
}
90-
91-
XCTAssertMatch(message, .contains("is unavailable"))
92-
XCTAssertMatch(message, .contains("was introduced in PackageDescription 5.6"))
93-
}
94-
}
9567
}

Diff for: Tests/WorkspaceTests/ManifestSourceGenerationTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,6 @@ class ManifestSourceGenerationTests: XCTestCase {
282282
]
283283
)
284284
"""
285-
try testManifestWritingRoundTrip(manifestContents: manifestContents, toolsVersion: .v5_6)
285+
try testManifestWritingRoundTrip(manifestContents: manifestContents, toolsVersion: .v5_5)
286286
}
287287
}

0 commit comments

Comments
 (0)