Skip to content

Commit 2aab899

Browse files
committed
Fix testable executables once more
A previous problem here was fixed in #6723, this new fix is attempting to resolve issues where macros are used transitively by a product that a test is depending on. It seems to me that those transitively available macros should not be statically linked into tests and in fact doing so can cause various issues such as linker errors on non-Darwin platforms. It does feel like eventually we need to get away from `computeDependencies(of:)` being a computation on the entire package graph and instead let each package produce separate products which we can then just use transitively, but that is a much bigger change to SwiftPM's build system. rdar://115071012 (cherry picked from commit 00a64df)
1 parent c50f753 commit 2aab899

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Sources/Build/BuildPlan.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,9 @@ public class BuildPlan: SPMBuildCore.BuildPlan {
799799
if product.targets.contains(target) {
800800
staticTargets.append(target)
801801
} else if product.type == .test && (target.underlyingTarget as? SwiftTarget)?.supportsTestableExecutablesFeature == true {
802-
if let toolsVersion = graph.package(for: product)?.manifest.toolsVersion, toolsVersion >= .v5_5 {
802+
// Only "top-level" targets should really be considered here, not transitive ones.
803+
let isTopLevel = topLevelDependencies.contains(target.underlyingTarget) || product.targets.contains(target)
804+
if let toolsVersion = graph.package(for: product)?.manifest.toolsVersion, toolsVersion >= .v5_5, isTopLevel {
803805
staticTargets.append(target)
804806
}
805807
}

0 commit comments

Comments
 (0)