Skip to content

Commit 95ff950

Browse files
authored
Add development-time assertions to catch errors where two llbuild commands are created with the same name. Otherwise this results in silently replacing some commands in the graph. We can discuss whether a future improvement would be to make these internal errors reported at runtime. (#3587)
1 parent 1d61ceb commit 95ff950

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Sources/LLBuildManifest/BuildManifest.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public struct BuildManifest {
5050
inputs: [Node],
5151
outputs: [Node]
5252
) {
53+
assert(commands[name] == nil, "aleady had a command named '\(name)'")
5354
let tool = PhonyTool(inputs: inputs, outputs: outputs)
5455
commands[name] = Command(name: name, tool: tool)
5556
}
@@ -59,6 +60,7 @@ public struct BuildManifest {
5960
inputs: [Node],
6061
outputs: [Node]
6162
) {
63+
assert(commands[name] == nil, "aleady had a command named '\(name)'")
6264
let tool = TestDiscoveryTool(inputs: inputs, outputs: outputs)
6365
commands[name] = Command(name: name, tool: tool)
6466
}
@@ -68,6 +70,7 @@ public struct BuildManifest {
6870
inputs: [Node],
6971
outputs: [Node]
7072
) {
73+
assert(commands[name] == nil, "aleady had a command named '\(name)'")
7174
let tool = CopyTool(inputs: inputs, outputs: outputs)
7275
commands[name] = Command(name: name, tool: tool)
7376
}
@@ -77,6 +80,7 @@ public struct BuildManifest {
7780
inputs: [Node],
7881
outputs: [Node]
7982
) {
83+
assert(commands[name] == nil, "aleady had a command named '\(name)'")
8084
let tool = PackageStructureTool(inputs: inputs, outputs: outputs)
8185
commands[name] = Command(name: name, tool: tool)
8286
}
@@ -86,6 +90,7 @@ public struct BuildManifest {
8690
inputs: [Node],
8791
outputs: [Node]
8892
) {
93+
assert(commands[name] == nil, "aleady had a command named '\(name)'")
8994
let tool = ArchiveTool(inputs: inputs, outputs: outputs)
9095
commands[name] = Command(name: name, tool: tool)
9196
}
@@ -100,6 +105,7 @@ public struct BuildManifest {
100105
workingDirectory: String? = nil,
101106
allowMissingInputs: Bool = false
102107
) {
108+
assert(commands[name] == nil, "aleady had a command named '\(name)'")
103109
let tool = ShellTool(
104110
description: description,
105111
inputs: inputs,
@@ -120,6 +126,7 @@ public struct BuildManifest {
120126
outputs: [Node],
121127
arguments: [String]
122128
) {
129+
assert(commands[name] == nil, "aleady had a command named '\(name)'")
123130
let tool = SwiftFrontendTool(
124131
moduleName: moduleName,
125132
description: description,
@@ -138,6 +145,7 @@ public struct BuildManifest {
138145
arguments: [String],
139146
dependencies: String? = nil
140147
) {
148+
assert(commands[name] == nil, "aleady had a command named '\(name)'")
141149
let tool = ClangTool(
142150
description: description,
143151
inputs: inputs,
@@ -163,6 +171,7 @@ public struct BuildManifest {
163171
isLibrary: Bool,
164172
wholeModuleOptimization: Bool
165173
) {
174+
assert(commands[name] == nil, "aleady had a command named '\(name)'")
166175
let tool = SwiftCompilerTool(
167176
inputs: inputs,
168177
outputs: outputs,
@@ -177,7 +186,6 @@ public struct BuildManifest {
177186
isLibrary: isLibrary,
178187
wholeModuleOptimization: wholeModuleOptimization
179188
)
180-
181189
commands[name] = Command(name: name, tool: tool)
182190
}
183191
}

0 commit comments

Comments
 (0)