Skip to content

Commit 918a8e1

Browse files
authored
Clarify/correct buildCommand docs (#6941)
Removed misleading and unneeded words; made the doc follow the Swift API Guidelines. * Similar cleanup for prebuildCommand
1 parent 76133fd commit 918a8e1

File tree

1 file changed

+84
-92
lines changed

1 file changed

+84
-92
lines changed

Sources/PackagePlugin/Command.swift

Lines changed: 84 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
/// A command to run during the build, including executable, command lines,
14-
/// environment variables, initial working directory, etc. All paths should
15-
/// be based on the ones passed to the plugin in the target build context.
14+
/// environment variables, initial working directory, etc. All paths should be
15+
/// based on the ones passed to the plugin in the target build context.
1616
public enum Command {
17-
17+
1818
case _buildCommand(
1919
displayName: String?,
2020
executable: Path,
@@ -23,7 +23,7 @@ public enum Command {
2323
workingDirectory: Path? = nil,
2424
inputFiles: [Path] = [],
2525
outputFiles: [Path] = [])
26-
26+
2727
case _prebuildCommand(
2828
displayName: String?,
2929
executable: Path,
@@ -34,32 +34,33 @@ public enum Command {
3434
}
3535

3636
public extension Command {
37-
38-
/// Creates a command to run during the build. The executable should be a
39-
/// tool returned by `PluginContext.tool(named:)`, and any paths in the
40-
/// arguments list as well as in the input and output lists should be
41-
/// based on the paths provided in the target build context structure.
37+
38+
/// Returns a command that runs when any of its ouput files are needed by
39+
/// the build, but out-of-date.
4240
///
43-
/// The build command will run whenever its outputs are missing or if its
44-
/// inputs have changed since the command was last run. In other words,
45-
/// it is incorporated into the build command graph.
41+
/// An output file is out-of-date if it doesn't exist, or if any input files
42+
/// have changed since the command was last run.
4643
///
47-
/// This is the preferred kind of command to create when the outputs that
48-
/// will be generated are known ahead of time.
44+
/// - Note: the paths in the list of output files may depend on the list of
45+
/// input file paths, but **must not** depend on reading the contents of
46+
/// any input files. Such cases must be handled using a `prebuildCommand`.
4947
///
5048
/// - parameters:
5149
/// - displayName: An optional string to show in build logs and other
5250
/// status areas.
53-
/// - executable: The executable to be invoked; should be a tool looked
54-
/// up using `tool(named:)`, which may reference either a tool provided
55-
/// by a binary target or build from source.
56-
/// - arguments: Arguments to be passed to the tool. Any paths should be
57-
/// based on the paths provided in the target build context.
58-
/// - environment: Any custom environment assignments for the subprocess.
59-
/// - inputFiles: Input files to the build command. Any changes to the
60-
/// input files cause the command to be rerun.
61-
/// - outputFiles: Output files that should be processed further according
62-
/// to the rules defined by the build system.
51+
/// - executable: The absolute path to the executable to be invoked.
52+
/// - arguments: Command-line arguments to be passed to the executable.
53+
/// - environment: Environment variable assignments visible to the
54+
/// executable.
55+
/// - inputFiles: Files on which the contents of output files may depend.
56+
/// Any paths passed as `arguments` should typically be passed here as
57+
/// well.
58+
/// - outputFiles: Files to be generated or updated by the executable.
59+
/// Any files recognizable by their extension as source files
60+
/// (e.g. `.swift`) are compiled into the target for which this command
61+
/// was generated as if in its source directory; other files are treated
62+
/// as resources as if explicitly listed in `Package.swift` using
63+
/// `.process(...)`.
6364
static func buildCommand(
6465
displayName: String?,
6566
executable: Path,
@@ -78,32 +79,32 @@ public extension Command {
7879
outputFiles: outputFiles)
7980
}
8081

81-
/// Creates a command to run during the build. The executable should be a
82-
/// tool returned by `PluginContext.tool(named:)`, and any paths in the
83-
/// arguments list as well as in the input and output lists should be
84-
/// based on the paths provided in the target build context structure.
82+
/// Returns a command that runs when any of its ouput files are needed
83+
/// by the build, but out-of-date.
8584
///
86-
/// The build command will run whenever its outputs are missing or if its
87-
/// inputs have changed since the command was last run. In other words,
88-
/// it is incorporated into the build command graph.
85+
/// An output file is out-of-date if it doesn't exist, or if any input
86+
/// files have changed since the command was last run.
8987
///
90-
/// This is the preferred kind of command to create when the outputs that
91-
/// will be generated are known ahead of time.
88+
/// - Note: the paths in the list of output files may depend on the list
89+
/// of input file paths, but **must not** depend on reading the contents
90+
/// of any input files. Such cases must be handled using a `prebuildCommand`.
9291
///
9392
/// - parameters:
9493
/// - displayName: An optional string to show in build logs and other
9594
/// status areas.
96-
/// - executable: The executable to be invoked; should be a tool looked
97-
/// up using `tool(named:)`, which may reference either a tool provided
98-
/// by a binary target or build from source.
99-
/// - arguments: Arguments to be passed to the tool. Any paths should be
100-
/// based on the paths provided in the target build context.
101-
/// - environment: Any custom environment assignments for the subprocess.
102-
/// - workingDirectory: Optional initial working directory of the command.
103-
/// - inputFiles: Input files to the build command. Any changes to the
104-
/// input files cause the command to be rerun.
105-
/// - outputFiles: Output files that should be processed further according
106-
/// to the rules defined by the build system.
95+
/// - executable: The absolute path to the executable to be invoked.
96+
/// - arguments: Command-line arguments to be passed to the executable.
97+
/// - environment: Environment variable assignments visible to the executable.
98+
/// - workingDirectory: Optional initial working directory when the executable
99+
/// runs.
100+
/// - inputFiles: Files on which the contents of output files may depend.
101+
/// Any paths passed as `arguments` should typically be passed here as well.
102+
/// - outputFiles: Files to be generated or updated by the executable.
103+
/// Any files recognizable by their extension as source files
104+
/// (e.g. `.swift`) are compiled into the target for which this command
105+
/// was generated as if in its source directory; other files are treated
106+
/// as resources as if explicitly listed in `Package.swift` using
107+
/// `.process(...)`.
107108
@available(*, unavailable, message: "specifying the initial working directory for a command is not yet supported")
108109
static func buildCommand(
109110
displayName: String?,
@@ -124,35 +125,31 @@ public extension Command {
124125
outputFiles: outputFiles)
125126
}
126127

127-
/// Creates a command to run before the build. The executable should be a
128-
/// tool returned by `PluginContext.tool(named:)`, and any paths in the
129-
/// arguments list and in the output files directory should be based on
130-
/// the paths provided in the target build context structure.
131-
///
132-
/// The build command will run before the build starts, and is allowed to
133-
/// create an arbitrary set of output files based on the contents of the
134-
/// inputs.
128+
/// Returns a command that runs unconditionally before every build.
135129
///
136-
/// Because prebuild commands are run on every build, they can have a
137-
/// significant performance impact and should only be used when there is
138-
/// no way to know the names of the outputs before the command is run.
139-
///
140-
/// The `outputFilesDirectory` parameter is the path of a directory into
141-
/// which the command will write its output files. Any files that are in
142-
/// that directory after the prebuild command finishes will be interpreted
143-
/// according to the same build rules as for sources.
130+
/// Prebuild commands can have a significant performance impact
131+
/// and should only be used when there would be no way to know the
132+
/// list of output file paths without first reading the contents
133+
/// of one or more input files. Typically there is no way to
134+
/// determine this list without first running the command, so
135+
/// instead of encoding that list, the caller supplies an
136+
/// `outputFilesDirectory` parameter, and all files in that
137+
/// directory after the command runs are treated as output files.
144138
///
145139
/// - parameters:
146140
/// - displayName: An optional string to show in build logs and other
147141
/// status areas.
148-
/// - executable: The executable to be invoked; should be a tool looked
149-
/// up using `tool(named:)`, which may reference either a tool provided
150-
/// by a binary target or build from source.
151-
/// - arguments: Arguments to be passed to the tool. Any paths should be
152-
/// based on the paths provided in the target build context.
153-
/// - environment: Any custom environment assignments for the subprocess.
154-
/// - outputFilesDirectory: A directory into which the command can write
155-
/// output files that should be processed further.
142+
/// - executable: The absolute path to the executable to be invoked.
143+
/// - arguments: Command-line arguments to be passed to the executable.
144+
/// - environment: Environment variable assignments visible to the executable.
145+
/// - workingDirectory: Optional initial working directory when the executable
146+
/// runs.
147+
/// - outputFilesDirectory: A directory into which the command writes its
148+
/// output files. Any files there recognizable by their extension as
149+
/// source files (e.g. `.swift`) are compiled into the target for which
150+
/// this command was generated as if in its source directory; other
151+
/// files are treated as resources as if explicitly listed in
152+
/// `Package.swift` using `.process(...)`.
156153
static func prebuildCommand(
157154
displayName: String?,
158155
executable: Path,
@@ -169,36 +166,31 @@ public extension Command {
169166
outputFilesDirectory: outputFilesDirectory)
170167
}
171168

172-
/// Creates a command to run before the build. The executable should be a
173-
/// tool returned by `PluginContext.tool(named:)`, and any paths in the
174-
/// arguments list and in the output files directory should be based on
175-
/// the paths provided in the target build context structure.
176-
///
177-
/// The build command will run before the build starts, and is allowed to
178-
/// create an arbitrary set of output files based on the contents of the
179-
/// inputs.
169+
/// Returns a command that runs unconditionally before every build.
180170
///
181171
/// Because prebuild commands are run on every build, they can have a
182-
/// significant performance impact and should only be used when there is
183-
/// no way to know the names of the outputs before the command is run.
184-
///
185-
/// The `outputFilesDirectory` parameter is the path of a directory into
186-
/// which the command will write its output files. Any files that are in
187-
/// that directory after the prebuild command finishes will be interpreted
188-
/// according to the same build rules as for sources.
172+
/// significant performance impact and should only be used when there
173+
/// would be no way to know the list of output file paths without first
174+
/// reading the contents of one or more input files. Typically there is
175+
/// no way to determine this list without first running the command, so
176+
/// instead of encoding that list, the caller supplies an
177+
/// `outputFilesDirectory` parameter, and all files in that directory
178+
/// after the command runs are treated as output files.
189179
///
190180
/// - parameters:
191181
/// - displayName: An optional string to show in build logs and other
192182
/// status areas.
193-
/// - executable: The executable to be invoked; should be a tool looked
194-
/// up using `tool(named:)`, which may reference either a tool provided
195-
/// by a binary target or build from source.
196-
/// - arguments: Arguments to be passed to the tool. Any paths should be
197-
/// based on the paths provided in the target build context.
198-
/// - environment: Any custom environment assignments for the subprocess.
199-
/// - workingDirectory: Optional initial working directory of the command.
200-
/// - outputFilesDirectory: A directory into which the command can write
201-
/// output files that should be processed further.
183+
/// - executable: The absolute path to the executable to be invoked.
184+
/// - arguments: Command-line arguments to be passed to the executable.
185+
/// - environment: Environment variable assignments visible to the executable.
186+
/// - workingDirectory: Optional initial working directory when the executable
187+
/// runs.
188+
/// - outputFilesDirectory: A directory into which the command writes its
189+
/// output files. Any files there recognizable by their extension as
190+
/// source files (e.g. `.swift`) are compiled into the target for which
191+
/// this command was generated as if in its source directory; other
192+
/// files are treated as resources as if explicitly listed in
193+
/// `Package.swift` using `.process(...)`.
202194
@available(*, unavailable, message: "specifying the initial working directory for a command is not yet supported")
203195
static func prebuildCommand(
204196
displayName: String?,

0 commit comments

Comments
 (0)