Skip to content

Commit

Permalink
Upgrade to Kotlin 2.0. (#2200)
Browse files Browse the repository at this point in the history
* Upgrade to Kotlin 2.0.

* Add overloads.

* More fixes.

* Fix build.

* Work around compiler bug.

* Re-add.

* Fixes.

* Fix warning.

* Disable allWarningsAsErrors.

* Update API.

* Fix yarn.

* Enable poko.

* Use poko snapshot.

* Upgrade lockfile.

* Update Kotlin.

* Update Compose compiler.
  • Loading branch information
colinrtwhite committed May 7, 2024
1 parent 93ef76a commit 5d8bbca
Show file tree
Hide file tree
Showing 35 changed files with 639 additions and 334 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
gradle-home-cache-cleanup: true

- name: Unit tests
run: ./gradlew allTests testDebugUnitTest verifyPaparazziDebug verifyRoborazziDebug
run: ./gradlew kotlinUpgradeYarnLock allTests testDebugUnitTest verifyPaparazziDebug verifyRoborazziDebug

instrumentation-tests:
name: Instrumentation tests
Expand Down
4 changes: 3 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ buildscript {
repositories {
google()
mavenCentral()
maven("https://oss.sonatype.org/content/repositories/snapshots/")
}
dependencies {
classpath(libs.gradlePlugin.android)
Expand Down Expand Up @@ -54,6 +55,7 @@ allprojects {
repositories {
google()
mavenCentral()
maven("https://oss.sonatype.org/content/repositories/snapshots/")
}

// Necessary to publish to Maven.
Expand Down Expand Up @@ -145,7 +147,7 @@ allprojects {

plugins.withId("dev.drewhamilton.poko") {
extensions.configure<PokoPluginExtension> {
pokoAnnotation = "coil3.annotation.Data"
pokoAnnotation = "coil3/annotation/Data"
}
}

Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/coil3/hierarchyTemplate.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private fun KotlinHierarchyBuilder.groupNonAndroid() {
private fun KotlinHierarchyBuilder.groupJsCommon() {
group("jsCommon") {
withJs()
withWasm()
withWasmJs()
}
}

Expand Down
15 changes: 4 additions & 11 deletions buildSrc/src/main/kotlin/coil3/multiplatform.kt
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ fun Project.applyKotlinJsImplicitDependencyWorkaround() {
dependsOn(getByPath(":coil:jsTestTestDevelopmentExecutableCompileSync"))
}
named("jsBrowserProductionWebpack").configure(configureJs)
named("jsBrowserProductionLibraryPrepare").configure(configureJs)
named("jsNodeProductionLibraryPrepare").configure(configureJs)
named("jsBrowserProductionLibraryDistribution").configure(configureJs)
named("jsNodeProductionLibraryDistribution").configure(configureJs)

val configureWasmJs: Task.() -> Unit = {
dependsOn(named("wasmJsDevelopmentLibraryCompileSync"))
Expand All @@ -112,15 +112,8 @@ fun Project.applyKotlinJsImplicitDependencyWorkaround() {
dependsOn(getByPath(":coil:wasmJsTestTestDevelopmentExecutableCompileSync"))
}
named("wasmJsBrowserProductionWebpack").configure(configureWasmJs)
named("wasmJsBrowserProductionLibraryPrepare").configure(configureWasmJs)
named("wasmJsNodeProductionLibraryPrepare").configure(configureWasmJs)
named("wasmJsBrowserProductionExecutableDistributeResources").configure {
dependsOn(named("wasmJsDevelopmentLibraryCompileSync"))
dependsOn(named("wasmJsDevelopmentExecutableCompileSync"))
dependsOn(named("wasmJsProductionLibraryCompileSync"))
dependsOn(named("wasmJsProductionExecutableCompileSync"))
dependsOn(named("wasmJsTestTestDevelopmentExecutableCompileSync"))
}
named("wasmJsBrowserProductionLibraryDistribution").configure(configureWasmJs)
named("wasmJsNodeProductionLibraryDistribution").configure(configureWasmJs)
}
}

Expand Down
21 changes: 12 additions & 9 deletions buildSrc/src/main/kotlin/coil3/projects.kt
Original file line number Diff line number Diff line change
Expand Up @@ -137,22 +137,25 @@ private fun <T : BaseExtension> Project.androidBase(
}
targets.configureEach {
compilations.configureEach {
compilerOptions.configure {
val arguments = listOf(
// https://kotlinlang.org/docs/compiler-reference.html#progressive
"-progressive",
// https://youtrack.jetbrains.com/issue/KT-61573
"-Xexpect-actual-classes",
)
freeCompilerArgs.addAll(arguments)
compileTaskProvider.configure {
compilerOptions {
val arguments = listOf(
// https://kotlinlang.org/docs/compiler-reference.html#progressive
"-progressive",
// https://youtrack.jetbrains.com/issue/KT-61573
"-Xexpect-actual-classes",
)
freeCompilerArgs.addAll(arguments)
}
}
}
}
}
}
tasks.withType<KotlinCompile>().configureEach {
compilerOptions {
allWarningsAsErrors.set(System.getenv("CI").toBoolean())
// Temporarily disable due to https://youtrack.jetbrains.com/issue/KT-60866.
// allWarningsAsErrors.set(System.getenv("CI").toBoolean())

val arguments = mutableListOf<String>()

Expand Down
2 changes: 2 additions & 0 deletions coil-core/api/android/coil-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,8 @@ public final class coil3/util/ServiceLoaderComponentRegistry {
public static final field INSTANCE Lcoil3/util/ServiceLoaderComponentRegistry;
public final fun getDecoders ()Ljava/util/List;
public final fun getFetchers ()Ljava/util/List;
public final fun register (Lcoil3/util/DecoderServiceLoaderTarget;)V
public final fun register (Lcoil3/util/FetcherServiceLoaderTarget;)V
}

public final class coil3/util/Utils_commonKt {
Expand Down
2 changes: 2 additions & 0 deletions coil-core/api/jvm/coil-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,8 @@ public final class coil3/util/ServiceLoaderComponentRegistry {
public static final field INSTANCE Lcoil3/util/ServiceLoaderComponentRegistry;
public final fun getDecoders ()Ljava/util/List;
public final fun getFetchers ()Ljava/util/List;
public final fun register (Lcoil3/util/DecoderServiceLoaderTarget;)V
public final fun register (Lcoil3/util/FetcherServiceLoaderTarget;)V
}

public final class coil3/util/Utils_commonKt {
Expand Down
5 changes: 2 additions & 3 deletions coil-core/src/commonMain/kotlin/coil3/EventListener.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import coil3.request.Options
import coil3.request.SuccessResult
import coil3.size.Size
import coil3.size.SizeResolver
import kotlin.jvm.JvmField

/**
* A listener for tracking the progress of an image request. This class is useful for
Expand Down Expand Up @@ -144,11 +143,11 @@ expect abstract class EventListener : ImageRequest.Listener {
fun create(request: ImageRequest): EventListener

companion object {
@JvmField val NONE: Factory
val NONE: Factory
}
}

companion object {
@JvmField val NONE: EventListener
val NONE: EventListener
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import kotlin.reflect.KClass
expect object ServiceLoaderComponentRegistry {
val fetchers: List<FetcherServiceLoaderTarget<*>>
val decoders: List<DecoderServiceLoaderTarget>

// Only available on non-JVM. Added these declarations to work-around a compiler bug.
fun register(fetcher: FetcherServiceLoaderTarget<*>)
fun register(decoder: DecoderServiceLoaderTarget)
}

@InternalCoilApi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,12 @@ actual object ServiceLoaderComponentRegistry {
DecoderServiceLoaderTarget::class.java.classLoader,
).iterator().asSequence().toList().toImmutableList()
}

actual fun register(fetcher: FetcherServiceLoaderTarget<*>) {
throw UnsupportedOperationException()
}

actual fun register(decoder: DecoderServiceLoaderTarget) {
throw UnsupportedOperationException()
}
}
1 change: 0 additions & 1 deletion coil-core/src/jvmCommonMain/kotlin/coil3/util/utils.jvm.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package coil3.util

@Suppress("ACTUAL_WITHOUT_EXPECT") // https://youtrack.jetbrains.com/issue/KT-37316
internal actual typealias WeakReference<T> = java.lang.ref.WeakReference<T>

internal actual fun Any.identityHashCode() = System.identityHashCode(this)
1 change: 0 additions & 1 deletion coil-core/src/nativeMain/kotlin/coil3/util/utils.native.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import kotlin.experimental.ExperimentalNativeApi
import kotlin.native.identityHashCode

@OptIn(ExperimentalNativeApi::class)
@Suppress("ACTUAL_WITHOUT_EXPECT") // https://youtrack.jetbrains.com/issue/KT-37316
internal actual typealias WeakReference<T> = kotlin.native.ref.WeakReference<T>

@OptIn(ExperimentalNativeApi::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ actual object ServiceLoaderComponentRegistry {
actual val decoders: List<DecoderServiceLoaderTarget>
get() = synchronized(lock) { _decoders.toImmutableList() }

fun register(fetcher: FetcherServiceLoaderTarget<*>) = synchronized(lock) {
actual fun register(fetcher: FetcherServiceLoaderTarget<*>) = synchronized(lock) {
_fetchers += fetcher
}

fun register(decoder: DecoderServiceLoaderTarget) = synchronized(lock) {
actual fun register(decoder: DecoderServiceLoaderTarget) = synchronized(lock) {
_decoders += decoder
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ actual class SvgDecoder @JvmOverloads actual constructor(
val useViewBoundsAsIntrinsicSize: Boolean,
) : Decoder {

override suspend fun decode() = runInterruptible {
actual override suspend fun decode(): DecodeResult? = runInterruptible {
val svg = source.source().use { SVG.getFromInputStream(it.inputStream()) }

val svgWidth: Float
Expand Down Expand Up @@ -103,7 +103,7 @@ actual class SvgDecoder @JvmOverloads actual constructor(
val useViewBoundsAsIntrinsicSize: Boolean,
) : Decoder.Factory {

override fun create(
actual override fun create(
result: SourceFetchResult,
options: Options,
imageLoader: ImageLoader,
Expand Down
12 changes: 11 additions & 1 deletion coil-svg/src/commonMain/kotlin/coil3/svg/SvgDecoder.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package coil3.svg

import coil3.ImageLoader
import coil3.decode.DecodeResult
import coil3.decode.Decoder
import coil3.decode.ImageSource
import coil3.fetch.SourceFetchResult
import coil3.request.Options

/**
Expand All @@ -17,8 +20,15 @@ expect class SvgDecoder(
options: Options,
useViewBoundsAsIntrinsicSize: Boolean = true,
) : Decoder {
override suspend fun decode(): DecodeResult?

class Factory(
useViewBoundsAsIntrinsicSize: Boolean = true,
) : Decoder.Factory
) : Decoder.Factory {
override fun create(
result: SourceFetchResult,
options: Options,
imageLoader: ImageLoader,
): Decoder?
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ actual class SvgDecoder actual constructor(
val useViewBoundsAsIntrinsicSize: Boolean,
) : Decoder {

override suspend fun decode(): DecodeResult {
actual override suspend fun decode(): DecodeResult? {
val bytes = source.source().readByteArray()
val svg = SVGDOM(Data.makeFromBytes(bytes))

Expand Down Expand Up @@ -107,7 +107,7 @@ actual class SvgDecoder actual constructor(
val useViewBoundsAsIntrinsicSize: Boolean,
) : Decoder.Factory {

override fun create(
actual override fun create(
result: SourceFetchResult,
options: Options,
imageLoader: ImageLoader,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import coil3.annotation.ExperimentalCoilApi
@ExperimentalCoilApi
@Data
actual class FakeImage actual constructor(
override val width: Int,
override val height: Int,
override val size: Long,
override val shareable: Boolean,
actual override val width: Int,
actual override val height: Int,
actual override val size: Long,
actual override val shareable: Boolean,
actual val color: Int,
) : Image {
override fun asDrawable(resources: Resources): Drawable {
Expand Down
4 changes: 4 additions & 0 deletions coil-test/src/commonMain/kotlin/coil3/test/FakeImage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@ expect class FakeImage(
shareable: Boolean = true,
color: Int = 0x000000,
) : Image {
override val width: Int
override val height: Int
override val size: Long
override val shareable: Boolean
val color: Int
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import org.jetbrains.skia.impl.use
@ExperimentalCoilApi
@Data
actual class FakeImage actual constructor(
override val width: Int,
override val height: Int,
override val size: Long,
override val shareable: Boolean,
actual override val width: Int,
actual override val height: Int,
actual override val size: Long,
actual override val shareable: Boolean,
actual val color: Int,
) : Image {
override fun toBitmap(): Bitmap {
Expand Down
11 changes: 6 additions & 5 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ androidx-benchmark = "1.2.4"
androidx-lifecycle = "2.7.0"
coroutines = "1.8.0"
jetbrains-compose = "1.6.2"
jetbrains-compose-compiler = "1.5.10.2"
kotlin = "1.9.23"
jetbrains-compose-compiler = "2.0.0-RC2"
kotlin = "2.0.0-RC2"
ktlint = "1.1.0"
ktor = "2.3.10"
ktor-wasm = "3.0.0-wasm2"
Expand All @@ -19,7 +19,7 @@ skiko = "0.7.97"
baselineProfile = { id = "androidx.baselineprofile", version.ref = "androidx-benchmark"}
binaryCompatibility = "org.jetbrains.kotlinx.binary-compatibility-validator:0.14.0"
dokka = "org.jetbrains.dokka:1.9.20"
poko = "dev.drewhamilton.poko:0.15.2"
poko = "dev.drewhamilton.poko:0.16.0-SNAPSHOT"
spotless = "com.diffplug.spotless:6.25.0"

[libraries]
Expand Down Expand Up @@ -52,7 +52,7 @@ androidx-test-runner = "androidx.test:runner:1.5.2"
androidx-test-uiautomator = "androidx.test.uiautomator:uiautomator:2.3.0"
androidx-vectordrawable-animated = "androidx.vectordrawable:vectordrawable-animated:1.2.0"

jetbrains-compose-compiler = { module = "org.jetbrains.compose.compiler:compiler", version.ref = "jetbrains-compose-compiler" }
jetbrains-compose-compiler = { module = "org.jetbrains.kotlin:kotlin-compose-compiler-plugin-embeddable", version.ref = "jetbrains-compose-compiler" }

coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "coroutines" }
coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" }
Expand All @@ -65,7 +65,8 @@ google-drawablepainter = "com.google.accompanist:accompanist-drawablepainter:0.3
junit = "junit:junit:4.13.2"

kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib" }
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test-junit" }
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test" }
kotlin-test-junit = { module = "org.jetbrains.kotlin:kotlin-test-junit" }

kotlinx-datetime = "org.jetbrains.kotlinx:kotlinx-datetime:0.5.0"
kotlinx-serialization-json = "org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3"
Expand Down
7 changes: 6 additions & 1 deletion internal/test-utils/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@ kotlin {
api(libs.androidx.core)
api(libs.androidx.test.core)
api(libs.androidx.test.junit)
api(libs.junit)
compileOnly(libs.robolectric)
}
}
named("jvmCommonMain") {
dependencies {
api(libs.kotlin.test.junit)
api(libs.junit)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import android.graphics.drawable.Drawable
import coil3.Image

actual class FakeImage actual constructor(
override val width: Int,
override val height: Int,
override val size: Long,
override val shareable: Boolean,
actual override val width: Int,
actual override val height: Int,
actual override val size: Long,
actual override val shareable: Boolean,
) : Image {
override fun asDrawable(resources: Resources): Drawable {
throw UnsupportedOperationException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ expect class FakeImage(
height: Int = 100,
size: Long = 4L * width * height,
shareable: Boolean = true,
) : Image
) : Image {
override val size: Long
override val width: Int
override val height: Int
override val shareable: Boolean
}

const val DEFAULT_FAKE_IMAGE_SIZE = 4L * 100 * 100

0 comments on commit 5d8bbca

Please sign in to comment.