Skip to content

Commit d653002

Browse files
committed
rdar://93679015 ([Plugins] SwiftPM does not build dependency executable before invoking plugin)
Make the list of input dependencies of an llbuild command that runs a plugin include the paths of all the tools on which the plugin has declared a dependency, not just the one that appears as an executable in the build command. This still needs a unit test.
1 parent d9ce602 commit d653002

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

Sources/Build/LLBuildManifestBuilder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ extension LLBuildManifestBuilder {
625625
manifest.addShellCmd(
626626
name: displayName + "-" + ByteString(encodingAsUTF8: uniquedName).sha256Checksum,
627627
description: displayName,
628-
inputs: [.file(execPath)] + command.inputFiles.map{ .file($0) },
628+
inputs: command.inputFiles.map{ .file($0) },
629629
outputs: command.outputFiles.map{ .file($0) },
630630
arguments: commandLine,
631631
environment: command.configuration.environment,

Sources/SPMBuildCore/PluginInvocation.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,9 @@ extension PackageGraph {
353353
dict[name] = path
354354
}
355355
})
356+
357+
// Determine additional input dependencies for any plugin commands, based on any executables the plugin target depends on.
358+
let toolPaths = toolNamesToPaths.values.sorted()
356359

357360
// Assign a plugin working directory based on the package, target, and plugin.
358361
let pluginOutputDir = outputDir.appending(components: package.identity.description, target.name, pluginTarget.name)
@@ -367,13 +370,15 @@ extension PackageGraph {
367370
let delegateQueue = DispatchQueue(label: "plugin-invocation")
368371
class PluginDelegate: PluginInvocationDelegate {
369372
let delegateQueue: DispatchQueue
373+
let toolPaths: [AbsolutePath]
370374
var outputData = Data()
371375
var diagnostics = [Basics.Diagnostic]()
372376
var buildCommands = [BuildToolPluginInvocationResult.BuildCommand]()
373377
var prebuildCommands = [BuildToolPluginInvocationResult.PrebuildCommand]()
374378

375-
init(delegateQueue: DispatchQueue) {
379+
init(delegateQueue: DispatchQueue, toolPaths: [AbsolutePath]) {
376380
self.delegateQueue = delegateQueue
381+
self.toolPaths = toolPaths
377382
}
378383

379384
func pluginEmittedOutput(_ data: Data) {
@@ -395,7 +400,7 @@ extension PackageGraph {
395400
arguments: arguments,
396401
environment: environment,
397402
workingDirectory: workingDirectory),
398-
inputFiles: inputFiles,
403+
inputFiles: toolPaths + inputFiles,
399404
outputFiles: outputFiles))
400405
}
401406

@@ -411,7 +416,7 @@ extension PackageGraph {
411416
outputFilesDirectory: outputFilesDirectory))
412417
}
413418
}
414-
let delegate = PluginDelegate(delegateQueue: delegateQueue)
419+
let delegate = PluginDelegate(delegateQueue: delegateQueue, toolPaths: toolPaths)
415420

416421
// Invoke the build tool plugin with the input parameters and the delegate that will collect outputs.
417422
let startTime = DispatchTime.now()

Tests/SPMBuildCoreTests/PluginInvocationTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ class PluginInvocationTests: XCTestCase {
212212
XCTAssertEqual(evalFirstCommand.configuration.arguments, ["-c", "/Foo/Sources/Foo/SomeFile.abc"])
213213
XCTAssertEqual(evalFirstCommand.configuration.environment, ["X": "Y"])
214214
XCTAssertEqual(evalFirstCommand.configuration.workingDirectory, AbsolutePath("/Foo/Sources/Foo"))
215-
XCTAssertEqual(evalFirstCommand.inputFiles, [])
215+
XCTAssertEqual(evalFirstCommand.inputFiles, [builtToolsDir.appending(component: "FooTool")])
216216
XCTAssertEqual(evalFirstCommand.outputFiles, [])
217217

218218
XCTAssertEqual(evalFirstResult.diagnostics.count, 1)

0 commit comments

Comments
 (0)