From 0238282c7b2b453b44ade7501d72bbea14d0c757 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petrus=20Nguy=E1=BB=85n=20Th=C3=A1i=20H=E1=BB=8Dc?= Date: Sat, 11 Nov 2023 15:47:00 +0700 Subject: [PATCH] Kotlin 1.9.20: new target hierarchy setup, opt in to 'expect'/'actual' classes (#193) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🎉🎉🎉🎉 --- build.gradle.kts | 148 ++++-------------- .../com/hoc081098/flowext/internal/Lock.kt | 0 .../com/hoc081098/flowext/internal/Lock.kt | 0 .../com/hoc081098/flowext/PairwiseTest.kt | 1 + .../com/hoc081098/flowext/SelectorsTest.kt | 3 - 5 files changed, 29 insertions(+), 123 deletions(-) rename src/{pthreadAndroidMain => androidNativeMain}/kotlin/com/hoc081098/flowext/internal/Lock.kt (100%) rename src/{darwinMain => appleMain}/kotlin/com/hoc081098/flowext/internal/Lock.kt (100%) diff --git a/build.gradle.kts b/build.gradle.kts index 664a81f9..9cf2d387 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,6 +5,7 @@ import org.gradle.api.tasks.testing.logging.TestExceptionFormat import org.gradle.api.tasks.testing.logging.TestLogEvent import org.jetbrains.dokka.gradle.DokkaTask import org.jetbrains.kotlin.gradle.dsl.JvmTarget +import org.jetbrains.kotlin.gradle.dsl.KotlinCompile import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithTests import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType import java.net.URL @@ -60,22 +61,18 @@ kotlin { } } browser { - testTask( - Action { - useMocha { - timeout = "10s" - } - }, - ) + testTask { + useMocha { + timeout = "10s" + } + } } nodejs { - testTask( - Action { - useMocha { - timeout = "10s" - } - }, - ) + testTask { + useMocha { + timeout = "10s" + } + } } } @@ -107,130 +104,28 @@ kotlin { androidNativeX64() sourceSets { - val commonMain by getting { + commonMain { dependencies { api("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion") } } - val commonTest by getting { + commonTest { dependencies { implementation(kotlin("test-common")) implementation(kotlin("test-annotations-common")) implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutinesVersion") } } - val jvmMain by getting { - dependsOn(commonMain) - } - val jvmTest by getting { - dependsOn(commonTest) - + jvmTest { dependencies { implementation(kotlin("test-junit")) } } - val jsMain by getting { - dependsOn(commonMain) - } - val jsTest by getting { + jsTest { dependencies { implementation(kotlin("test-js")) } } - - val nativeMain by creating { - dependsOn(commonMain) - } - val nativeTest by creating { - dependsOn(commonTest) - } - - val darwinMain by creating { - dependsOn(nativeMain) - } - val darwinTest by creating { - dependsOn(nativeTest) - } - - val linuxMain by creating { - dependsOn(nativeMain) - } - val linuxTest by creating { - dependsOn(nativeTest) - } - - val pthreadAndroidMain by creating { - dependsOn(nativeMain) - } - val pthreadAndroidTest by creating { - dependsOn(nativeTest) - } - - val appleTargets = - listOf( - "iosX64", - "iosSimulatorArm64", - "iosArm64", - "macosX64", - "macosArm64", - "tvosArm64", - "tvosX64", - "tvosSimulatorArm64", - "watchosArm32", - "watchosArm64", - "watchosSimulatorArm64", - "watchosX64", - "watchosSimulatorArm64", - "watchosDeviceArm64", - ) - - val linuxTargets = - listOf( - "linuxX64", - "linuxArm64", - ) - - val androidNativeTargets = - listOf( - "androidNativeArm32", - "androidNativeArm64", - "androidNativeX86", - "androidNativeX64", - ) - - appleTargets.forEach { - getByName("${it}Main") { - dependsOn(darwinMain) - } - getByName("${it}Test") { - dependsOn(darwinTest) - } - } - - linuxTargets.forEach { - getByName("${it}Main") { - dependsOn(linuxMain) - } - getByName("${it}Test") { - dependsOn(linuxTest) - } - } - - androidNativeTargets.forEach { - getByName("${it}Main") { - dependsOn(pthreadAndroidMain) - } - getByName("${it}Test") { - dependsOn(pthreadAndroidTest) - } - } - - getByName("mingwX64Main") { - dependsOn(nativeMain) - } - getByName("mingwX64Test") { - dependsOn(nativeTest) - } } // enable running ios tests on a background thread as well @@ -250,6 +145,19 @@ kotlin { } } +tasks.withType>().configureEach { + kotlinOptions { + // 'expect'/'actual' classes (including interfaces, objects, annotations, enums, + // and 'actual' typealiases) are in Beta. + // You can use -Xexpect-actual-classes flag to suppress this warning. + // Also see: https://youtrack.jetbrains.com/issue/KT-61573 + freeCompilerArgs += + listOf( + "-Xexpect-actual-classes", + ) + } +} + spotless { kotlin { target("**/*.kt") diff --git a/src/pthreadAndroidMain/kotlin/com/hoc081098/flowext/internal/Lock.kt b/src/androidNativeMain/kotlin/com/hoc081098/flowext/internal/Lock.kt similarity index 100% rename from src/pthreadAndroidMain/kotlin/com/hoc081098/flowext/internal/Lock.kt rename to src/androidNativeMain/kotlin/com/hoc081098/flowext/internal/Lock.kt diff --git a/src/darwinMain/kotlin/com/hoc081098/flowext/internal/Lock.kt b/src/appleMain/kotlin/com/hoc081098/flowext/internal/Lock.kt similarity index 100% rename from src/darwinMain/kotlin/com/hoc081098/flowext/internal/Lock.kt rename to src/appleMain/kotlin/com/hoc081098/flowext/internal/Lock.kt diff --git a/src/commonTest/kotlin/com/hoc081098/flowext/PairwiseTest.kt b/src/commonTest/kotlin/com/hoc081098/flowext/PairwiseTest.kt index 3ea7ff06..ce81b5f6 100644 --- a/src/commonTest/kotlin/com/hoc081098/flowext/PairwiseTest.kt +++ b/src/commonTest/kotlin/com/hoc081098/flowext/PairwiseTest.kt @@ -42,6 +42,7 @@ import kotlinx.coroutines.flow.take private data class MyTuple2(val first: A, val second: B) +@Suppress("NOTHING_TO_INLINE") private inline infix fun A.with(second: B) = MyTuple2(this, second) @ExperimentalCoroutinesApi diff --git a/src/commonTest/kotlin/com/hoc081098/flowext/SelectorsTest.kt b/src/commonTest/kotlin/com/hoc081098/flowext/SelectorsTest.kt index f44c2702..c4a52513 100644 --- a/src/commonTest/kotlin/com/hoc081098/flowext/SelectorsTest.kt +++ b/src/commonTest/kotlin/com/hoc081098/flowext/SelectorsTest.kt @@ -26,7 +26,6 @@ package com.hoc081098.flowext import com.hoc081098.flowext.utils.BaseTest import com.hoc081098.flowext.utils.test -import kotlin.native.concurrent.SharedImmutable import kotlin.test.Test import kotlin.test.assertEquals import kotlinx.coroutines.ExperimentalCoroutinesApi @@ -73,10 +72,8 @@ private fun Flow.scanSkipFirst( operation: suspend (acc: R, value: T) -> R, ): Flow = scan(initial, operation).drop(1) -@SharedImmutable private val zeroToTen = List(10) { it.toString() } -@SharedImmutable private val reducer: (acc: State, value: Int) -> State = { state, action -> when (action) { // items