Skip to content

Fix build failures when two or more plugin-generated build commands have the same name #3585

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ let package = Package(
name: "MyLocalTool",
plugins: [
"MySourceGenBuildToolPlugin",
"MyAmbiguouslyNamedCommandPlugin",
]
),
// The plugin that generates build tool commands to invoke MySourceGenBuildTool.
Expand All @@ -23,5 +24,13 @@ let package = Package(
.executableTarget(
name: "MySourceGenBuildTool"
),
// Plugin that emits commands with a generic name.
.plugin(
name: "MyAmbiguouslyNamedCommandPlugin",
capability: .buildTool(),
dependencies: [
"MySourceGenBuildTool",
]
),
]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import PackagePlugin

for inputFile in targetBuildContext.inputFiles.filter({ $0.path.extension == "dat" }) {
let inputPath = inputFile.path
let outputName = "Ambiguous_" + inputPath.stem + ".swift"
let outputPath = targetBuildContext.pluginWorkDirectory.appending(outputName)
commandConstructor.addBuildCommand(
displayName:
"This is a constant name",
executable:
try targetBuildContext.tool(named: "MySourceGenBuildTool").path,
arguments: [
"\(inputPath)",
"\(outputPath)"
],
environment: [
"VARIABLE_NAME_PREFIX": "SECOND_PREFIX_"
],
inputFiles: [
inputPath,
],
outputFiles: [
outputPath
]
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I am Bar!
5 changes: 3 additions & 2 deletions Sources/Build/ManifestBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -584,10 +584,11 @@ extension LLBuildManifestBuilder {

// Add any regular build commands created by plugins for the target (prebuild commands are handled separately).
for command in target.pluginInvocationResults.reduce([], { $0 + $1.buildCommands }) {
// Create a shell command to invoke the executable. We include the path of the executable as a dependency.
// 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.
let execPath = AbsolutePath(command.configuration.executable, relativeTo: buildParameters.buildPath)
let uniquedName = ([execPath.pathString] + command.configuration.arguments).joined(separator: "|")
manifest.addShellCmd(
name: command.configuration.displayName,
name: command.configuration.displayName + "-" + ByteString(encodingAsUTF8: uniquedName).sha256Checksum,
description: command.configuration.displayName,
inputs: [.file(execPath)] + command.inputFiles.map{ .file($0) },
outputs: command.outputFiles.map{ .file($0) },
Expand Down