@@ -149,6 +149,37 @@ extension LLBuildManifestBuilder {
149
149
private func createSwiftCompileCommand(
150
150
_ target: SwiftTargetBuildDescription
151
151
) {
152
+ let inputs = computeSwiftCompileCmdInputs ( target)
153
+
154
+ let cmdName = target. target. getCommandName ( config: buildConfig)
155
+ let objectNodes = target. objects. map ( Node . file)
156
+ let moduleNode = Node . file ( target. moduleOutputPath)
157
+ let cmdOutputs = objectNodes + [ moduleNode]
158
+ let isLibrary = target. target. type == . library || target. target. type == . test
159
+
160
+ manifest. addSwiftCmd (
161
+ name: cmdName,
162
+ inputs: inputs,
163
+ outputs: cmdOutputs,
164
+ executable: buildParameters. toolchain. swiftCompiler,
165
+ moduleName: target. target. c99name,
166
+ moduleOutputPath: target. moduleOutputPath,
167
+ importPath: buildParameters. buildPath,
168
+ tempsPath: target. tempsPath,
169
+ objects: target. objects,
170
+ otherArgs: target. compileArguments ( ) ,
171
+ sources: target. sources,
172
+ isLibrary: isLibrary,
173
+ WMO: buildParameters. configuration == . release
174
+ )
175
+
176
+ addTargetCmd ( target, cmdOutputs: cmdOutputs)
177
+ addModuleWrapCmd ( target)
178
+ }
179
+
180
+ private func computeSwiftCompileCmdInputs(
181
+ _ target: SwiftTargetBuildDescription
182
+ ) -> [ Node ] {
152
183
var inputs = target. sources. map ( Node . file)
153
184
154
185
// Add resources node as the input to the target. This isn't great because we
@@ -210,26 +241,11 @@ extension LLBuildManifestBuilder {
210
241
}
211
242
}
212
243
213
- let cmdName = target. target. getCommandName ( config: buildConfig)
214
- let cmdOutputs = target. objects. map ( Node . file) + [ . file( target. moduleOutputPath) ]
215
-
216
- let isLibrary = target. target. type == . library || target. target. type == . test
217
- manifest. addSwiftCmd (
218
- name: cmdName,
219
- inputs: inputs,
220
- outputs: cmdOutputs,
221
- executable: buildParameters. toolchain. swiftCompiler,
222
- moduleName: target. target. c99name,
223
- moduleOutputPath: target. moduleOutputPath,
224
- importPath: buildParameters. buildPath,
225
- tempsPath: target. tempsPath,
226
- objects: target. objects,
227
- otherArgs: target. compileArguments ( ) ,
228
- sources: target. sources,
229
- isLibrary: isLibrary,
230
- WMO: buildParameters. configuration == . release
231
- )
244
+ return inputs
245
+ }
232
246
247
+ /// Adds a top-level phony command that builds the entire target.
248
+ private func addTargetCmd( _ target: SwiftTargetBuildDescription , cmdOutputs: [ Node ] ) {
233
249
// Create a phony node to represent the entire target.
234
250
let targetName = target. target. getLLBuildTargetName ( config: buildConfig)
235
251
let targetOutput : Node = . virtual( targetName)
@@ -246,21 +262,22 @@ extension LLBuildManifestBuilder {
246
262
}
247
263
addNode ( targetOutput, toTarget: . test)
248
264
}
265
+ }
249
266
267
+ private func addModuleWrapCmd( _ target: SwiftTargetBuildDescription ) {
250
268
// Add commands to perform the module wrapping Swift modules when debugging statergy is `modulewrap`.
251
- if buildParameters. debuggingStrategy == . modulewrap {
252
- let moduleWrapArgs = [
253
- target. buildParameters. toolchain. swiftCompiler. pathString,
254
- " -modulewrap " , target. moduleOutputPath. pathString,
255
- " -o " , target. wrappedModuleOutputPath. pathString
256
- ]
257
- manifest. addShellCmd (
258
- name: target. wrappedModuleOutputPath. pathString,
259
- description: " Wrapping AST for \( target. target. name) for debugging " ,
260
- inputs: [ . file( target. moduleOutputPath) ] ,
261
- outputs: [ . file( target. wrappedModuleOutputPath) ] ,
262
- args: moduleWrapArgs)
263
- }
269
+ guard buildParameters. debuggingStrategy == . modulewrap else { return }
270
+ let moduleWrapArgs = [
271
+ target. buildParameters. toolchain. swiftCompiler. pathString,
272
+ " -modulewrap " , target. moduleOutputPath. pathString,
273
+ " -o " , target. wrappedModuleOutputPath. pathString
274
+ ]
275
+ manifest. addShellCmd (
276
+ name: target. wrappedModuleOutputPath. pathString,
277
+ description: " Wrapping AST for \( target. target. name) for debugging " ,
278
+ inputs: [ . file( target. moduleOutputPath) ] ,
279
+ outputs: [ . file( target. wrappedModuleOutputPath) ] ,
280
+ args: moduleWrapArgs)
264
281
}
265
282
}
266
283
0 commit comments