[mpp] Report commonTest with dependsOn similarly to commonMain

^KT-60556
This commit is contained in:
Dmitry Savvinov
2023-07-26 19:29:54 +02:00
committed by Space Team
parent 890e53b8e7
commit c9b7063d96
7 changed files with 33 additions and 16 deletions
@@ -6,7 +6,7 @@ kotlin.mpp.enableCompatibilityMetadataVariant, kotlin.mpp.hierarchicalStructureS
Read the details here: https://kotlinlang.org/docs/multiplatform-compatibility-guide.html#deprecate-hmpp-properties
#diagnostic-end
e: [CommonMainWithDependsOnDiagnostic | ERROR] commonMain can't declare dependsOn on other source sets
e: [CommonMainOrTestWithDependsOnDiagnostic | ERROR] commonMain can't declare dependsOn on other source sets
#diagnostic-end
w: [KotlinDefaultHierarchyFallbackDependsOnUsageDetected | WARNING] The Default Kotlin Hierarchy was not applied to 'project ':subprojectA'':
@@ -20,7 +20,7 @@ to your gradle.properties
> Configure project :subprojectB
e: [CommonMainWithDependsOnDiagnostic | ERROR] commonMain can't declare dependsOn on other source sets
e: [CommonMainOrTestWithDependsOnDiagnostic | ERROR] commonMain can't declare dependsOn on other source sets
#diagnostic-end
w: [KotlinDefaultHierarchyFallbackDependsOnUsageDetected | WARNING] The Default Kotlin Hierarchy was not applied to 'project ':subprojectB'':
@@ -97,7 +97,7 @@ internal interface KotlinGradleProjectChecker {
companion object {
val ALL_CHECKERS: List<KotlinGradleProjectChecker> = listOf(
CommonMainWithDependsOnChecker,
CommonMainOrTestWithDependsOnChecker,
DeprecatedKotlinNativeTargetsChecker,
MissingNativeStdlibChecker,
UnusedSourceSetsChecker,
@@ -35,8 +35,8 @@ object KotlinToolingDiagnostics {
)
}
object CommonMainWithDependsOnDiagnostic : ToolingDiagnosticFactory(ERROR) {
operator fun invoke() = build("commonMain can't declare dependsOn on other source sets")
object CommonMainOrTestWithDependsOnDiagnostic : ToolingDiagnosticFactory(ERROR) {
operator fun invoke(suffix: String) = build("common$suffix can't declare dependsOn on other source sets")
}
object NativeStdlibIsMissingDiagnostic : ToolingDiagnosticFactory(WARNING) {
@@ -587,4 +587,4 @@ private fun String.indentLines(nSpaces: Int = 4, skipFirstLine: Boolean = true):
if (skipFirstLine && index == 0) return@joinToString line
if (line.isNotBlank()) "$spaces$line" else line
}
}
}
@@ -6,19 +6,27 @@
package org.jetbrains.kotlin.gradle.plugin.diagnostics.checkers
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
import org.jetbrains.kotlin.gradle.plugin.diagnostics.KotlinToolingDiagnostics
import org.jetbrains.kotlin.gradle.plugin.diagnostics.KotlinToolingDiagnosticsCollector
import org.jetbrains.kotlin.gradle.plugin.diagnostics.KotlinGradleProjectChecker
import org.jetbrains.kotlin.gradle.plugin.diagnostics.KotlinGradleProjectCheckerContext
import org.jetbrains.kotlin.gradle.plugin.diagnostics.KotlinToolingDiagnostics
import org.jetbrains.kotlin.gradle.plugin.diagnostics.KotlinToolingDiagnosticsCollector
import org.jetbrains.kotlin.gradle.plugin.sources.internal
internal object CommonMainWithDependsOnChecker : KotlinGradleProjectChecker {
internal object CommonMainOrTestWithDependsOnChecker : KotlinGradleProjectChecker {
override suspend fun KotlinGradleProjectCheckerContext.runChecks(collector: KotlinToolingDiagnosticsCollector) {
fun KotlinSourceSet.registerReporting(suffix: String) {
internal.dependsOn.forAll {
collector.reportOncePerGradleProject(
project,
KotlinToolingDiagnostics.CommonMainOrTestWithDependsOnDiagnostic(suffix),
key = suffix
)
}
}
multiplatformExtension?.sourceSets?.all {
if (it.name == KotlinSourceSet.COMMON_MAIN_SOURCE_SET_NAME) {
it.internal.dependsOn.forAll {
collector.reportOncePerGradleProject(project, KotlinToolingDiagnostics.CommonMainWithDependsOnDiagnostic())
}
when (it.name) {
KotlinSourceSet.COMMON_MAIN_SOURCE_SET_NAME -> it.registerReporting("Main")
KotlinSourceSet.COMMON_TEST_SOURCE_SET_NAME -> it.registerReporting("Test")
}
}
}
@@ -14,8 +14,8 @@ import org.junit.Test
class MppDiagnosticsFunctionalTest {
@Test
fun testCommonMainWithDependsOn() {
checkDiagnosticsWithMppProject("commonMainWithDependsOn") {
fun testCommonMainOrTestWithDependsOn() {
checkDiagnosticsWithMppProject("commonMainOrTestWithDependsOn") {
kotlin {
jvm()
linuxX64()
@@ -29,6 +29,13 @@ class MppDiagnosticsFunctionalTest {
dependsOn(myCustomCommonMain)
dependsOn(myCustomCommonMain2) // check that diagnostic isn't duplicated
}
val myCustomCommonTest = create("myCustomCommonTest")
val myCustomCommonTest2 = create("myCustomCommonTest2")
commonTest {
dependsOn(myCustomCommonTest)
dependsOn(myCustomCommonTest2) // check that diagnostic isn't duplicated
}
}
}
}
@@ -0,0 +1,3 @@
[CommonMainOrTestWithDependsOnDiagnostic | ERROR] commonMain can't declare dependsOn on other source sets
----
[CommonMainOrTestWithDependsOnDiagnostic | ERROR] commonTest can't declare dependsOn on other source sets
@@ -1 +0,0 @@
[CommonMainWithDependsOnDiagnostic | ERROR] commonMain can't declare dependsOn on other source sets