[mpp] Minor: use ToolingDiagnostic for reporting cyclic dependsOn-edges

This commit is contained in:
Dmitry Savvinov
2023-06-26 15:45:00 +03:00
committed by Space Team
parent 7abb0d9f0c
commit 71c1abde5c
2 changed files with 14 additions and 4 deletions
@@ -594,6 +594,14 @@ object KotlinToolingDiagnostics {
throwable = trace,
)
}
object CircularDependsOnEdges : ToolingDiagnosticFactory(FATAL) {
operator fun invoke(sourceSetsOnCycle: Collection<String>) = build(
"""
Circular dependsOn hierarchy found in the Kotlin source sets: ${sourceSetsOnCycle.joinToString(" -> ")}
""".trimIndent()
)
}
}
private fun String.indentLines(nSpaces: Int = 4, skipFirstLine: Boolean = true): String {
@@ -5,8 +5,9 @@
package org.jetbrains.kotlin.gradle.plugin.sources
import org.gradle.api.InvalidUserCodeException
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
import org.jetbrains.kotlin.gradle.plugin.diagnostics.KotlinToolingDiagnostics
import org.jetbrains.kotlin.gradle.plugin.diagnostics.reportDiagnostic
internal fun KotlinSourceSet.checkForCircularDependsOnEdges(other: KotlinSourceSet): Nothing? {
val stack = mutableListOf(this)
@@ -15,9 +16,10 @@ internal fun KotlinSourceSet.checkForCircularDependsOnEdges(other: KotlinSourceS
fun checkReachableRecursively(from: KotlinSourceSet) {
if (!visited.add(from)) return
stack += from
if (this == from) throw InvalidUserCodeException(
"Circular dependsOn hierarchy found in the Kotlin source sets: ${(stack.toList()).joinToString(" -> ") { it.name }}"
)
if (this == from) {
// CircularDependsOnEdges has severity FATAL, so this call will throw an exception
project.reportDiagnostic(KotlinToolingDiagnostics.CircularDependsOnEdges(stack.map { it.name }))
}
from.dependsOn.forEach { next -> checkReachableRecursively(next) }
stack -= from
}