Skip to content

Commit 2d793cd

Browse files
committed
- Limit the fix to tools-version 5.9
- Add minimum deployment target to example
1 parent c5c6777 commit 2d793cd

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

Fixtures/Miscellaneous/Plugins/IncorrectDependencies/Package.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
// swift-tools-version:5.8
1+
// swift-tools-version:5.9
22
import PackageDescription
33

44
let package = Package(
55
name: "111920845-sample",
6+
platforms: [
7+
.macOS(.v10_15), // example uses swift concurrency which is only available in 10.15 or newer
8+
],
69
products: [
710
.executable(name: "MyPluginExecutable", targets: ["MyPluginExecutable"]),
811
.plugin(name: "MyPlugin", targets: ["MyPlugin"]),

Sources/Build/BuildPlan.swift

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -695,14 +695,22 @@ public class BuildPlan: SPMBuildCore.BuildPlan {
695695
libraryBinaryPaths: Set<AbsolutePath>,
696696
availableTools: [String: AbsolutePath]
697697
) {
698+
/* Prior to tools-version 5.9, we used to errorneously recursively traverse plugin dependencies and statically include their
699+
targets. For compatibility reasons, we preserve that behavior for older tools-versions. */
700+
let shouldExcludePlugins: Bool
701+
if let toolsVersion = self.graph.package(for: product)?.manifest.toolsVersion {
702+
shouldExcludePlugins = toolsVersion >= .v5_9
703+
} else {
704+
shouldExcludePlugins = false
705+
}
698706

699707
// Sort the product targets in topological order.
700708
let nodes: [ResolvedTarget.Dependency] = product.targets.map { .target($0, conditions: []) }
701709
let allTargets = try topologicalSort(nodes, successors: { dependency in
702710
switch dependency {
703711
// Include all the dependencies of a target.
704712
case .target(let target, _):
705-
if [.macro, .plugin].contains(target.type) {
713+
if shouldExcludePlugins, [.macro, .plugin].contains(target.type) {
706714
return []
707715
}
708716
return target.dependencies.filter { $0.satisfies(self.buildEnvironment) }
@@ -714,10 +722,13 @@ public class BuildPlan: SPMBuildCore.BuildPlan {
714722
return []
715723
}
716724

725+
let productDependencies: [ResolvedTarget.Dependency] = product.targets.map { .target($0, conditions: []) }
717726
switch product.type {
718727
case .library(.automatic), .library(.static):
719-
return product.targets.map { .target($0, conditions: []) }
720-
case .library(.dynamic), .test, .executable, .snippet, .macro, .plugin:
728+
return productDependencies
729+
case .plugin:
730+
return shouldExcludePlugins ? [] : productDependencies
731+
case .library(.dynamic), .test, .executable, .snippet, .macro:
721732
return []
722733
}
723734
}

0 commit comments

Comments
 (0)