Skip to content

Commit 62bf7f7

Browse files
committed
Make sure that the command for a plugin-generated command is unique by adding the input and output files 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 string and not the string itself. rdar://79872414
1 parent aa17407 commit 62bf7f7

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,8 +586,9 @@ extension LLBuildManifestBuilder {
586586
for command in target.pluginInvocationResults.reduce([], { $0 + $1.buildCommands }) {
587587
// Create a shell command to invoke the executable. We include the path of the executable as a dependency.
588588
let execPath = AbsolutePath(command.configuration.executable, relativeTo: buildParameters.buildPath)
589+
let uniquedName = ([command.configuration.displayName] + (command.inputFiles + command.outputFiles ).map{ $0.pathString }).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)