[Gradle] Migrate unrecognized K/N distro warning

This commit is contained in:
Dmitry Savvinov
2023-03-27 16:36:40 +02:00
parent d9b7130f4b
commit 4f309c0c8f
2 changed files with 13 additions and 6 deletions
@@ -203,4 +203,11 @@ object KotlinToolingDiagnostics {
"Project property '$deprecatedPropertyName' is deprecated. Please use '$replacement' instead."
)
}
object UnrecognizedKotlinNativeDistributionType : ToolingDiagnosticFactory(WARNING) {
operator fun invoke(actualValue: String) = build(
"Gradle Property 'kotlin.native.distribution.type' sets unknown Kotlin/Native distribution type: ${actualValue}\n" +
"Available values: prebuilt, light"
)
}
}
@@ -7,8 +7,10 @@ package org.jetbrains.kotlin.gradle.targets.native.internal
import org.gradle.api.Project
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider
import org.jetbrains.kotlin.gradle.targets.native.internal.NativeDistributionType.*
import org.jetbrains.kotlin.gradle.utils.SingleWarningPerBuild
import org.jetbrains.kotlin.gradle.plugin.diagnostics.KotlinToolingDiagnostics
import org.jetbrains.kotlin.gradle.plugin.diagnostics.reportDiagnosticOncePerBuild
import org.jetbrains.kotlin.gradle.targets.native.internal.NativeDistributionType.LIGHT
import org.jetbrains.kotlin.gradle.targets.native.internal.NativeDistributionType.PREBUILT
import org.jetbrains.kotlin.util.capitalizeDecapitalize.toLowerCaseAsciiOnly
internal enum class NativeDistributionType(val suffix: String?, val mustGeneratePlatformLibs: Boolean) {
@@ -19,15 +21,13 @@ internal enum class NativeDistributionType(val suffix: String?, val mustGenerate
internal class NativeDistributionTypeProvider(private val project: Project) {
private val propertiesProvider = PropertiesProvider(project)
private fun warning(message: String) = SingleWarningPerBuild.show(project, "Warning: $message")
fun getDistributionType(): NativeDistributionType {
return when (propertiesProvider.nativeDistributionType?.toLowerCaseAsciiOnly()) {
return when (val type = propertiesProvider.nativeDistributionType?.toLowerCaseAsciiOnly()) {
null -> PREBUILT
"prebuilt" -> PREBUILT
"light" -> LIGHT
else -> {
warning("Unknown Kotlin/Native distribution type: ${propertiesProvider.nativeDistributionType?.toLowerCaseAsciiOnly()}. Available values: prebuilt, light")
project.reportDiagnosticOncePerBuild(KotlinToolingDiagnostics.UnrecognizedKotlinNativeDistributionType(type))
PREBUILT
}
}