Skip to content

Commit a7d5baf

Browse files
committed
[Plugins] Make sure that plugins work when referenced by tools and destination modules
Remove incorrect assumption that the outputs of the plugin are always connected to a destination build of a particular module and add a build triple into the path to separate the outputs of a plugin. This comes into play when i.e. a test is built for both `tools` and `destination`, we need two plugin invocations to handle that.
1 parent d791528 commit a7d5baf

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

Sources/PackageGraph/BuildTriple.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ import class PackageModel.Product
1616
/// Triple for which code should be compiled for.
1717
/// > Note: We're not using "host" and "target" triple terminology in this enum, as that clashes with build
1818
/// > system "targets" and can lead to confusion in this context.
19-
public enum BuildTriple {
19+
public enum BuildTriple: String {
2020
/// Triple for which build tools are compiled (the host triple).
21-
case tools
21+
case tools = "tools"
2222

2323
/// Triple of the destination platform for which end products are compiled (the target triple).
24-
case destination
24+
case destination = "destination"
2525
}
2626

2727
extension Target {

Sources/SPMBuildCore/Plugins/PluginInvocation.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ extension ModulesGraph {
452452
let toolPaths = accessibleTools.values.map { $0.path }.sorted()
453453

454454
// Assign a plugin working directory based on the package, target, and plugin.
455-
let pluginOutputDir = outputDir.appending(components: package.identity.description, target.name, pluginTarget.name)
455+
let pluginOutputDir = outputDir.appending(components: package.identity.description, target.name, target.buildTriple.rawValue, pluginTarget.name)
456456

457457
// Determine the set of directories under which plugins are allowed to write. We always include just the output directory, and for now there is no possibility of opting into others.
458458
let writableDirectories = [outputDir]
@@ -597,9 +597,7 @@ extension ModulesGraph {
597597
}
598598

599599
// Associate the list of results with the target. The list will have one entry for each plugin used by the target.
600-
var targetID = target.id
601-
targetID.buildTriple = .destination
602-
pluginResultsByTarget[targetID] = (target, buildToolPluginResults)
600+
pluginResultsByTarget[target.id] = (target, buildToolPluginResults)
603601
}
604602
return pluginResultsByTarget
605603
}

Tests/FunctionalTests/PluginTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ final class PluginTests: XCTestCase {
226226

227227
try testWithTemporaryDirectory { tmpPath in
228228
let packageDir = tmpPath.appending(components: "MyPackage")
229-
let pathOfGeneratedFile = packageDir.appending(components: [".build", "plugins", "outputs", "mypackage", "SomeTarget", "Plugin", "best.txt"])
229+
let pathOfGeneratedFile = packageDir.appending(components: [".build", "plugins", "outputs", "mypackage", "SomeTarget", "destination", "Plugin", "best.txt"])
230230

231231
try createPackageUnderTest(packageDir: packageDir, toolsVersion: .v5_9)
232232
let (_, stderr) = try executeSwiftBuild(packageDir, env: ["SWIFT_DRIVER_SWIFTSCAN_LIB" : "/this/is/a/bad/path"])

0 commit comments

Comments
 (0)