From 84d64c05fe3a6bcdd49c2d095047d68d1b642b52 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Mena Date: Wed, 15 Nov 2023 15:34:35 +0100 Subject: [PATCH 01/14] First draft of Arrow Optics + Compose --- .../api/android/arrow-optics-compose.api | 17 ++++ .../api/jvm/arrow-optics-compose.api | 17 ++++ .../arrow-optics-compose/build.gradle.kts | 83 +++++++++++++++++++ .../arrow-optics-compose/gradle.properties | 4 + .../commonMain/kotlin/arrow/optics/Copy.kt | 29 +++++++ .../commonMain/kotlin/arrow/optics/Flow.kt | 70 ++++++++++++++++ .../commonMain/kotlin/arrow/optics/State.kt | 27 ++++++ build.gradle.kts | 2 + gradle.properties | 4 +- gradle/libs.versions.toml | 7 ++ settings.gradle.kts | 5 ++ 11 files changed, 264 insertions(+), 1 deletion(-) create mode 100644 arrow-libs/optics/arrow-optics-compose/api/android/arrow-optics-compose.api create mode 100644 arrow-libs/optics/arrow-optics-compose/api/jvm/arrow-optics-compose.api create mode 100644 arrow-libs/optics/arrow-optics-compose/build.gradle.kts create mode 100644 arrow-libs/optics/arrow-optics-compose/gradle.properties create mode 100644 arrow-libs/optics/arrow-optics-compose/src/commonMain/kotlin/arrow/optics/Copy.kt create mode 100644 arrow-libs/optics/arrow-optics-compose/src/commonMain/kotlin/arrow/optics/Flow.kt create mode 100644 arrow-libs/optics/arrow-optics-compose/src/commonMain/kotlin/arrow/optics/State.kt diff --git a/arrow-libs/optics/arrow-optics-compose/api/android/arrow-optics-compose.api b/arrow-libs/optics/arrow-optics-compose/api/android/arrow-optics-compose.api new file mode 100644 index 00000000000..31d871ddeda --- /dev/null +++ b/arrow-libs/optics/arrow-optics-compose/api/android/arrow-optics-compose.api @@ -0,0 +1,17 @@ +public final class arrow/optics/CopyKt { + public static final fun update (Landroidx/compose/runtime/MutableState;Lkotlin/jvm/functions/Function1;)V + public static final fun updateCopy (Landroidx/compose/runtime/MutableState;Lkotlin/jvm/functions/Function1;)V + public static final fun updateCopy (Lkotlinx/coroutines/flow/MutableStateFlow;Lkotlin/jvm/functions/Function1;)V +} + +public final class arrow/optics/FlowKt { + public static final fun optic (Lkotlinx/coroutines/flow/MutableStateFlow;Larrow/optics/PLens;)Lkotlinx/coroutines/flow/MutableStateFlow; + public static final fun optic (Lkotlinx/coroutines/flow/SharedFlow;Larrow/optics/Getter;)Lkotlinx/coroutines/flow/SharedFlow; + public static final fun optic (Lkotlinx/coroutines/flow/StateFlow;Larrow/optics/Getter;)Lkotlinx/coroutines/flow/StateFlow; +} + +public final class arrow/optics/StateKt { + public static final fun optic (Landroidx/compose/runtime/MutableState;Larrow/optics/PLens;)Landroidx/compose/runtime/MutableState; + public static final fun optic (Landroidx/compose/runtime/State;Larrow/optics/Getter;)Landroidx/compose/runtime/State; +} + diff --git a/arrow-libs/optics/arrow-optics-compose/api/jvm/arrow-optics-compose.api b/arrow-libs/optics/arrow-optics-compose/api/jvm/arrow-optics-compose.api new file mode 100644 index 00000000000..31d871ddeda --- /dev/null +++ b/arrow-libs/optics/arrow-optics-compose/api/jvm/arrow-optics-compose.api @@ -0,0 +1,17 @@ +public final class arrow/optics/CopyKt { + public static final fun update (Landroidx/compose/runtime/MutableState;Lkotlin/jvm/functions/Function1;)V + public static final fun updateCopy (Landroidx/compose/runtime/MutableState;Lkotlin/jvm/functions/Function1;)V + public static final fun updateCopy (Lkotlinx/coroutines/flow/MutableStateFlow;Lkotlin/jvm/functions/Function1;)V +} + +public final class arrow/optics/FlowKt { + public static final fun optic (Lkotlinx/coroutines/flow/MutableStateFlow;Larrow/optics/PLens;)Lkotlinx/coroutines/flow/MutableStateFlow; + public static final fun optic (Lkotlinx/coroutines/flow/SharedFlow;Larrow/optics/Getter;)Lkotlinx/coroutines/flow/SharedFlow; + public static final fun optic (Lkotlinx/coroutines/flow/StateFlow;Larrow/optics/Getter;)Lkotlinx/coroutines/flow/StateFlow; +} + +public final class arrow/optics/StateKt { + public static final fun optic (Landroidx/compose/runtime/MutableState;Larrow/optics/PLens;)Landroidx/compose/runtime/MutableState; + public static final fun optic (Landroidx/compose/runtime/State;Larrow/optics/Getter;)Landroidx/compose/runtime/State; +} + diff --git a/arrow-libs/optics/arrow-optics-compose/build.gradle.kts b/arrow-libs/optics/arrow-optics-compose/build.gradle.kts new file mode 100644 index 00000000000..6f7ae7fb697 --- /dev/null +++ b/arrow-libs/optics/arrow-optics-compose/build.gradle.kts @@ -0,0 +1,83 @@ +@file:Suppress("DSL_SCOPE_VIOLATION") + +repositories { + google() + mavenCentral() + maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") +} + +plugins { + id(libs.plugins.kotlin.multiplatform.get().pluginId) + // alias(libs.plugins.arrowGradleConfig.kotlin) + alias(libs.plugins.arrowGradleConfig.publish) + alias(libs.plugins.spotless) + alias(libs.plugins.jetbrainsCompose) + alias(libs.plugins.android.library) +} + +apply(from = property("ANIMALSNIFFER_MPP")) + +kotlin { + explicitApi() + + jvm { + jvmToolchain(8) + } + js(IR) { + browser() + nodejs() + } + androidTarget() + // Native: https://kotlinlang.org/docs/native-target-support.html + // -- Tier 1 -- + linuxX64() + macosX64() + macosArm64() + iosSimulatorArm64() + iosX64() + // -- Tier 2 -- + // linuxArm64() + watchosSimulatorArm64() + watchosX64() + watchosArm64() + tvosSimulatorArm64() + tvosX64() + tvosArm64() + iosArm64() + // -- Tier 3 -- + mingwX64() + + sourceSets { + commonMain { + dependencies { + api(projects.arrowOptics) + api(libs.coroutines.core) + api(compose.runtime) + implementation(libs.kotlin.stdlibCommon) + } + } + + commonTest { + dependencies { + implementation(libs.kotlin.test) + implementation(libs.kotest.assertionsCore) + implementation(libs.kotest.property) + } + } + } +} + +tasks.withType { + useJUnitPlatform() +} + +android { + namespace = "arrow.optics.compose" + compileSdk = libs.versions.android.compileSdk.get().toInt() +} + +tasks.named("jvmJar").configure { + manifest { + attributes["Automatic-Module-Name"] = "arrow.optics.compose" + } +} diff --git a/arrow-libs/optics/arrow-optics-compose/gradle.properties b/arrow-libs/optics/arrow-optics-compose/gradle.properties new file mode 100644 index 00000000000..d569b6effb4 --- /dev/null +++ b/arrow-libs/optics/arrow-optics-compose/gradle.properties @@ -0,0 +1,4 @@ +# Maven publishing configuration +pom.name=Arrow Optics for Compose +# Build configuration +kapt.incremental.apt=false \ No newline at end of file diff --git a/arrow-libs/optics/arrow-optics-compose/src/commonMain/kotlin/arrow/optics/Copy.kt b/arrow-libs/optics/arrow-optics-compose/src/commonMain/kotlin/arrow/optics/Copy.kt new file mode 100644 index 00000000000..1cc26c41b95 --- /dev/null +++ b/arrow-libs/optics/arrow-optics-compose/src/commonMain/kotlin/arrow/optics/Copy.kt @@ -0,0 +1,29 @@ +package arrow.optics + +import androidx.compose.runtime.MutableState +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.update + +/** + * Modifies the value in this [MutableState] + * by applying the function [block] to the current value. + */ +public inline fun MutableState.update(block: (T) -> T) { + value = block(value) +} + +/** + * Modifies the value in this [MutableState] + * by performing the operations in the [Copy] [block]. + */ +public fun MutableState.updateCopy(block: Copy.() -> Unit) { + update { it.copy(block) } +} + +/** + * Updates the value in this [MutableStateFlow] + * by performing the operations in the [Copy] [block]. + */ +public fun MutableStateFlow.updateCopy(block: Copy.() -> Unit) { + update { it.copy(block) } +} diff --git a/arrow-libs/optics/arrow-optics-compose/src/commonMain/kotlin/arrow/optics/Flow.kt b/arrow-libs/optics/arrow-optics-compose/src/commonMain/kotlin/arrow/optics/Flow.kt new file mode 100644 index 00000000000..30902538cca --- /dev/null +++ b/arrow-libs/optics/arrow-optics-compose/src/commonMain/kotlin/arrow/optics/Flow.kt @@ -0,0 +1,70 @@ +package arrow.optics + +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.flow.FlowCollector +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.SharedFlow +import kotlinx.coroutines.flow.StateFlow + +/** + * Exposes the values of [this] through the optic. + */ +public fun SharedFlow.optic(g: Getter): SharedFlow = object : SharedFlow { + override suspend fun collect(collector: FlowCollector): Nothing = + this@optic.collect { collector.emit(g.get(it)) } + + override val replayCache: List + get() = this@optic.replayCache.map { g.get(it) } +} + +/** + * Exposes the values of [this] through the optic. + */ +public fun StateFlow.optic(g: Getter): StateFlow = object : StateFlow { + override val value: A + get() = g.get(this@optic.value) + + override suspend fun collect(collector: FlowCollector): Nothing = + this@optic.collect { collector.emit(g.get(it)) } + + override val replayCache: List + get() = this@optic.replayCache.map { g.get(it) } +} + +/** + * Exposes the values of [this] through the optic. + * Any change made to [value] is reflected in the original [MutableStateFlow]. + */ +public fun MutableStateFlow.optic(lens: Lens): MutableStateFlow = object : MutableStateFlow { + override var value: A + get() = lens.get(this@optic.value) + set(newValue) { + this@optic.value = lens.set(this@optic.value, newValue) + } + + override suspend fun collect(collector: FlowCollector): Nothing = + this@optic.collect { collector.emit(lens.get(it)) } + + override fun compareAndSet(expect: A, update: A): Boolean { + val expectT = lens.set(this@optic.value, expect) + val updateT = lens.set(this@optic.value, update) + return compareAndSet(expectT, updateT) + } + + override fun tryEmit(value: A): Boolean = + this@optic.tryEmit(lens.set(this@optic.value, value)) + + override suspend fun emit(value: A): Unit = + this@optic.emit(lens.set(this@optic.value, value)) + + override val subscriptionCount: StateFlow + get() = this@optic.subscriptionCount + + override val replayCache: List + get() = this@optic.replayCache.map { lens.get(it) } + + @ExperimentalCoroutinesApi + override fun resetReplayCache() { + this@optic.resetReplayCache() + } +} diff --git a/arrow-libs/optics/arrow-optics-compose/src/commonMain/kotlin/arrow/optics/State.kt b/arrow-libs/optics/arrow-optics-compose/src/commonMain/kotlin/arrow/optics/State.kt new file mode 100644 index 00000000000..9fc93058b31 --- /dev/null +++ b/arrow-libs/optics/arrow-optics-compose/src/commonMain/kotlin/arrow/optics/State.kt @@ -0,0 +1,27 @@ +package arrow.optics + +import androidx.compose.runtime.MutableState +import androidx.compose.runtime.State + +/** + * Exposes the value of [this] through the optic. + */ +public fun State.optic(g: Getter): State = object : State { + override val value: A + get() = g.get(this@optic.value) +} + +/** + * Exposes the value of [this] through the optic. + * Any change made to [value] is reflected in the original [MutableState]. + */ +public fun MutableState.optic(lens: Lens): MutableState = object : MutableState { + override var value: A + get() = lens.get(this@optic.value) + set(newValue) { + this@optic.value = lens.set(this@optic.value, newValue) + } + + override fun component1(): A = value + override fun component2(): (A) -> Unit = { value = it } +} diff --git a/build.gradle.kts b/build.gradle.kts index c83b401be48..04d0bef23c5 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -37,6 +37,7 @@ allprojects { plugins { base + alias(libs.plugins.android.library) apply false alias(libs.plugins.dokka) alias(libs.plugins.animalSniffer) apply false alias(libs.plugins.kotest.multiplatform) apply false @@ -46,6 +47,7 @@ plugins { alias(libs.plugins.kotlin.binaryCompatibilityValidator) alias(libs.plugins.arrowGradleConfig.nexus) alias(libs.plugins.spotless) apply false + alias(libs.plugins.jetbrainsCompose) apply false } apply(plugin = libs.plugins.kotlinx.knit.get().pluginId) diff --git a/gradle.properties b/gradle.properties index 2f87e20b88c..4bc9a0ebb16 100644 --- a/gradle.properties +++ b/gradle.properties @@ -26,7 +26,7 @@ kotlin.mpp.stability.nowarn=true # https://youtrack.jetbrains.com/issue/KT-32476 kotlin.native.ignoreIncorrectDependencies=true kotlin.native.ignoreDisabledTargets=true -kotlin.native.cacheKind.linuxX64=none +# kotlin.native.cacheKind.linuxX64=none # https://youtrack.jetbrains.com/issue/KT-45545#focus=Comments-27-4773544.0-0 kapt.use.worker.api=false kotlin.mpp.applyDefaultHierarchyTemplate=false @@ -37,3 +37,5 @@ ANIMALSNIFFER=../../gradle/animalsniffer.gradle ANIMALSNIFFER_MPP=../../gradle/animalsniffer-mpp.gradle dokkaEnabled=false + +android.useAndroidX=true \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 7ccf8d238cc..33b576e08e8 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -22,6 +22,10 @@ mockWebServer = "4.12.0" retrofit = "2.9.0" retrofitKotlinxSerialization = "1.0.0" spotlessVersion = "6.22.0" +compose = "1.5.4" +composePlugin = "1.5.10" +agp = "8.1.3" +android-compileSdk = "34" [libraries] coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" } @@ -53,6 +57,7 @@ assertj = { module = "org.assertj:assertj-core", version.ref = "assertj" } classgraph = { module = "io.github.classgraph:classgraph", version.ref = "classgraph" } kotlinCompileTesting = { module = "com.github.tschuchortdev:kotlin-compile-testing", version.ref = "kotlinCompileTesting" } kotlinCompileTestingKsp = { module = "com.github.tschuchortdev:kotlin-compile-testing-ksp", version.ref = "kotlinCompileTesting" } +compose-runtime = { module = "androidx.compose.runtime:runtime", version.ref = "compose" } [plugins] animalSniffer = { id = "ru.vyarus.animalsniffer", version.ref = "animalSniffer" } @@ -71,3 +76,5 @@ kotlinx-kover = { id = "org.jetbrains.kotlinx.kover", version.ref = "kover" } kotlinx-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlinxSerializationPlugin" } ksp = { id = "com.google.devtools.ksp", version.ref = "kspVersion" } spotless = { id = "com.diffplug.spotless", version.ref = "spotlessVersion" } +jetbrainsCompose = { id = "org.jetbrains.compose", version.ref = "composePlugin" } +android-library = { id = "com.android.library", version.ref = "agp" } diff --git a/settings.gradle.kts b/settings.gradle.kts index 3957a87e1a0..622c3cf0d9f 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -9,6 +9,8 @@ pluginManagement { mavenCentral() mavenLocal() kotlin_repo_url?.also { maven(it) } + google() + maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") } } @@ -73,6 +75,9 @@ project(":arrow-optics").projectDir = file("arrow-libs/optics/arrow-optics") include("arrow-optics-reflect") project(":arrow-optics-reflect").projectDir = file("arrow-libs/optics/arrow-optics-reflect") +include("arrow-optics-compose") +project(":arrow-optics-compose").projectDir = file("arrow-libs/optics/arrow-optics-compose") + include("arrow-optics-ksp-plugin") project(":arrow-optics-ksp-plugin").projectDir = file("arrow-libs/optics/arrow-optics-ksp-plugin") From 2270eb283d299f84649220ae39b50e9b031c0a07 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Mena Date: Wed, 15 Nov 2023 16:24:22 +0100 Subject: [PATCH 02/14] Use Java 17 in GitHub Actions --- .github/workflows/publish.yml | 4 +-- .github/workflows/pull_request.yml | 40 +++++++++++++++--------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index cc2fd9e2624..703110b1ded 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -32,8 +32,8 @@ jobs: - name: Set up Java uses: actions/setup-java@v3 with: - distribution: 'zulu' - java-version: 11 + distribution: 'temurin' + java-version: 17 - name: assemble uses: gradle/gradle-build-action@v2 diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 831e18ae9ff..b6fc48e7406 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -22,8 +22,8 @@ jobs: - name: Set up Java uses: actions/setup-java@v3 with: - distribution: 'zulu' - java-version: 11 + distribution: 'temurin' + java-version: 17 - name: ios and watchos tests uses: gradle/gradle-build-action@v2 @@ -49,8 +49,8 @@ jobs: - name: Set up Java uses: actions/setup-java@v3 with: - distribution: 'zulu' - java-version: 11 + distribution: 'temurin' + java-version: 17 - name: macos and tvos tests uses: gradle/gradle-build-action@v2 @@ -76,8 +76,8 @@ jobs: - name: Set up Java uses: actions/setup-java@v3 with: - distribution: 'zulu' - java-version: 11 + distribution: 'temurin' + java-version: 17 - name: mingwX64Test uses: gradle/gradle-build-action@v2 @@ -103,8 +103,8 @@ jobs: - name: Set up Java uses: actions/setup-java@v3 with: - distribution: 'zulu' - java-version: 11 + distribution: 'temurin' + java-version: 17 - name: check uses: gradle/gradle-build-action@v2 @@ -130,8 +130,8 @@ jobs: - name: Set up Java uses: actions/setup-java@v3 with: - distribution: 'zulu' - java-version: 11 + distribution: 'temurin' + java-version: 17 - name: jvmTest uses: gradle/gradle-build-action@v2 @@ -173,8 +173,8 @@ jobs: - name: Set up Java uses: actions/setup-java@v3 with: - distribution: 'zulu' - java-version: 11 + distribution: 'temurin' + java-version: 17 - name: jvmTest (K2 enabled) uses: gradle/gradle-build-action@v2 @@ -200,8 +200,8 @@ jobs: - name: Set up Java uses: actions/setup-java@v3 with: - distribution: 'zulu' - java-version: 11 + distribution: 'temurin' + java-version: 17 - name: kotlinUpgradeYarnLock uses: gradle/gradle-build-action@v2 @@ -232,8 +232,8 @@ jobs: - name: Set up Java uses: actions/setup-java@v3 with: - distribution: 'zulu' - java-version: 11 + distribution: 'temurin' + java-version: 17 - name: linuxX64Test uses: gradle/gradle-build-action@v2 @@ -259,8 +259,8 @@ jobs: - name: Set up Java uses: actions/setup-java@v3 with: - distribution: 'zulu' - java-version: 11 + distribution: 'temurin' + java-version: 17 - name: apiDump uses: gradle/gradle-build-action@v2 @@ -285,8 +285,8 @@ jobs: - name: Set up Java uses: actions/setup-java@v3 with: - distribution: 'zulu' - java-version: 11 + distribution: 'temurin' + java-version: 17 - name: spotlessApply uses: gradle/gradle-build-action@v2 From 607dc712c06da6bac0a68cc1712a945595f9bde0 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Mena Date: Wed, 15 Nov 2023 16:27:54 +0100 Subject: [PATCH 03/14] Use Java 17 in GitHub Actions, take 2 --- .github/workflows/publish.yml | 2 +- .github/workflows/pull_request.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 703110b1ded..2dab5ccfb62 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -11,7 +11,7 @@ on: env: BASEDIR: ${{github.workspace}}/arrow-libs - GRADLE_OPTS: -Dorg.gradle.daemon=false -Dorg.gradle.kotlin.dsl.internal.io.timeout=120000 -Dorg.gradle.jvmargs="-Xmx5g -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -XX:+UseParallelGC -XX:MaxMetaspaceSize=1g -Dfile.encoding=UTF-8" + GRADLE_OPTS: -Dorg.gradle.daemon=false -Dorg.gradle.kotlin.dsl.internal.io.timeout=120000 -Dorg.gradle.jvmargs="-Xmx5g -XX:+HeapDumpOnOutOfMemoryError -XX:+UseParallelGC -XX:MaxMetaspaceSize=1g -Dfile.encoding=UTF-8" OSS_USER: '${{ secrets.OSS_USER }}' OSS_TOKEN: '${{ secrets.OSS_TOKEN }}' OSS_STAGING_PROFILE_ID: '${{ secrets.OSS_STAGING_PROFILE_ID }}' diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index b6fc48e7406..9239f47b83c 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -3,7 +3,7 @@ name: "pull_request" on: pull_request env: - GRADLE_OPTS: -Dorg.gradle.daemon=false -Dorg.gradle.kotlin.dsl.internal.io.timeout=120000 -Dorg.gradle.jvmargs="-Xmx5g -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -XX:+UseParallelGC -XX:MaxMetaspaceSize=1g -Dfile.encoding=UTF-8" + GRADLE_OPTS: -Dorg.gradle.daemon=false -Dorg.gradle.kotlin.dsl.internal.io.timeout=120000 -Dorg.gradle.jvmargs="-Xmx5g -XX:+HeapDumpOnOutOfMemoryError -XX:+UseParallelGC -XX:MaxMetaspaceSize=1g -Dfile.encoding=UTF-8" concurrency: group: pull_request-${{ github.ref }} From ce0f9c6ef54065aed834b59239b6fc9e506f6e30 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Mena Date: Wed, 15 Nov 2023 16:43:19 +0100 Subject: [PATCH 04/14] Fix choice of compiler in Compose for -dev Kotlin versions --- .github/workflows/pull_request.yml | 2 +- .../optics/arrow-optics-compose/build.gradle.kts | 14 +++++++++++++- settings.gradle.kts | 5 +++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 9239f47b83c..ac6f6629d04 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -179,7 +179,7 @@ jobs: - name: jvmTest (K2 enabled) uses: gradle/gradle-build-action@v2 with: - arguments: "jvmTest -Pkotlin_version=2.0.0-dev-6573 -Pkotlin_repo_url=https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap -Pkotlin_language_version=2.0 -Pkotlin_api_version=2.0" + arguments: "jvmTest -Pkotlin_version=2.0.0-dev-6573 -Pkotlin_repo_url=https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap -Pkotlin_language_version=2.0 -Pkotlin_api_version=2.0 -Pcompose_version=1.6.0-dev1276" - name: Upload reports if: failure() diff --git a/arrow-libs/optics/arrow-optics-compose/build.gradle.kts b/arrow-libs/optics/arrow-optics-compose/build.gradle.kts index 6f7ae7fb697..064a051bd4c 100644 --- a/arrow-libs/optics/arrow-optics-compose/build.gradle.kts +++ b/arrow-libs/optics/arrow-optics-compose/build.gradle.kts @@ -1,5 +1,8 @@ @file:Suppress("DSL_SCOPE_VIOLATION") +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + + repositories { google() mavenCentral() @@ -67,10 +70,19 @@ kotlin { } } -tasks.withType { +tasks.withType().configureEach { useJUnitPlatform() } +compose { + // override the choice of Compose if we use a Kotlin -dev version + val kotlinVersion = project.rootProject.properties["kotlin_version"] as? String + if (kotlinVersion != null && kotlinVersion.contains("-dev-")) { + kotlinCompilerPlugin.set(dependencies.compiler.forKotlin("1.9.20")) + kotlinCompilerPluginArgs.add("suppressKotlinVersionCompatibilityCheck=1.9.20") + } +} + android { namespace = "arrow.optics.compose" compileSdk = libs.versions.android.compileSdk.get().toInt() diff --git a/settings.gradle.kts b/settings.gradle.kts index 622c3cf0d9f..54694ce3d3c 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -22,6 +22,7 @@ plugins { dependencyResolutionManagement { @Suppress("LocalVariableName") val kotlin_repo_url: String? by settings @Suppress("LocalVariableName") val kotlin_version: String? by settings + @Suppress("LocalVariableName") val compose_version: String? by settings repositories { mavenCentral() @@ -35,6 +36,10 @@ dependencyResolutionManagement { println("Overriding Kotlin version with $kotlin_version") version("kotlin", kotlin_version!!) } + if (!compose_version.isNullOrBlank()) { + println("Overriding Compose version with $compose_version") + version("composePlugin", compose_version!!) + } } } } From 9bc65ae5d7e042886846f6e106f695b945025b88 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Mena Date: Wed, 15 Nov 2023 17:31:01 +0100 Subject: [PATCH 05/14] Fix choice of compiler in Compose for -dev Kotlin versions, take 2 --- arrow-libs/optics/arrow-optics-compose/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arrow-libs/optics/arrow-optics-compose/build.gradle.kts b/arrow-libs/optics/arrow-optics-compose/build.gradle.kts index 064a051bd4c..f5a50d9afab 100644 --- a/arrow-libs/optics/arrow-optics-compose/build.gradle.kts +++ b/arrow-libs/optics/arrow-optics-compose/build.gradle.kts @@ -79,7 +79,7 @@ compose { val kotlinVersion = project.rootProject.properties["kotlin_version"] as? String if (kotlinVersion != null && kotlinVersion.contains("-dev-")) { kotlinCompilerPlugin.set(dependencies.compiler.forKotlin("1.9.20")) - kotlinCompilerPluginArgs.add("suppressKotlinVersionCompatibilityCheck=1.9.20") + kotlinCompilerPluginArgs.add("suppressKotlinVersionCompatibilityCheck=$kotlinVersion") } } From 4b24494a1a7f93d0ff9b5414bb43ecd93d6e6662 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Mena Date: Fri, 17 Nov 2023 15:07:46 +0100 Subject: [PATCH 06/14] Keep atomicity of update --- .../src/commonMain/kotlin/arrow/optics/Copy.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arrow-libs/optics/arrow-optics-compose/src/commonMain/kotlin/arrow/optics/Copy.kt b/arrow-libs/optics/arrow-optics-compose/src/commonMain/kotlin/arrow/optics/Copy.kt index 1cc26c41b95..d76ce3480f7 100644 --- a/arrow-libs/optics/arrow-optics-compose/src/commonMain/kotlin/arrow/optics/Copy.kt +++ b/arrow-libs/optics/arrow-optics-compose/src/commonMain/kotlin/arrow/optics/Copy.kt @@ -1,6 +1,7 @@ package arrow.optics import androidx.compose.runtime.MutableState +import androidx.compose.runtime.snapshots.Snapshot import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.update @@ -9,7 +10,9 @@ import kotlinx.coroutines.flow.update * by applying the function [block] to the current value. */ public inline fun MutableState.update(block: (T) -> T) { - value = block(value) + Snapshot.withMutableSnapshot { + value = block(value) + } } /** From 272185628aa83c691d7bc6ceaa9abfe73711d5c5 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Date: Thu, 30 Nov 2023 20:33:18 +0100 Subject: [PATCH 07/14] Update libs.versions.toml --- gradle/libs.versions.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 58647c07285..ab4ff56de0d 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -23,8 +23,8 @@ retrofit = "2.9.0" retrofitKotlinxSerialization = "1.0.0" spotlessVersion = "6.23.2" compose = "1.5.4" -composePlugin = "1.5.10" -agp = "8.1.3" +composePlugin = "1.5.11" +agp = "8.2.0" android-compileSdk = "34" [libraries] From 0947c3a6fae975157993aeaef3bbee84f8ed4ac7 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Date: Thu, 30 Nov 2023 20:43:09 +0100 Subject: [PATCH 08/14] Update build.gradle.kts --- arrow-libs/optics/arrow-optics-compose/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arrow-libs/optics/arrow-optics-compose/build.gradle.kts b/arrow-libs/optics/arrow-optics-compose/build.gradle.kts index f5a50d9afab..2df6f0fbf09 100644 --- a/arrow-libs/optics/arrow-optics-compose/build.gradle.kts +++ b/arrow-libs/optics/arrow-optics-compose/build.gradle.kts @@ -78,7 +78,7 @@ compose { // override the choice of Compose if we use a Kotlin -dev version val kotlinVersion = project.rootProject.properties["kotlin_version"] as? String if (kotlinVersion != null && kotlinVersion.contains("-dev-")) { - kotlinCompilerPlugin.set(dependencies.compiler.forKotlin("1.9.20")) + kotlinCompilerPlugin.set(dependencies.compiler.forKotlin("2.0.0-Beta1")) kotlinCompilerPluginArgs.add("suppressKotlinVersionCompatibilityCheck=$kotlinVersion") } } From 3ac85879d7433d55ae27fc548317469a57371515 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Date: Mon, 11 Dec 2023 15:22:15 +0100 Subject: [PATCH 09/14] Update pull_request.yml --- .github/workflows/pull_request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 47085c455af..ec280b0eb83 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -179,7 +179,7 @@ jobs: - name: jvmTest (K2 enabled) uses: gradle/gradle-build-action@v2 with: - arguments: "jvmTest -Pkotlin_version=2.0.0-dev-7674 -Pkotlin_repo_url=https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap -Pkotlin_language_version=2.0 -Pkotlin_api_version=2.0 -Pcompose_version=1.6.0-dev1296" + arguments: "jvmTest -Pkotlin_version=2.0.0-dev-9013 -Pkotlin_repo_url=https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap -Pkotlin_language_version=2.0 -Pkotlin_api_version=2.0 -Pcompose_version=1.6.0-dev1323" - name: Upload reports if: failure() From aeadb48a038dc246cb1e553fe90221c0a11c25d2 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Date: Mon, 11 Dec 2023 15:26:19 +0100 Subject: [PATCH 10/14] Update pull_request.yml --- .github/workflows/pull_request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index ec280b0eb83..d4d94682ed6 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -179,7 +179,7 @@ jobs: - name: jvmTest (K2 enabled) uses: gradle/gradle-build-action@v2 with: - arguments: "jvmTest -Pkotlin_version=2.0.0-dev-9013 -Pkotlin_repo_url=https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap -Pkotlin_language_version=2.0 -Pkotlin_api_version=2.0 -Pcompose_version=1.6.0-dev1323" + arguments: "jvmTest -Pkotlin_version=2.0.0-dev-7674 -Pkotlin_repo_url=https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap -Pkotlin_language_version=2.0 -Pkotlin_api_version=2.0 -Pcompose_version=1.6.0-dev1323" - name: Upload reports if: failure() From b5f037f26c78135879709804a0364f037d6658ef Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Date: Thu, 21 Dec 2023 11:40:21 +0100 Subject: [PATCH 11/14] Update pull_request.yml --- .github/workflows/pull_request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 4924d2f204e..ed1004fba0e 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -179,7 +179,7 @@ jobs: - name: jvmTest (K2 enabled) uses: gradle/gradle-build-action@v2 with: - arguments: "jvmTest -Pkotlin_version=2.0.0-Beta2 -Pksp_version=2.0.0-Beta2-1.0.16 -Pcompose_version=1.6.0-alpha1 -Pkotlin_language_version=2.0 -Pkotlin_api_version=2.0" + arguments: "jvmTest -Pkotlin_version=2.0.0-Beta2 -Pksp_version=2.0.0-Beta2-1.0.16 -Pcompose_version=1.6.0-alpha01 -Pkotlin_language_version=2.0 -Pkotlin_api_version=2.0" - name: Upload reports if: failure() From 16b23ae4298d5c2538100d3a324ff1aca581b40f Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Mena Date: Fri, 19 Jan 2024 13:44:43 +0100 Subject: [PATCH 12/14] Update versions --- .github/workflows/pull_request.yml | 2 +- gradle/libs.versions.toml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index ed1004fba0e..acd6aa39d25 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -179,7 +179,7 @@ jobs: - name: jvmTest (K2 enabled) uses: gradle/gradle-build-action@v2 with: - arguments: "jvmTest -Pkotlin_version=2.0.0-Beta2 -Pksp_version=2.0.0-Beta2-1.0.16 -Pcompose_version=1.6.0-alpha01 -Pkotlin_language_version=2.0 -Pkotlin_api_version=2.0" + arguments: "jvmTest -Pkotlin_version=2.0.0-Beta2 -Pksp_version=2.0.0-Beta2-1.0.16 -Pkotlin_language_version=2.0 -Pkotlin_api_version=2.0" - name: Upload reports if: failure() diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index b30cd797999..075488a07a0 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -22,8 +22,8 @@ mockWebServer = "4.12.0" retrofit = "2.9.0" retrofitKotlinxSerialization = "1.0.0" spotlessVersion = "6.24.0" -compose = "1.5.4" -composePlugin = "1.5.11" +compose = "1.6.0-rc01" +composePlugin = "1.6.0-dev1369" agp = "8.2.0" android-compileSdk = "34" cache4k = "0.12.0" From d700c774a43a1a550c24291c06eea0c31dc65e81 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Mena Date: Mon, 22 Jan 2024 16:23:03 +0100 Subject: [PATCH 13/14] Do not run Compose tests with K2 --- settings.gradle.kts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/settings.gradle.kts b/settings.gradle.kts index 8444ea11cfa..b21acef692b 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,3 +1,5 @@ +@file:Suppress("LocalVariableName") + enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") rootProject.name = "arrow" @@ -19,12 +21,12 @@ plugins { id("org.gradle.toolchains.foojay-resolver-convention") version("0.8.0") } -dependencyResolutionManagement { - @Suppress("LocalVariableName") val kotlin_repo_url: String? by settings - @Suppress("LocalVariableName") val kotlin_version: String? by settings - @Suppress("LocalVariableName") val ksp_version: String? by settings - @Suppress("LocalVariableName") val compose_version: String? by settings +val kotlin_repo_url: String? by settings +val kotlin_version: String? by settings +val ksp_version: String? by settings +val compose_version: String? by settings +dependencyResolutionManagement { repositories { mavenCentral() gradlePluginPortal() @@ -94,8 +96,10 @@ project(":arrow-optics").projectDir = file("arrow-libs/optics/arrow-optics") include("arrow-optics-reflect") project(":arrow-optics-reflect").projectDir = file("arrow-libs/optics/arrow-optics-reflect") -include("arrow-optics-compose") -project(":arrow-optics-compose").projectDir = file("arrow-libs/optics/arrow-optics-compose") +if (kotlin_version.isNullOrBlank() || "2.0" !in kotlin_version!!) { + include("arrow-optics-compose") + project(":arrow-optics-compose").projectDir = file("arrow-libs/optics/arrow-optics-compose") +} include("arrow-optics-ksp-plugin") project(":arrow-optics-ksp-plugin").projectDir = file("arrow-libs/optics/arrow-optics-ksp-plugin") From 452aa9989c4998ff384a014feb087c6af87d259d Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Mena Date: Tue, 23 Jan 2024 10:47:27 +0100 Subject: [PATCH 14/14] Apply suggestion --- .../src/commonMain/kotlin/arrow/optics/Copy.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arrow-libs/optics/arrow-optics-compose/src/commonMain/kotlin/arrow/optics/Copy.kt b/arrow-libs/optics/arrow-optics-compose/src/commonMain/kotlin/arrow/optics/Copy.kt index d76ce3480f7..4fa50e90cba 100644 --- a/arrow-libs/optics/arrow-optics-compose/src/commonMain/kotlin/arrow/optics/Copy.kt +++ b/arrow-libs/optics/arrow-optics-compose/src/commonMain/kotlin/arrow/optics/Copy.kt @@ -9,7 +9,7 @@ import kotlinx.coroutines.flow.update * Modifies the value in this [MutableState] * by applying the function [block] to the current value. */ -public inline fun MutableState.update(block: (T) -> T) { +public inline fun MutableState.update(crossinline block: (T) -> T) { Snapshot.withMutableSnapshot { value = block(value) }