Skip to content

Commit d212230

Browse files
committed
Provide deprecation messages for PackagePlugin.Path
As `PackagePlugin.Path` was deprecated in favor of `PackagePlugin.URL`, we should provide explicit deprecation messages that redirect plugin authors to the recommended use of the `URL` type.
1 parent 2eb73b9 commit d212230

File tree

5 files changed

+201
-184
lines changed

5 files changed

+201
-184
lines changed

Sources/PackagePlugin/Command.swift

+20-22
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift open source project
44
//
5-
// Copyright (c) 2021-2022 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2021-2024 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See http://swift.org/LICENSE.txt for license information
@@ -16,7 +16,6 @@ import Foundation
1616
/// environment variables, initial working directory, etc. All paths should be
1717
/// based on the ones passed to the plugin in the target build context.
1818
public enum Command {
19-
2019
/// Returns a command that runs when any of its output files are needed by
2120
/// the build, but out-of-date.
2221
///
@@ -86,8 +85,7 @@ public enum Command {
8685
)
8786
}
8887

89-
public extension Command {
90-
88+
extension Command {
9189
/// Returns a command that runs when any of its output files are needed by
9290
/// the build, but out-of-date.
9391
///
@@ -114,20 +112,20 @@ public extension Command {
114112
/// was generated as if in its source directory; other files are treated
115113
/// as resources as if explicitly listed in `Package.swift` using
116114
/// `.process(...)`.
117-
@available(_PackageDescription, deprecated: 6.0)
118-
static func buildCommand(
115+
@available(_PackageDescription, deprecated: 6.0, message: "Use `URL` type instead of `Path`.")
116+
public static func buildCommand(
119117
displayName: String?,
120118
executable: Path,
121119
arguments: [CustomStringConvertible],
122120
environment: [String: CustomStringConvertible] = [:],
123121
inputFiles: [Path] = [],
124122
outputFiles: [Path] = []
125123
) -> Command {
126-
return buildCommand(
124+
self.buildCommand(
127125
displayName: displayName,
128126
executable: URL(fileURLWithPath: executable.stringValue),
129-
arguments: arguments.map{ $0.description },
130-
environment: environment.mapValues{ $0.description },
127+
arguments: arguments.map(\.description),
128+
environment: environment.mapValues { $0.description },
131129
inputFiles: inputFiles.map { URL(fileURLWithPath: $0.stringValue) },
132130
outputFiles: outputFiles.map { URL(fileURLWithPath: $0.stringValue) }
133131
)
@@ -160,7 +158,7 @@ public extension Command {
160158
/// as resources as if explicitly listed in `Package.swift` using
161159
/// `.process(...)`.
162160
@available(*, unavailable, message: "specifying the initial working directory for a command is not yet supported")
163-
static func buildCommand(
161+
public static func buildCommand(
164162
displayName: String?,
165163
executable: Path,
166164
arguments: [CustomStringConvertible],
@@ -169,11 +167,11 @@ public extension Command {
169167
inputFiles: [Path] = [],
170168
outputFiles: [Path] = []
171169
) -> Command {
172-
return buildCommand(
170+
self.buildCommand(
173171
displayName: displayName,
174172
executable: URL(fileURLWithPath: executable.stringValue),
175-
arguments: arguments.map{ $0.description },
176-
environment: environment.mapValues{ $0.description },
173+
arguments: arguments.map(\.description),
174+
environment: environment.mapValues { $0.description },
177175
inputFiles: inputFiles.map { URL(fileURLWithPath: $0.stringValue) },
178176
outputFiles: outputFiles.map { URL(fileURLWithPath: $0.stringValue) }
179177
)
@@ -204,19 +202,19 @@ public extension Command {
204202
/// this command was generated as if in its source directory; other
205203
/// files are treated as resources as if explicitly listed in
206204
/// `Package.swift` using `.process(...)`.
207-
@available(_PackageDescription, deprecated: 6.0)
208-
static func prebuildCommand(
205+
@available(_PackageDescription, deprecated: 6.0, message: "Use `URL` type instead of `Path`.")
206+
public static func prebuildCommand(
209207
displayName: String?,
210208
executable: Path,
211209
arguments: [CustomStringConvertible],
212210
environment: [String: CustomStringConvertible] = [:],
213211
outputFilesDirectory: Path
214212
) -> Command {
215-
return prebuildCommand(
213+
self.prebuildCommand(
216214
displayName: displayName,
217215
executable: URL(fileURLWithPath: executable.stringValue),
218-
arguments: arguments.map{ $0.description },
219-
environment: environment.mapValues{ $0.description },
216+
arguments: arguments.map(\.description),
217+
environment: environment.mapValues { $0.description },
220218
outputFilesDirectory: URL(fileURLWithPath: outputFilesDirectory.stringValue)
221219
)
222220
}
@@ -247,19 +245,19 @@ public extension Command {
247245
/// files are treated as resources as if explicitly listed in
248246
/// `Package.swift` using `.process(...)`.
249247
@available(*, unavailable, message: "specifying the initial working directory for a command is not yet supported")
250-
static func prebuildCommand(
248+
public static func prebuildCommand(
251249
displayName: String?,
252250
executable: Path,
253251
arguments: [CustomStringConvertible],
254252
environment: [String: CustomStringConvertible] = [:],
255253
workingDirectory: Path? = .none,
256254
outputFilesDirectory: Path
257255
) -> Command {
258-
return prebuildCommand(
256+
self.prebuildCommand(
259257
displayName: displayName,
260258
executable: URL(fileURLWithPath: executable.stringValue),
261-
arguments: arguments.map{ $0.description },
262-
environment: environment.mapValues{ $0.description },
259+
arguments: arguments.map(\.description),
260+
environment: environment.mapValues { $0.description },
263261
outputFilesDirectory: URL(fileURLWithPath: outputFilesDirectory.stringValue)
264262
)
265263
}

Sources/PackagePlugin/Context.swift

+7-7
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public struct PluginContext {
3131
/// write its outputs to that directory. The plugin may also create other
3232
/// directories for cache files and other file system content that either
3333
/// it or the command will need.
34-
@available(_PackageDescription, deprecated: 6.0)
34+
@available(_PackageDescription, deprecated: 6.0, renamed: "pluginWorkDirectory")
3535
public let pluginWorkDirectory: Path
3636

3737
/// The path of a writable directory into which the plugin or the build
@@ -65,12 +65,12 @@ public struct PluginContext {
6565
}
6666
return Tool(name: name, path: Path(url: tool.path), url: tool.path)
6767
} else {
68-
for dir in toolSearchDirectoryURLs {
69-
#if os(Windows)
68+
for dir in self.toolSearchDirectoryURLs {
69+
#if os(Windows)
7070
let hostExecutableSuffix = ".exe"
71-
#else
71+
#else
7272
let hostExecutableSuffix = ""
73-
#endif
73+
#endif
7474
let path = dir.appendingPathComponent(name + hostExecutableSuffix)
7575
if FileManager.default.isExecutableFile(atPath: path.path) {
7676
return Tool(name: name, path: Path(url: path), url: path)
@@ -86,7 +86,7 @@ public struct PluginContext {
8686

8787
/// The paths of directories of in which to search for tools that aren't in
8888
/// the `toolNamesToPaths` map.
89-
@available(_PackageDescription, deprecated: 6.0)
89+
@available(_PackageDescription, deprecated: 6.0, renamed: "toolSearchDirectoryURLs")
9090
let toolSearchDirectories: [Path]
9191

9292
/// The paths of directories of in which to search for tools that aren't in
@@ -100,7 +100,7 @@ public struct PluginContext {
100100
public let name: String
101101

102102
/// Full path of the built or provided tool in the file system.
103-
@available(_PackageDescription, deprecated: 6.0)
103+
@available(_PackageDescription, deprecated: 6.0, renamed: "url")
104104
public let path: Path
105105

106106
/// Full path of the built or provided tool in the file system.

0 commit comments

Comments
 (0)