11
11
//===----------------------------------------------------------------------===//
12
12
13
13
/// 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.
16
16
public enum Command {
17
-
17
+
18
18
case _buildCommand(
19
19
displayName: String ? ,
20
20
executable: Path ,
@@ -23,7 +23,7 @@ public enum Command {
23
23
workingDirectory: Path ? = nil ,
24
24
inputFiles: [ Path ] = [ ] ,
25
25
outputFiles: [ Path ] = [ ] )
26
-
26
+
27
27
case _prebuildCommand(
28
28
displayName: String ? ,
29
29
executable: Path ,
@@ -34,32 +34,33 @@ public enum Command {
34
34
}
35
35
36
36
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.
42
40
///
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.
46
43
///
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`.
49
47
///
50
48
/// - parameters:
51
49
/// - displayName: An optional string to show in build logs and other
52
50
/// 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(...)`.
63
64
static func buildCommand(
64
65
displayName: String ? ,
65
66
executable: Path ,
@@ -78,32 +79,32 @@ public extension Command {
78
79
outputFiles: outputFiles)
79
80
}
80
81
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.
85
84
///
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.
89
87
///
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`.
92
91
///
93
92
/// - parameters:
94
93
/// - displayName: An optional string to show in build logs and other
95
94
/// 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(...)`.
107
108
@available ( * , unavailable, message: " specifying the initial working directory for a command is not yet supported " )
108
109
static func buildCommand(
109
110
displayName: String ? ,
@@ -124,35 +125,31 @@ public extension Command {
124
125
outputFiles: outputFiles)
125
126
}
126
127
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.
135
129
///
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 .
144
138
///
145
139
/// - parameters:
146
140
/// - displayName: An optional string to show in build logs and other
147
141
/// 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(...)`.
156
153
static func prebuildCommand(
157
154
displayName: String ? ,
158
155
executable: Path ,
@@ -169,36 +166,31 @@ public extension Command {
169
166
outputFilesDirectory: outputFilesDirectory)
170
167
}
171
168
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.
180
170
///
181
171
/// 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 .
189
179
///
190
180
/// - parameters:
191
181
/// - displayName: An optional string to show in build logs and other
192
182
/// 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(...)`.
202
194
@available ( * , unavailable, message: " specifying the initial working directory for a command is not yet supported " )
203
195
static func prebuildCommand(
204
196
displayName: String ? ,
0 commit comments