Skip to content

Commit 60761e6

Browse files
committed
[ManifestBuilder] Refactor createSwiftCompileCommand into smaller chunks
1 parent d974ef4 commit 60761e6

File tree

1 file changed

+49
-32
lines changed

1 file changed

+49
-32
lines changed

Sources/Build/ManifestBuilder.swift

Lines changed: 49 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,37 @@ extension LLBuildManifestBuilder {
149149
private func createSwiftCompileCommand(
150150
_ target: SwiftTargetBuildDescription
151151
) {
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] {
152183
var inputs = target.sources.map(Node.file)
153184

154185
// Add resources node as the input to the target. This isn't great because we
@@ -210,26 +241,11 @@ extension LLBuildManifestBuilder {
210241
}
211242
}
212243

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+
}
232246

247+
/// Adds a top-level phony command that builds the entire target.
248+
private func addTargetCmd(_ target: SwiftTargetBuildDescription, cmdOutputs: [Node]) {
233249
// Create a phony node to represent the entire target.
234250
let targetName = target.target.getLLBuildTargetName(config: buildConfig)
235251
let targetOutput: Node = .virtual(targetName)
@@ -246,21 +262,22 @@ extension LLBuildManifestBuilder {
246262
}
247263
addNode(targetOutput, toTarget: .test)
248264
}
265+
}
249266

267+
private func addModuleWrapCmd(_ target: SwiftTargetBuildDescription) {
250268
// 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)
264281
}
265282
}
266283

0 commit comments

Comments
 (0)