Browse Source

Check Wasm compatibility with Kotlin

igor.demin/wasm-kotlin-compatibility
Igor Demin 3 months ago
parent
commit
06f461a120
  1. 41
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposeKotlinCompatibility.kt
  2. 9
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposePlugin.kt
  3. 79
      gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/KotlinCompatibilityUnitTest.kt

41
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposeKotlinCompatibility.kt

@ -0,0 +1,41 @@
package org.jetbrains.compose
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
internal object ComposeKotlinCompatibility {
fun checkKotlinIsSupported(kotlinVersion: String, kotlinPlatformType: KotlinPlatformType) {
val kotlinVersion = kotlinVersion.parseVersionOrNull()
when(kotlinPlatformType) {
KotlinPlatformType.wasm -> check(
kotlinVersion == null ||
kotlinVersion.major == 0 ||
kotlinVersion > Version(1, 9, 21)
) {
"Compose Multiplatform ${ComposeBuildConfig.composeGradlePluginVersion} doesn't support Kotlin " +
"$kotlinVersion. Minimal supported version is 1.9.22"
}
else -> Unit
}
}
}
// parse only simple numbers, as we need only them, not whole semantic versioning checks
private fun String.parseVersionOrNull(): Version? {
val parts = split(".")
return Version(
parts.getOrNull(0)?.toIntOrNull() ?: return null,
parts.getOrNull(1)?.toIntOrNull() ?: return null,
parts.getOrNull(2)?.toIntOrNull() ?: return null,
)
}
private class Version(val major: Int, val minor: Int, val patch: Int) : Comparable<Version> {
override fun compareTo(other: Version) = compareValuesBy(
this,
other,
{ it.major },
{ it.minor },
{ it.patch },
)
}

9
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposePlugin.kt

@ -121,6 +121,15 @@ abstract class ComposePlugin : Plugin<Project> {
}
}
private fun checkKotlinIsSupported(project: Project) {
project.mppExtOrNull?.targets?.forEach {
ComposeKotlinCompatibility.checkKotlinIsSupported(
it.project.getKotlinPluginVersion(),
it.platformType
)
}
}
@Suppress("DEPRECATION")
class Dependencies(project: Project) {
val desktop = DesktopDependencies

79
gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/KotlinCompatibilityUnitTest.kt

@ -0,0 +1,79 @@
package org.jetbrains.compose.test.tests.integration
import org.jetbrains.compose.ComposeKotlinCompatibility
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
class KotlinCompatibilityUnitTest {
@Test
fun jvm() {
ComposeKotlinCompatibility.checkKotlinIsSupported("1.9.21", KotlinPlatformType.jvm)
ComposeKotlinCompatibility.checkKotlinIsSupported("1.9.22", KotlinPlatformType.jvm)
ComposeKotlinCompatibility.checkKotlinIsSupported("2.0.0-Beta", KotlinPlatformType.jvm)
ComposeKotlinCompatibility.checkKotlinIsSupported("2.0.0-Beta2", KotlinPlatformType.jvm)
ComposeKotlinCompatibility.checkKotlinIsSupported("fdsfsf", KotlinPlatformType.jvm)
ComposeKotlinCompatibility.checkKotlinIsSupported("fdsfsf", KotlinPlatformType.jvm)
}
@Test
fun wasm000() {
ComposeKotlinCompatibility.checkKotlinIsSupported("0.0.0", KotlinPlatformType.wasm)
}
@Test
fun wasmabc() {
ComposeKotlinCompatibility.checkKotlinIsSupported("abc", KotlinPlatformType.wasm)
}
@Test
fun wasm000something() {
ComposeKotlinCompatibility.checkKotlinIsSupported("0.0.0-something", KotlinPlatformType.wasm)
}
@Test
fun wasm0040() {
ComposeKotlinCompatibility.checkKotlinIsSupported("0.0.40", KotlinPlatformType.wasm)
}
@Test
fun wasm000SNAPSHOT() {
ComposeKotlinCompatibility.checkKotlinIsSupported("0.0.0-SNAPSHOT", KotlinPlatformType.wasm)
}
@Test
fun wasm1821() {
assertThrows<IllegalStateException> {
ComposeKotlinCompatibility.checkKotlinIsSupported("1.8.21", KotlinPlatformType.wasm)
}
}
@Test
fun wasm1822() {
assertThrows<IllegalStateException> {
ComposeKotlinCompatibility.checkKotlinIsSupported("1.8.22", KotlinPlatformType.wasm)
}
}
@Test
fun wasm1921() {
assertThrows<IllegalStateException> {
ComposeKotlinCompatibility.checkKotlinIsSupported("1.9.21", KotlinPlatformType.wasm)
}
}
@Test
fun wasm1922() {
ComposeKotlinCompatibility.checkKotlinIsSupported("1.9.22", KotlinPlatformType.wasm)
}
@Test
fun wasm200Beta() {
ComposeKotlinCompatibility.checkKotlinIsSupported("2.0.0-Beta", KotlinPlatformType.wasm)
}
@Test
fun wasm200Beta1() {
ComposeKotlinCompatibility.checkKotlinIsSupported("2.0.0-Beta1", KotlinPlatformType.wasm)
}
}
Loading…
Cancel
Save