[mpp] Migrate HMPP-flags deprecations to the new infra
This commit is contained in:
committed by
Space Team
parent
29223dbd4a
commit
a539db932c
+7
-11
@@ -6,12 +6,12 @@
|
||||
package org.jetbrains.kotlin.gradle.mpp
|
||||
|
||||
import org.gradle.util.GradleVersion
|
||||
import org.jetbrains.kotlin.gradle.plugin.diagnostics.KotlinToolingDiagnostics
|
||||
import org.jetbrains.kotlin.gradle.testbase.*
|
||||
import org.jetbrains.kotlin.gradle.util.replaceText
|
||||
import org.jetbrains.kotlin.test.TestMetadata
|
||||
import kotlin.io.path.appendText
|
||||
import kotlin.io.path.writeText
|
||||
import kotlin.test.assertFalse
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
@MppGradlePluginTests
|
||||
class MppDiagnosticsIt : KGPBaseTest() {
|
||||
@@ -49,6 +49,7 @@ class MppDiagnosticsIt : KGPBaseTest() {
|
||||
}
|
||||
|
||||
@GradleTest
|
||||
@TestMetadata("new-mpp-lib-and-app/sample-lib-gradle-kotlin-dsl")
|
||||
fun testReportTargetsOfTheSamplePlatformAndWithTheSameAttributes(gradleVersion: GradleVersion) {
|
||||
project("new-mpp-lib-and-app/sample-lib-gradle-kotlin-dsl", gradleVersion) {
|
||||
// A hack to make project compatible with GradleTestKit infrastructure
|
||||
@@ -89,15 +90,10 @@ class MppDiagnosticsIt : KGPBaseTest() {
|
||||
|
||||
private fun TestProject.checkDeprecatedProperties(isDeprecationExpected: Boolean) {
|
||||
build {
|
||||
val assert: (Boolean, String) -> Unit = if (isDeprecationExpected) ::assertTrue else ::assertFalse
|
||||
val warnings = output.lines().filter { it.startsWith("w:") }.toSet()
|
||||
|
||||
defaultFlags.keys.forEach { flag ->
|
||||
assert(
|
||||
warnings.any { warning -> Regex(".*$flag.*is obsolete.*").matches(warning) },
|
||||
"A deprecation warning for the '$flag' should have been reported",
|
||||
)
|
||||
}
|
||||
if (isDeprecationExpected)
|
||||
output.assertHasDiagnostic(KotlinToolingDiagnostics.HierarchicalMultiplatformFlagsWarning)
|
||||
else
|
||||
output.assertNoDiagnostic(KotlinToolingDiagnostics.HierarchicalMultiplatformFlagsWarning)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.gradle.plugin.diagnostics
|
||||
|
||||
import org.jetbrains.kotlin.gradle.InternalKotlinGradlePluginApi
|
||||
import org.jetbrains.kotlin.gradle.plugin.diagnostics.ToolingDiagnostic.Severity.WARNING
|
||||
|
||||
@InternalKotlinGradlePluginApi // used in integration tests
|
||||
object KotlinToolingDiagnostics {
|
||||
object HierarchicalMultiplatformFlagsWarning : ToolingDiagnosticFactory(WARNING) {
|
||||
operator fun invoke(usedDeprecatedFlags: List<String>) = build(
|
||||
"The following properties are obsolete and will be removed in Kotlin 1.9.20:\n" +
|
||||
"${usedDeprecatedFlags.joinToString()}\n" +
|
||||
"Read the details here: https://kotlinlang.org/docs/multiplatform-compatibility-guide.html#deprecate-hmpp-properties",
|
||||
)
|
||||
}
|
||||
}
|
||||
+9
-43
@@ -6,45 +6,29 @@
|
||||
package org.jetbrains.kotlin.gradle.plugin.mpp.internal
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
|
||||
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
|
||||
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtensionOrNull
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet.Companion.COMMON_MAIN_SOURCE_SET_NAME
|
||||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.Companion.kotlinPropertiesProvider
|
||||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_MPP_ENABLE_COMPATIBILITY_METADATA_VARIANT
|
||||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_MPP_ENABLE_GRANULAR_SOURCE_SETS_METADATA
|
||||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_MPP_HIERARCHICAL_STRUCTURE_BY_DEFAULT
|
||||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_MPP_HIERARCHICAL_STRUCTURE_SUPPORT
|
||||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_NATIVE_DEPENDENCY_PROPAGATION
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.internal
|
||||
import org.jetbrains.kotlin.gradle.plugin.diagnostics.KotlinToolingDiagnostics
|
||||
import org.jetbrains.kotlin.gradle.plugin.diagnostics.kotlinToolingDiagnosticsCollector
|
||||
import org.jetbrains.kotlin.gradle.utils.SingleWarningPerBuild
|
||||
import org.jetbrains.kotlin.gradle.utils.runProjectConfigurationHealthCheckWhenEvaluated
|
||||
import org.jetbrains.kotlin.gradle.utils.toMap
|
||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||
import org.jetbrains.kotlin.tooling.core.UnsafeApi
|
||||
|
||||
internal fun runDeprecationDiagnostics(project: Project) {
|
||||
checkAndReportDeprecatedMppProperties(project)
|
||||
handleHierarchicalStructureFlagsMigration(project)
|
||||
checkAndReportDeprecatedSourceSetsLayouts(project)
|
||||
project.runProjectConfigurationHealthCheckWhenEvaluated {
|
||||
checkAndReportDeprecatedNativeTargets(project)
|
||||
reportTargetsWithNonUniqueConsumableConfigurations(project)
|
||||
checkAndReportPreHmppDependenciesUsage(project)
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkAndReportDeprecatedNativeTargets(project: Project) {
|
||||
val targets = project.extensions.getByType(KotlinMultiplatformExtension::class.java).targets
|
||||
val usedDeprecatedTargets = targets.filter { it is KotlinNativeTarget && it.konanTarget in KonanTarget.deprecatedTargets }
|
||||
if (usedDeprecatedTargets.isEmpty()) return
|
||||
SingleWarningPerBuild.show(
|
||||
project,
|
||||
"w: The following deprecated Kotlin/Native targets were used in the project: ${usedDeprecatedTargets.joinToString { it.targetName }}"
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Report scenario when there are two targets of the same platform without distinguishing attribute
|
||||
*/
|
||||
@@ -87,34 +71,20 @@ private fun checkAndReportDeprecatedMppProperties(project: Project) {
|
||||
val projectProperties = project.kotlinPropertiesProvider
|
||||
if (projectProperties.ignoreHmppDeprecationWarnings == true) return
|
||||
|
||||
val warnings = deprecatedMppProperties.mapNotNull { propertyName ->
|
||||
val usedProperties = deprecatedMppProperties.mapNotNull { propertyName ->
|
||||
if (propertyName in propertiesSetByPlugin && projectProperties.mpp13XFlagsSetByPlugin)
|
||||
return@mapNotNull null
|
||||
|
||||
@OptIn(UnsafeApi::class)
|
||||
projectProperties.property(propertyName)?.let { getMppDeprecationWarningMessageForProperty(propertyName) }
|
||||
propertyName.takeIf { projectProperties.property(propertyName) != null }
|
||||
}
|
||||
|
||||
warnings.forEach { message ->
|
||||
SingleWarningPerBuild.show(project, message)
|
||||
}
|
||||
}
|
||||
if (usedProperties.isEmpty()) return
|
||||
|
||||
private fun checkAndReportDeprecatedSourceSetsLayouts(project: Project) {
|
||||
project.reportCommonMainDependsOnOtherSourceSets()
|
||||
}
|
||||
|
||||
private fun Project.reportCommonMainDependsOnOtherSourceSets() {
|
||||
multiplatformExtensionOrNull?.sourceSets?.all {
|
||||
if (it.name == COMMON_MAIN_SOURCE_SET_NAME) {
|
||||
it.internal.dependsOn.forAll {
|
||||
SingleWarningPerBuild.show(
|
||||
project,
|
||||
"w: 'commonMain' source set can't depend on other source sets."
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
project.kotlinToolingDiagnosticsCollector.reportOncePerGradleBuild(
|
||||
project,
|
||||
KotlinToolingDiagnostics.HierarchicalMultiplatformFlagsWarning(usedProperties)
|
||||
)
|
||||
}
|
||||
|
||||
internal val deprecatedMppProperties: List<String> = listOf(
|
||||
@@ -129,7 +99,3 @@ private val propertiesSetByPlugin: Set<String> = setOf(
|
||||
KOTLIN_MPP_ENABLE_GRANULAR_SOURCE_SETS_METADATA,
|
||||
KOTLIN_NATIVE_DEPENDENCY_PROPAGATION,
|
||||
)
|
||||
|
||||
internal fun getMppDeprecationWarningMessageForProperty(property: String): String =
|
||||
"w: The property '$property' is obsolete and will be removed in Kotlin 1.9.20. Read the details here: " +
|
||||
"https://kotlinlang.org/docs/multiplatform-compatibility-guide.html#deprecate-hmpp-properties"
|
||||
|
||||
Reference in New Issue
Block a user