Skip to content
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

Paper over test fixture dependency cycles in mod score computation #1082

Merged
merged 3 commits into from
Nov 11, 2024
Merged
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jgrapht.alg.scoring.BetweennessCentrality
import org.jgrapht.graph.DefaultEdge
import org.jgrapht.graph.DirectedAcyclicGraph
import org.jgrapht.graph.GraphCycleProhibitedException

public object ModuleStatsTasks {
public const val AGGREGATOR_NAME: String = "aggregateModuleStats"
Expand Down Expand Up @@ -330,16 +331,23 @@ public abstract class ModuleStatsAggregatorTask : DefaultTask() {
graph.addVertex(dependency)
try {
graph.addEdge(subproject, dependency)
} catch (e: IllegalArgumentException) {
} catch (e: GraphCycleProhibitedException) {
// Surprisingly, not unexpected. This can happen when project A has a compileOnly
// dependency on project B and project B has a testImplementation dependency on project A.
// This _only_ happens with model and test-model, which we should just modularize out to a
// third "model-tests" module
if ("model" !in subproject || "model" !in dependency) {
throw RuntimeException(
"Cycle from $subproject to $dependency. Please modularize this better!",
e,
)
if (subproject.contains("test-fixtures") xor dependency.contains("test-fixtures")) {
// This is a big bandaid over the ability for projects to depend own their own test
// fixtures, which breaks the cycle in these scenarios.
// We allow this specific case, ideally in the future with native testFixtures()
// support this would just go away.
} else {
throw RuntimeException(
"Cycle from $subproject to $dependency. Please modularize this better!",
e,
)
}
}
}
}
Expand Down
Loading