Skip to content

Commit 5c3d5fa

Browse files
committed
Make sure that the command for a plugin-generated command is unique by including the command line as well.
Otherwise the llbuild manifest will contain only the last defined command with the same name, leading to build failures. To avoid having the name be exceedingly long, what we append to the name is a digest of the command line and not the full command line itself. rdar://79872414
1 parent 426e296 commit 5c3d5fa

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

Fixtures/Miscellaneous/Plugins/ContrivedTestPlugin/Package.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ let package = Package(
99
name: "MyLocalTool",
1010
plugins: [
1111
"MySourceGenBuildToolPlugin",
12+
"MyAmbiguouslyNamedCommandPlugin",
1213
]
1314
),
1415
// The plugin that generates build tool commands to invoke MySourceGenBuildTool.
@@ -23,5 +24,13 @@ let package = Package(
2324
.executableTarget(
2425
name: "MySourceGenBuildTool"
2526
),
27+
// Plugin that emits commands with a generic name.
28+
.plugin(
29+
name: "MyAmbiguouslyNamedCommandPlugin",
30+
capability: .buildTool(),
31+
dependencies: [
32+
"MySourceGenBuildTool",
33+
]
34+
),
2635
]
2736
)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import PackagePlugin
2+
3+
for inputFile in targetBuildContext.inputFiles.filter({ $0.path.extension == "dat" }) {
4+
let inputPath = inputFile.path
5+
let outputName = "Ambiguous_" + inputPath.stem + ".swift"
6+
let outputPath = targetBuildContext.pluginWorkDirectory.appending(outputName)
7+
commandConstructor.addBuildCommand(
8+
displayName:
9+
"This is a constant name",
10+
executable:
11+
try targetBuildContext.tool(named: "MySourceGenBuildTool").path,
12+
arguments: [
13+
"\(inputPath)",
14+
"\(outputPath)"
15+
],
16+
environment: [
17+
"VARIABLE_NAME_PREFIX": "SECOND_PREFIX_"
18+
],
19+
inputFiles: [
20+
inputPath,
21+
],
22+
outputFiles: [
23+
outputPath
24+
]
25+
)
26+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
I am Bar!

Sources/Build/ManifestBuilder.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,10 +584,11 @@ extension LLBuildManifestBuilder {
584584

585585
// Add any regular build commands created by plugins for the target (prebuild commands are handled separately).
586586
for command in target.pluginInvocationResults.reduce([], { $0 + $1.buildCommands }) {
587-
// Create a shell command to invoke the executable. We include the path of the executable as a dependency.
587+
// Create a shell command to invoke the executable. We include the path of the executable as a dependency, and make sure the name is unique.
588588
let execPath = AbsolutePath(command.configuration.executable, relativeTo: buildParameters.buildPath)
589+
let uniquedName = ([execPath.pathString] + command.configuration.arguments).joined(separator: "|")
589590
manifest.addShellCmd(
590-
name: command.configuration.displayName,
591+
name: command.configuration.displayName + "-" + ByteString(encodingAsUTF8: uniquedName).sha256Checksum,
591592
description: command.configuration.displayName,
592593
inputs: [.file(execPath)] + command.inputFiles.map{ .file($0) },
593594
outputs: command.outputFiles.map{ .file($0) },

0 commit comments

Comments
 (0)