Skip to content

Commit ea18f28

Browse files
heckjbripeticca
andauthored
Docs/package plugin api docs (#8901)
Creates a documentation catalog and edits the content to provide public documentation for the Package Plugin API resolves #8827 ### Motivation: The Package Plugin API is required when creating swift package manager plugins, but doesn't have publicly hosted documentation today. This resolves that by creating the documentation catalog, adding curation (organization), and editing the documentation content to match. ### Modifications: - creates a documentation catalog - provides curation (extension) DocC pages to provide organization to the module and to each of the public types in the module - edits to the documentation comments to align stylistically with DocC conventions. ### Result: The potential to build a documentation archive for the Package Plugin API. Preview the contents of this PR using the command: ``` swift package --disable-sandbox preview-documentation --target PackagePlugin ``` --------- Co-authored-by: Bri Peticca <bripeticca@gmail.com>
1 parent a5a1da5 commit ea18f28

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1180
-308
lines changed

Sources/PackagePlugin/ArgumentExtractor.swift

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,29 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
/// A rudimentary helper for extracting options and flags from a string list representing command line arguments. The idea is to extract all known options and flags, leaving just the positional arguments. This does not handle well the case in which positional arguments (or option argument values) happen to have the same name as an option or a flag. It only handles the long `--<name>` form of options, but it does respect `--` as an indication that all remaining arguments are positional.
13+
/// A rudimentary helper for extracting options and flags from a list of strings that represent command line arguments.
14+
///
15+
/// Create the extractor with the full command line arguments provided, then extract all known
16+
/// options and flags, which leaves the positional arguments.
17+
///
18+
/// This does not handle the case where positional arguments (or optional argument values) have the same
19+
/// name as an option or a flag. It only handles the long form of options, not short forms, for example: `--<name>`, not `-n`.
20+
/// It respects an argument that consists of two hyphens (`--`) as an indication that all remaining arguments are positional.
1421
public struct ArgumentExtractor {
1522
private var args: [String]
1623
private let literals: [String]
1724

18-
/// Initializes a ArgumentExtractor with a list of strings from which to extract flags and options. If the list contains `--`, any arguments that follow it are considered to be literals.
25+
/// Creates an argument extractor with a list of strings from which to extract flags and options.
26+
///
27+
/// If the list contains `--`, any arguments that follow it are considered positional arguments.
1928
public init(_ arguments: [String]) {
2029
// Split the array on the first `--`, if there is one. Everything after that is a literal.
2130
let parts = arguments.split(separator: "--", maxSplits: 1, omittingEmptySubsequences: false)
2231
self.args = Array(parts[0])
2332
self.literals = Array(parts.count == 2 ? parts[1] : [])
2433
}
2534

26-
/// Extracts options of the form `--<name> <value>` or `--<name>=<value>` from the remaining arguments, and returns the extracted values.
35+
/// Extracts options of the form `--<name> <value>` or `--<name>=<value>` from the remaining arguments and returns the extracted values.
2736
public mutating func extractOption(named name: String) -> [String] {
2837
var values: [String] = []
2938
var idx = 0
@@ -66,12 +75,16 @@ public struct ArgumentExtractor {
6675
return count
6776
}
6877

69-
/// Returns any unextracted flags or options (based strictly on whether remaining arguments have a "--" prefix).
78+
/// Returns any unextracted flags or options.
79+
///
80+
/// This is based strictly on whether remaining arguments have a `--` prefix.
7081
public var unextractedOptionsOrFlags: [String] {
7182
return args.filter{ $0.hasPrefix("--") }
7283
}
7384

74-
/// Returns all remaining arguments, including any literals after the first `--` if there is one.
85+
/// Returns all remaining arguments.
86+
///
87+
/// The returned values include any positional arguments after the first `--`, if there is one.
7588
public var remainingArguments: [String] {
7689
return args + literals
7790
}

Sources/PackagePlugin/Command.swift

Lines changed: 52 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,35 @@
1212

1313
import Foundation
1414

15-
/// A command to run during the build, including executable, command lines,
16-
/// environment variables, initial working directory, etc. All paths should be
17-
/// based on the ones passed to the plugin in the target build context.
15+
/// A command to run during the build.
16+
///
17+
/// A command includes the executable, command lines, environment variables, initial working directory, and so on.
18+
/// All paths should be based on the ones that SwiftPM passes to the plugin in the target build context.
1819
public enum Command {
1920
/// Returns a command that runs when any of its output files are needed by
20-
/// the build, but out-of-date.
21+
/// the build and are out-of-date.
2122
///
2223
/// An output file is out-of-date if it doesn't exist, or if any input files
2324
/// have changed since the command was last run.
2425
///
2526
/// - Note: the paths in the list of output files may depend on the list of
2627
/// input file paths, but **must not** depend on reading the contents of
27-
/// any input files. Such cases must be handled using a `prebuildCommand`.
28+
/// any input files. Use a `prebuildCommand`if the functionality of your plugin
29+
/// requires you to read the contents of an input file.
2830
///
2931
/// - parameters:
3032
/// - displayName: An optional string to show in build logs and other
3133
/// status areas.
32-
/// - executable: The absolute path to the executable to be invoked.
33-
/// - arguments: Command-line arguments to be passed to the executable.
34-
/// - environment: Environment variable assignments visible to the
34+
/// - executable: The absolute path to the executable to invoke.
35+
/// - arguments: The command-line arguments for the executable.
36+
/// - environment: Any environment variable assignments visible to the
3537
/// executable.
36-
/// - inputFiles: Files on which the contents of output files may depend.
38+
/// - inputFiles: A list of files on which the contents of output files may depend.
3739
/// Any paths passed as `arguments` should typically be passed here as
3840
/// well.
39-
/// - outputFiles: Files to be generated or updated by the executable.
41+
/// - outputFiles: A list of files to be generated or updated by the executable.
4042
/// Any files recognizable by their extension as source files
41-
/// (e.g. `.swift`) are compiled into the target for which this command
43+
/// (for example, `.swift`) are compiled into the target for which this command
4244
/// was generated as if in its source directory; other files are treated
4345
/// as resources as if explicitly listed in `Package.swift` using
4446
/// `.process(...)`.
@@ -61,17 +63,18 @@ public enum Command {
6163
/// determine this list without first running the command, so
6264
/// instead of encoding that list, the caller supplies an
6365
/// `outputFilesDirectory` parameter, and all files in that
64-
/// directory after the command runs are treated as output files.
66+
/// directory after the command runs are treated as the output files
67+
/// of the plugin.
6568
///
6669
/// - parameters:
6770
/// - displayName: An optional string to show in build logs and other
6871
/// status areas.
69-
/// - executable: The absolute path to the executable to be invoked.
70-
/// - arguments: Command-line arguments to be passed to the executable.
71-
/// - environment: Environment variable assignments visible to the executable.
72+
/// - executable: The absolute path to the executable to invoke.
73+
/// - arguments: The command-line arguments for the executable.
74+
/// - environment: Any environment variable assignments visible to the executable.
7275
/// - outputFilesDirectory: A directory into which the command writes its
73-
/// output files. Any files there recognizable by their extension as
74-
/// source files (e.g. `.swift`) are compiled into the target for which
76+
/// output files. The package manager compiles any files there recognizable by
77+
/// their extension as source files (for example, `.swift`) into the target for which
7578
/// this command was generated as if in its source directory; other
7679
/// files are treated as resources as if explicitly listed in
7780
/// `Package.swift` using `.process(...)`.
@@ -87,7 +90,7 @@ public enum Command {
8790

8891
extension Command {
8992
/// Returns a command that runs when any of its output files are needed by
90-
/// the build, but out-of-date.
93+
/// the build and are out-of-date.
9194
///
9295
/// An output file is out-of-date if it doesn't exist, or if any input files
9396
/// have changed since the command was last run.
@@ -99,19 +102,23 @@ extension Command {
99102
/// - parameters:
100103
/// - displayName: An optional string to show in build logs and other
101104
/// status areas.
102-
/// - executable: The absolute path to the executable to be invoked.
103-
/// - arguments: Command-line arguments to be passed to the executable.
105+
/// - executable: The absolute path to the executable to invoke.
106+
/// - arguments: Command-line arguments for the executable.
104107
/// - environment: Environment variable assignments visible to the
105108
/// executable.
106109
/// - inputFiles: Files on which the contents of output files may depend.
107110
/// Any paths passed as `arguments` should typically be passed here as
108111
/// well.
109-
/// - outputFiles: Files to be generated or updated by the executable.
110-
/// Any files recognizable by their extension as source files
111-
/// (e.g. `.swift`) are compiled into the target for which this command
112+
/// - outputFiles: The files that the plugin generates or updates using the executable.
113+
/// The package manager compiles any files recognizable by their extension as source files
114+
/// (e.g. `.swift`) into the target for which this command
112115
/// was generated as if in its source directory; other files are treated
113116
/// as resources as if explicitly listed in `Package.swift` using
114117
/// `.process(...)`.
118+
///
119+
/// @DeprecationSummary {
120+
/// Use ``buildCommand(displayName:executable:arguments:environment:inputFiles:outputFiles:)-swift.enum.case`` instead.
121+
/// }
115122
@available(_PackageDescription, deprecated: 6.0, message: "Use `URL` type instead of `Path`.")
116123
public static func buildCommand(
117124
displayName: String?,
@@ -132,32 +139,33 @@ extension Command {
132139
}
133140

134141
/// Returns a command that runs when any of its output files are needed
135-
/// by the build, but out-of-date.
142+
/// by the build and are out-of-date.
136143
///
137144
/// An output file is out-of-date if it doesn't exist, or if any input
138145
/// files have changed since the command was last run.
139146
///
140147
/// - Note: the paths in the list of output files may depend on the list
141148
/// of input file paths, but **must not** depend on reading the contents
142-
/// of any input files. Such cases must be handled using a `prebuildCommand`.
149+
/// of any input files. Use a `prebuildCommand`if the functionality of your plugin
150+
/// requires you to read the contents of an input file.
143151
///
144152
/// - parameters:
145153
/// - displayName: An optional string to show in build logs and other
146154
/// status areas.
147-
/// - executable: The absolute path to the executable to be invoked.
148-
/// - arguments: Command-line arguments to be passed to the executable.
149-
/// - environment: Environment variable assignments visible to the executable.
155+
/// - executable: The absolute path to the executable to invoke.
156+
/// - arguments: The command-line arguments for the executable.
157+
/// - environment: Any environment variable assignments visible to the executable.
150158
/// - workingDirectory: Optional initial working directory when the executable
151159
/// runs.
152-
/// - inputFiles: Files on which the contents of output files may depend.
160+
/// - inputFiles: A list of files on which the contents of output files may depend.
153161
/// Any paths passed as `arguments` should typically be passed here as well.
154-
/// - outputFiles: Files to be generated or updated by the executable.
162+
/// - outputFiles: A list of files to be generated or updated by the executable.
155163
/// Any files recognizable by their extension as source files
156-
/// (e.g. `.swift`) are compiled into the target for which this command
164+
/// (for example, `.swift`) are compiled into the target for which this command
157165
/// was generated as if in its source directory; other files are treated
158166
/// as resources as if explicitly listed in `Package.swift` using
159167
/// `.process(...)`.
160-
@available(*, unavailable, message: "specifying the initial working directory for a command is not yet supported")
168+
@available(*, unavailable, message: "specifying the initial working directory for a command is not supported")
161169
public static func buildCommand(
162170
displayName: String?,
163171
executable: Path,
@@ -191,17 +199,18 @@ extension Command {
191199
/// - parameters:
192200
/// - displayName: An optional string to show in build logs and other
193201
/// status areas.
194-
/// - executable: The absolute path to the executable to be invoked.
195-
/// - arguments: Command-line arguments to be passed to the executable.
196-
/// - environment: Environment variable assignments visible to the executable.
197-
/// - workingDirectory: Optional initial working directory when the executable
198-
/// runs.
202+
/// - executable: The absolute path to the executable to invoke.
203+
/// - arguments: The command-line arguments for the executable.
204+
/// - environment: Any environment variable assignments visible to the executable.
199205
/// - outputFilesDirectory: A directory into which the command writes its
200206
/// output files. Any files there recognizable by their extension as
201-
/// source files (e.g. `.swift`) are compiled into the target for which
207+
/// source files (for example, `.swift`) are compiled into the target for which
202208
/// this command was generated as if in its source directory; other
203209
/// files are treated as resources as if explicitly listed in
204210
/// `Package.swift` using `.process(...)`.
211+
/// @DeprecationSummary {
212+
/// Use ``prebuildCommand(displayName:executable:arguments:environment:outputFilesDirectory:)-swift.enum.case`` instead.
213+
/// }
205214
@available(_PackageDescription, deprecated: 6.0, message: "Use `URL` type instead of `Path`.")
206215
public static func prebuildCommand(
207216
displayName: String?,
@@ -233,18 +242,18 @@ extension Command {
233242
/// - parameters:
234243
/// - displayName: An optional string to show in build logs and other
235244
/// status areas.
236-
/// - executable: The absolute path to the executable to be invoked.
237-
/// - arguments: Command-line arguments to be passed to the executable.
238-
/// - environment: Environment variable assignments visible to the executable.
245+
/// - executable: The absolute path to the executable to invoke.
246+
/// - arguments: The command-line arguments for the executable.
247+
/// - environment: Any environment variable assignments visible to the executable.
239248
/// - workingDirectory: Optional initial working directory when the executable
240249
/// runs.
241250
/// - outputFilesDirectory: A directory into which the command writes its
242251
/// output files. Any files there recognizable by their extension as
243-
/// source files (e.g. `.swift`) are compiled into the target for which
252+
/// source files (for example, `.swift`) are compiled into the target for which
244253
/// this command was generated as if in its source directory; other
245254
/// files are treated as resources as if explicitly listed in
246255
/// `Package.swift` using `.process(...)`.
247-
@available(*, unavailable, message: "specifying the initial working directory for a command is not yet supported")
256+
@available(*, unavailable, message: "specifying the initial working directory for a command is not supported")
248257
public static func prebuildCommand(
249258
displayName: String?,
250259
executable: Path,

0 commit comments

Comments
 (0)