Skip to content

Commit 0917f65

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
1 parent 92e0e8f commit 0917f65

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
@@ -790,7 +790,9 @@ public class BuildPlan: SPMBuildCore.BuildPlan {
790790
if product.targets.contains(target) {
791791
staticTargets.append(target)
792792
} else if product.type == .test && (target.underlyingTarget as? SwiftTarget)?.supportsTestableExecutablesFeature == true {
793-
if let toolsVersion = graph.package(for: product)?.manifest.toolsVersion, toolsVersion >= .v5_5 {
793+
// Only "top-level" targets should really be considered here, not transitive ones.
794+
let isTopLevel = topLevelDependencies.contains(target.underlyingTarget) || product.targets.contains(target)
795+
if let toolsVersion = graph.package(for: product)?.manifest.toolsVersion, toolsVersion >= .v5_5, isTopLevel {
794796
staticTargets.append(target)
795797
}
796798
}

0 commit comments

Comments
 (0)