[mpp] Minor: use ToolingDiagnostic for reporting cyclic dependsOn-edges
This commit is contained in:
committed by
Space Team
parent
7abb0d9f0c
commit
71c1abde5c
+8
@@ -594,6 +594,14 @@ object KotlinToolingDiagnostics {
|
|||||||
throwable = trace,
|
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 {
|
private fun String.indentLines(nSpaces: Int = 4, skipFirstLine: Boolean = true): String {
|
||||||
|
|||||||
+6
-4
@@ -5,8 +5,9 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.gradle.plugin.sources
|
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.KotlinSourceSet
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.diagnostics.KotlinToolingDiagnostics
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.diagnostics.reportDiagnostic
|
||||||
|
|
||||||
internal fun KotlinSourceSet.checkForCircularDependsOnEdges(other: KotlinSourceSet): Nothing? {
|
internal fun KotlinSourceSet.checkForCircularDependsOnEdges(other: KotlinSourceSet): Nothing? {
|
||||||
val stack = mutableListOf(this)
|
val stack = mutableListOf(this)
|
||||||
@@ -15,9 +16,10 @@ internal fun KotlinSourceSet.checkForCircularDependsOnEdges(other: KotlinSourceS
|
|||||||
fun checkReachableRecursively(from: KotlinSourceSet) {
|
fun checkReachableRecursively(from: KotlinSourceSet) {
|
||||||
if (!visited.add(from)) return
|
if (!visited.add(from)) return
|
||||||
stack += from
|
stack += from
|
||||||
if (this == from) throw InvalidUserCodeException(
|
if (this == from) {
|
||||||
"Circular dependsOn hierarchy found in the Kotlin source sets: ${(stack.toList()).joinToString(" -> ") { it.name }}"
|
// 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) }
|
from.dependsOn.forEach { next -> checkReachableRecursively(next) }
|
||||||
stack -= from
|
stack -= from
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user