Skip to content

Commit f2e7318

Browse files
committed
[Build] BuildPlan: Always discover test modules through their aggregate products
Fixes a situation when tests were build for both host and target even though they should have been built only for the host (i.e. when one of the modules depends on a macro).
1 parent ee2f2f1 commit f2e7318

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

Sources/Build/BuildPlan/BuildPlan.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -986,9 +986,9 @@ extension BuildPlan {
986986
}
987987

988988
for module in package.modules {
989-
if case .test = module.underlying.type,
990-
!graph.rootPackages.contains(id: package.id)
991-
{
989+
// Tests are discovered through an aggregate product which also
990+
// informs their destination.
991+
if case .test = module.underlying.type {
992992
continue
993993
}
994994

@@ -1002,7 +1002,7 @@ extension BuildPlan {
10021002
for product: ResolvedProduct,
10031003
destination: Destination
10041004
) -> [TraversalNode] {
1005-
guard destination == .host else {
1005+
guard destination == .host || product.underlying.type == .test else {
10061006
return []
10071007
}
10081008

Sources/_InternalTestSupport/MockPackageGraphs.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ package func macrosTestsPackageGraph() throws -> MockPackageGraph {
137137
"/swift-mmio/Sources/MMIOMacros/source.swift",
138138
"/swift-mmio/Sources/MMIOMacrosTests/source.swift",
139139
"/swift-mmio/Sources/MMIOMacro+PluginTests/source.swift",
140+
"/swift-mmio/Sources/NOOPTests/source.swift",
140141
"/swift-syntax/Sources/SwiftSyntax/source.swift",
141142
"/swift-syntax/Sources/SwiftSyntaxMacrosTestSupport/source.swift",
142143
"/swift-syntax/Sources/SwiftSyntaxMacros/source.swift",
@@ -203,6 +204,11 @@ package func macrosTestsPackageGraph() throws -> MockPackageGraph {
203204
.target(name: "MMIOMacros")
204205
],
205206
type: .test
207+
),
208+
TargetDescription(
209+
name: "NOOPTests",
210+
dependencies: [],
211+
type: .test
206212
)
207213
]
208214
),

Tests/BuildTests/CrossCompilationBuildPlanTests.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,15 @@ final class CrossCompilationBuildPlanTests: XCTestCase {
295295
fileSystem: fs,
296296
observabilityScope: scope
297297
)
298+
299+
// Make sure that build plan doesn't have any "target" tests.
300+
for (_, description) in plan.targetMap where description.module.underlying.type == .test {
301+
XCTAssertEqual(description.buildParameters.destination, .host)
302+
}
303+
298304
let result = try BuildPlanResult(plan: plan)
299305
result.checkProductsCount(2)
300-
result.checkTargetsCount(16)
306+
result.checkTargetsCount(17)
301307

302308
XCTAssertTrue(try result.allTargets(named: "SwiftSyntax")
303309
.map { try $0.swift() }

0 commit comments

Comments
 (0)