Skip to content

[Build] BuildPlan: Always discover test modules through their aggrega… #7879

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Sources/Build/BuildPlan/BuildPlan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -986,9 +986,9 @@ extension BuildPlan {
}

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

Expand All @@ -1002,7 +1002,7 @@ extension BuildPlan {
for product: ResolvedProduct,
destination: Destination
) -> [TraversalNode] {
guard destination == .host else {
guard destination == .host || product.underlying.type == .test else {
return []
}

Expand Down
6 changes: 6 additions & 0 deletions Sources/_InternalTestSupport/MockPackageGraphs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ package func macrosTestsPackageGraph() throws -> MockPackageGraph {
"/swift-mmio/Sources/MMIOMacros/source.swift",
"/swift-mmio/Sources/MMIOMacrosTests/source.swift",
"/swift-mmio/Sources/MMIOMacro+PluginTests/source.swift",
"/swift-mmio/Sources/NOOPTests/source.swift",
"/swift-syntax/Sources/SwiftSyntax/source.swift",
"/swift-syntax/Sources/SwiftSyntaxMacrosTestSupport/source.swift",
"/swift-syntax/Sources/SwiftSyntaxMacros/source.swift",
Expand Down Expand Up @@ -203,6 +204,11 @@ package func macrosTestsPackageGraph() throws -> MockPackageGraph {
.target(name: "MMIOMacros")
],
type: .test
),
TargetDescription(
name: "NOOPTests",
dependencies: [],
type: .test
)
]
),
Expand Down
8 changes: 7 additions & 1 deletion Tests/BuildTests/CrossCompilationBuildPlanTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,15 @@ final class CrossCompilationBuildPlanTests: XCTestCase {
fileSystem: fs,
observabilityScope: scope
)

// Make sure that build plan doesn't have any "target" tests.
for (_, description) in plan.targetMap where description.module.underlying.type == .test {
XCTAssertEqual(description.buildParameters.destination, .host)
}

let result = try BuildPlanResult(plan: plan)
result.checkProductsCount(2)
result.checkTargetsCount(16)
result.checkTargetsCount(17)

XCTAssertTrue(try result.allTargets(named: "SwiftSyntax")
.map { try $0.swift() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ final class CrossCompilationPackageGraphTests: XCTestCase {
"SwiftSyntaxMacrosTestSupport",
"SwiftSyntaxMacrosTestSupport"
)
result.check(testModules: "MMIOMacrosTests", "MMIOMacro+PluginTests")
// TODO: NOOPTests are mentioned twice because in the graph they appear
// as if they target both "tools" and "destination", see the test below.
// Once the `buildTriple` is gone, there is going to be only one mention
// left.
result.check(testModules: "MMIOMacrosTests", "MMIOMacro+PluginTests", "NOOPTests", "NOOPTests")
result.checkTarget("MMIO") { result in
result.check(buildTriple: .destination)
result.check(dependencies: "MMIOMacros")
Expand Down Expand Up @@ -180,6 +184,13 @@ final class CrossCompilationPackageGraphTests: XCTestCase {
XCTAssertEqual(graph.package(for: result.target)?.identity, .plain("swift-syntax"))
}
}

result.checkTargets("NOOPTests") { results in
XCTAssertEqual(results.count, 2)

XCTAssertEqual(results.filter({ $0.target.buildTriple == .tools }).count, 1)
XCTAssertEqual(results.filter({ $0.target.buildTriple == .destination }).count, 1)
}
}
}

Expand Down