Browse Source

support k2 compose compiler plugin

shish/composable-test-cases-k2
Pavel Shishkin 4 months ago
parent
commit
504ce18e91
  1. 21
      compose/integrations/composable-test-cases/build.gradle.kts
  2. 10
      compose/integrations/composable-test-cases/buildSrc/build.gradle.kts
  3. 23
      compose/integrations/composable-test-cases/buildSrc/src/main/kotlin/TargetsConfiguration.kt
  4. 70
      compose/integrations/composable-test-cases/buildSrc/src/main/kotlin/internal/ComposeCompilerArtifactProvider.kt
  5. 50
      compose/integrations/composable-test-cases/buildSrc/src/main/kotlin/internal/InternalComposeSupportPlugin.kt
  6. 3
      compose/integrations/composable-test-cases/common/build.gradle.kts
  7. 14
      compose/integrations/composable-test-cases/gradle.properties
  8. 6
      compose/integrations/composable-test-cases/gradle/libs.versions.toml
  9. 119
      compose/integrations/composable-test-cases/settings.gradle.kts
  10. 1
      compose/integrations/composable-test-cases/testcases/anonymousObjects/lib/build.gradle.kts
  11. 1
      compose/integrations/composable-test-cases/testcases/anonymousObjects/main/build.gradle.kts
  12. 1
      compose/integrations/composable-test-cases/testcases/constructors/lib/build.gradle.kts
  13. 1
      compose/integrations/composable-test-cases/testcases/constructors/main/build.gradle.kts
  14. 31
      compose/integrations/composable-test-cases/testcases/expectActual/lib/build.gradle.kts
  15. 1
      compose/integrations/composable-test-cases/testcases/expectActual/main/build.gradle.kts
  16. 1
      compose/integrations/composable-test-cases/testcases/inheritance/composableInterface/lib/build.gradle.kts
  17. 1
      compose/integrations/composable-test-cases/testcases/inheritance/composableInterface/main/build.gradle.kts
  18. 1
      compose/integrations/composable-test-cases/testcases/inheritance/funInterface/lib/build.gradle.kts
  19. 1
      compose/integrations/composable-test-cases/testcases/inheritance/funInterface/main/build.gradle.kts
  20. 1
      compose/integrations/composable-test-cases/testcases/lambdas/lib/build.gradle.kts
  21. 1
      compose/integrations/composable-test-cases/testcases/lambdas/main/build.gradle.kts
  22. 1
      compose/integrations/composable-test-cases/testcases/rememberAnonymousObj/lib/build.gradle.kts
  23. 1
      compose/integrations/composable-test-cases/testcases/rememberAnonymousObj/main/build.gradle.kts
  24. 1
      compose/integrations/composable-test-cases/testcases/stability/lib/build.gradle.kts
  25. 1
      compose/integrations/composable-test-cases/testcases/stability/main/build.gradle.kts
  26. 1
      compose/integrations/composable-test-cases/testcases/template/lib/build.gradle.kts
  27. 1
      compose/integrations/composable-test-cases/testcases/template/main/build.gradle.kts
  28. 1
      compose/integrations/composable-test-cases/testcases/valueClass/lib/build.gradle.kts
  29. 1
      compose/integrations/composable-test-cases/testcases/valueClass/main/build.gradle.kts

21
compose/integrations/composable-test-cases/build.gradle.kts

@ -1,4 +1,3 @@
import internal.InternalComposeSupportPlugin
import org.jetbrains.kotlin.gradle.dsl.KotlinCompile
import org.jetbrains.kotlin.gradle.dsl.KotlinJsCompile
@ -14,26 +13,7 @@ allprojects {
// mavenLocal()
}
// Apply here for all subprojects instead of applying in each build.gradle.kts separately.
// It applies the compiler plugin
this.apply<InternalComposeSupportPlugin>()
afterEvaluate {
val pluginOptionPrefix = "plugin:androidx.compose.compiler.plugins.kotlin:"
val project = this
val kotlinVersion = project.properties["kotlin.version"] as? String
project.tasks.withType(KotlinCompile::class.java).configureEach {
kotlinOptions.apply {
freeCompilerArgs +=
listOf(
"-P",
"${pluginOptionPrefix}suppressKotlinVersionCompatibilityCheck=$kotlinVersion"
)
}
}
tasks.withType<KotlinJsCompile>().configureEach {
kotlinOptions.freeCompilerArgs += listOf(
"-Xklib-enable-signature-clash-checks=false",
@ -49,6 +29,7 @@ allprojects {
plugins {
kotlin("multiplatform") apply false
alias(libs.plugins.composeCompiler).apply(false)
}
fun Project.disableYarnLockMismatchReport() {

10
compose/integrations/composable-test-cases/buildSrc/build.gradle.kts

@ -1,5 +1,3 @@
import org.jetbrains.kotlin.gradle.dsl.KotlinCompile
repositories {
mavenCentral()
gradlePluginPortal()
@ -19,11 +17,3 @@ java {
dependencies {
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin")
}
tasks.withType<KotlinCompile<*>>().configureEach {
kotlinOptions {
languageVersion = "1.9"
apiVersion = "1.9"
}
}

23
compose/integrations/composable-test-cases/buildSrc/src/main/kotlin/TargetsConfiguration.kt

@ -11,25 +11,15 @@ val Project.coroutinesVersion: String
return extraProperties.properties["kotlinx.coroutines.version"] as String
}
val Project.isInIdea: Boolean
get() {
return System.getProperty("idea.active")?.toBoolean() == true
}
val Project.isFailingJsCase: Boolean
get() = this.name.contains("-failingJs-")
val Project.isMingwX64Enabled: Boolean
get() = false //this.isInIdea
@OptIn(ExperimentalWasmDsl::class)
fun KotlinMultiplatformExtension.configureTargets() {
jvm("desktop")
applyDefaultHierarchyTemplate()
configureJsTargets()
wasmJs {
d8 {}
}
ios()
iosArm64()
iosSimulatorArm64()
iosX64()
@ -64,3 +54,12 @@ fun KotlinSourceSet.configureCommonTestDependencies() {
}
}
}
val Project.composeVersion: String
get() = properties["compose.version"] as? String
?: error("'compose.version' is not defined")
val Project.composeRuntimeDependency: String
get() = properties["compose.runtime.artifactId"] as? String
?: properties["compose.runtime.groupId"]?.let { "$it:runtime:$composeVersion" }
?: "org.jetbrains.compose.runtime:runtime:${composeVersion}"

70
compose/integrations/composable-test-cases/buildSrc/src/main/kotlin/internal/ComposeCompilerArtifactProvider.kt

@ -1,70 +0,0 @@
/*
* Copyright 2020-2022 JetBrains s.r.o. and respective authors and developers.
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
*/
package internal
import internal.ComposeCompilerArtifactProvider.DefaultCompiler.pluginArtifact
import org.jetbrains.kotlin.gradle.plugin.SubpluginArtifact
// Partially copy-pasted from https://github.com/JetBrains/compose-multiplatform/tree/master/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose
internal class ComposeCompilerArtifactProvider(
private val customPluginString: () -> String
) {
val compilerArtifact: SubpluginArtifact by lazy {
val customPlugin = customPluginString()
val customCoordinates = customPlugin.split(":")
when (customCoordinates.size) {
1 -> {
val customVersion = customCoordinates[0]
check(customVersion.isNotBlank()) { "'compose.kotlinCompilerPlugin' cannot be blank!" }
pluginArtifact(version = customVersion)
}
3 -> pluginArtifact(
version = customCoordinates[2],
groupId = customCoordinates[0],
artifactId = customCoordinates[1],
)
else -> error("""
Illegal format of 'compose.kotlinCompilerPlugin' property.
Expected format: either '<VERSION>' or '<GROUP_ID>:<ARTIFACT_ID>:<VERSION>'
Actual value: '$customPlugin'
""".trimIndent())
}
}
val compilerHostedArtifact: SubpluginArtifact
get() = compilerArtifact.run {
val newArtifactId =
if (groupId == DefaultCompiler.GROUP_ID && artifactId == DefaultCompiler.ARTIFACT_ID) {
DefaultCompiler.HOSTED_ARTIFACT_ID
} else artifactId
copy(artifactId = newArtifactId)
}
internal object DefaultCompiler {
const val GROUP_ID = "org.jetbrains.compose.compiler"
const val ARTIFACT_ID = "compiler"
const val HOSTED_ARTIFACT_ID = "compiler-hosted"
fun pluginArtifact(
version: String,
groupId: String = GROUP_ID,
artifactId: String = ARTIFACT_ID,
): SubpluginArtifact =
SubpluginArtifact(groupId = groupId, artifactId = artifactId, version = version)
}
}
internal fun SubpluginArtifact.copy(
groupId: String? = null,
artifactId: String? = null,
version: String? = null
): SubpluginArtifact =
SubpluginArtifact(
groupId = groupId ?: this.groupId,
artifactId = artifactId ?: this.artifactId,
version = version ?: this.version
)

50
compose/integrations/composable-test-cases/buildSrc/src/main/kotlin/internal/InternalComposeSupportPlugin.kt

@ -1,50 +0,0 @@
/*
* Copyright 2020-2021 JetBrains s.r.o. and respective authors and developers.
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
*/
package internal
import org.gradle.api.Project
import org.gradle.api.provider.Provider
import org.jetbrains.kotlin.gradle.plugin.*
// Partially copy-pasted from https://github.com/JetBrains/compose-multiplatform/tree/master/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose
class InternalComposeSupportPlugin : KotlinCompilerPluginSupportPlugin {
private lateinit var composeCompilerArtifactProvider: ComposeCompilerArtifactProvider
override fun apply(target: Project) {
super.apply(target)
val composeCompilerVersion = target.properties["compose.kotlinCompilerPluginVersion"] as? String
?: error("'compose.kotlinCompilerPluginVersion' is not defined")
composeCompilerArtifactProvider = ComposeCompilerArtifactProvider { composeCompilerVersion }
}
override fun getCompilerPluginId(): String = "androidx.compose.compiler.plugins.kotlin"
override fun getPluginArtifact(): SubpluginArtifact =
composeCompilerArtifactProvider.compilerArtifact
override fun getPluginArtifactForNative(): SubpluginArtifact =
composeCompilerArtifactProvider.compilerHostedArtifact
override fun isApplicable(kotlinCompilation: KotlinCompilation<*>): Boolean = true
override fun applyToCompilation(kotlinCompilation: KotlinCompilation<*>): Provider<List<SubpluginOption>> {
val target = kotlinCompilation.target
return target.project.provider { emptyList() }
}
private fun options(vararg options: Pair<String, String>): List<SubpluginOption> =
options.map { SubpluginOption(it.first, it.second) }
}
val Project.composeVersion: String
get() = properties["compose.version"] as? String
?: error("'compose.version' is not defined")
val Project.composeRuntimeDependency: String
get() = properties["compose.runtime.artifactId"] as? String
?: properties["compose.runtime.groupId"]?.let { it.toString() + ":runtime:$composeVersion" }
?: "org.jetbrains.compose.runtime:runtime:${composeVersion}"

3
compose/integrations/composable-test-cases/common/build.gradle.kts

@ -1,7 +1,6 @@
import internal.composeRuntimeDependency
plugins {
kotlin("multiplatform")
alias(libs.plugins.composeCompiler)
}
group = "com.example"

14
compose/integrations/composable-test-cases/gradle.properties

@ -1,7 +1,7 @@
org.gradle.jvmargs=-Xmx4096M -XX:MaxMetaspaceSize=512m
kotlin.code.style=official
android.useAndroidX=true
kotlin.version=1.9.24
kotlin.version=2.0.20-RC
agp.version=7.3.0
# a version of compose libraries. In this project the only dependency is compose-runtime.
@ -10,15 +10,3 @@ compose.version=1.6.10-rc01
compose.runtime.groupId=org.jetbrains.compose.runtime
kotlinx.coroutines.version=1.8.0
#empty by default - a default version will be used
#compose.kotlinCompilerPluginVersion=23.12.18
compose.kotlinCompilerPluginVersion=1.5.13.3
# default|failingJs - see enum class CasesToRun
tests.casesToRun=default
# comma separated names of test cases known to fail (either compilation or while running) with k/js.
#tests.failing.kjs=rememberAnonymousObj
# TODO: we should test with both K2 and K1
#kotlin.experimental.tryK2=true

6
compose/integrations/composable-test-cases/gradle/libs.versions.toml

@ -1,5 +1,5 @@
[versions]
kotlinx-datetime = "0.5.0"
kotlin="2.0.20-RC"
[libraries]
kotlinx-datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version.ref = "kotlinx-datetime" }
[plugins]
composeCompiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }

119
compose/integrations/composable-test-cases/settings.gradle.kts

@ -9,8 +9,6 @@ pluginManagement {
}
}
rootProject.name = "composable-test-cases"
fun module(name: String, path: String) {
include(name)
val projectDir = rootDir.resolve(path).normalize().absoluteFile
@ -22,112 +20,31 @@ fun module(name: String, path: String) {
gradle.startParameter.setContinueOnFailure(true)
enum class CasesToRun(val value: String) {
Default("default"),
FailingJs("failingJs"),
;
fun isDefault() = this == Default
}
val casesToRun = CasesToRun.values().firstOrNull {
it.value == extra["tests.casesToRun"]
} ?: CasesToRun.Default
val listOfFailingJsCases = (extra.properties.getOrDefault("tests.failing.kjs", "") as String).split(",")
val failingJsSuffix = "failingJs"
fun getFailingSuffix(testCaseName: String): String? {
if (casesToRun == CasesToRun.FailingJs &&
listOfFailingJsCases.contains(testCaseName)
) {
return failingJsSuffix
}
return null
}
fun addRememberAnonymousObjTestCase(testFailingJs: Boolean = false) {
val libName = ":testcase-rememberAnonymousObj-lib".let {
if (testFailingJs) {
it.replace("-lib", "-$failingJsSuffix-lib")
} else {
it
}
}
val mainName = ":testcase-rememberAnonymousObj-main".let {
if (testFailingJs) {
it.replace("-main", "-$failingJsSuffix-main")
} else {
it
}
}
module(libName, "testcases/rememberAnonymousObj/lib")
module(mainName, "testcases/rememberAnonymousObj/main")
}
/**
* @param name - the name of a test case
* @param failingTestCaseNameSuffix - the suffix to add for a failing test case.
* Each platform should have its own unique suffix.
*/
fun addATestCase(name: String, failingTestCaseNameSuffix: String? = null) {
val libName = ":testcase-$name-lib".let {
if (failingTestCaseNameSuffix != null) {
it.replace("-lib", "-$failingTestCaseNameSuffix-lib")
} else {
it
}
}
val mainName = ":testcase-$name-main".let {
if (failingTestCaseNameSuffix != null) {
it.replace("-main", "-$failingTestCaseNameSuffix-main")
} else {
it
}
}
println("adding $libName, $mainName")
module(libName, "testcases/$name/lib")
module(mainName, "testcases/$name/main")
}
include(":common")
if (casesToRun.isDefault()) {
module(":testcase-template-lib", "testcases/template/lib")
module(":testcase-template-main", "testcases/template/main")
module(":testcase-inheritance-composableInterface-lib", "testcases/inheritance/composableInterface/lib")
module(":testcase-inheritance-composableInterface-main", "testcases/inheritance/composableInterface/main")
module(":testcase-template-lib", "testcases/template/lib")
module(":testcase-template-main", "testcases/template/main")
module(":testcase-inheritance-funInterface-lib", "testcases/inheritance/funInterface/lib")
module(":testcase-inheritance-funInterface-main", "testcases/inheritance/funInterface/main")
module(":testcase-inheritance-composableInterface-lib", "testcases/inheritance/composableInterface/lib")
module(":testcase-inheritance-composableInterface-main", "testcases/inheritance/composableInterface/main")
module(":testcase-constructors-lib", "testcases/constructors/lib")
module(":testcase-constructors-main", "testcases/constructors/main")
module(":testcase-inheritance-funInterface-lib", "testcases/inheritance/funInterface/lib")
module(":testcase-inheritance-funInterface-main", "testcases/inheritance/funInterface/main")
module(":testcase-anonymousObjects-lib", "testcases/anonymousObjects/lib")
module(":testcase-anonymousObjects-main", "testcases/anonymousObjects/main")
module(":testcase-constructors-lib", "testcases/constructors/lib")
module(":testcase-constructors-main", "testcases/constructors/main")
module(":testcase-valueClass-lib", "testcases/valueClass/lib")
module(":testcase-valueClass-main", "testcases/valueClass/main")
module(":testcase-anonymousObjects-lib", "testcases/anonymousObjects/lib")
module(":testcase-anonymousObjects-main", "testcases/anonymousObjects/main")
module(":testcase-lambdas-lib", "testcases/lambdas/lib")
module(":testcase-lambdas-main", "testcases/lambdas/main")
module(":testcase-valueClass-lib", "testcases/valueClass/lib")
module(":testcase-valueClass-main", "testcases/valueClass/main")
module(":testcase-expectActual-lib", "testcases/expectActual/lib")
module(":testcase-expectActual-main", "testcases/expectActual/main")
module(":testcase-lambdas-lib", "testcases/lambdas/lib")
module(":testcase-lambdas-main", "testcases/lambdas/main")
module(":testcase-stability-lib", "testcases/stability/lib")
module(":testcase-stability-main", "testcases/stability/main")
}
module(":testcase-expectActual-lib", "testcases/expectActual/lib")
module(":testcase-expectActual-main", "testcases/expectActual/main")
/**
* Below we add modules for cases which are known to be failing at least on 1 platform.
* These cases should be fixed!
*/
"rememberAnonymousObj".also {
addATestCase(name = it, failingTestCaseNameSuffix = getFailingSuffix(it))
}
module(":testcase-stability-lib", "testcases/stability/lib")
module(":testcase-stability-main", "testcases/stability/main")

1
compose/integrations/composable-test-cases/testcases/anonymousObjects/lib/build.gradle.kts

@ -1,5 +1,6 @@
plugins {
kotlin("multiplatform")
alias(libs.plugins.composeCompiler)
}
kotlin {

1
compose/integrations/composable-test-cases/testcases/anonymousObjects/main/build.gradle.kts

@ -1,5 +1,6 @@
plugins {
kotlin("multiplatform")
alias(libs.plugins.composeCompiler)
}
kotlin {

1
compose/integrations/composable-test-cases/testcases/constructors/lib/build.gradle.kts

@ -1,5 +1,6 @@
plugins {
kotlin("multiplatform")
alias(libs.plugins.composeCompiler)
}
kotlin {

1
compose/integrations/composable-test-cases/testcases/constructors/main/build.gradle.kts

@ -1,5 +1,6 @@
plugins {
kotlin("multiplatform")
alias(libs.plugins.composeCompiler)
}
kotlin {

31
compose/integrations/composable-test-cases/testcases/expectActual/lib/build.gradle.kts

@ -1,5 +1,6 @@
plugins {
kotlin("multiplatform")
alias(libs.plugins.composeCompiler)
}
kotlin {
@ -14,35 +15,5 @@ kotlin {
val commonTest by getting {
configureCommonTestDependencies()
}
val nativeMain by creating {
dependsOn(commonMain)
}
val iosMain by getting {
dependsOn(nativeMain)
}
val iosX64Main by getting {
dependsOn(iosMain)
}
val iosArm64Main by getting {
dependsOn(iosMain)
}
val iosSimulatorArm64Main by getting {
dependsOn(iosMain)
}
val linuxX64Main by getting {
dependsOn(nativeMain)
}
val macosX64Main by getting {
dependsOn(nativeMain)
}
val macosArm64Main by getting {
dependsOn(nativeMain)
}
if (project.isMingwX64Enabled) {
val mingwX64Main by getting {
dependsOn(nativeMain)
}
}
}
}

1
compose/integrations/composable-test-cases/testcases/expectActual/main/build.gradle.kts

@ -1,5 +1,6 @@
plugins {
kotlin("multiplatform")
alias(libs.plugins.composeCompiler)
}
kotlin {

1
compose/integrations/composable-test-cases/testcases/inheritance/composableInterface/lib/build.gradle.kts

@ -1,5 +1,6 @@
plugins {
kotlin("multiplatform")
alias(libs.plugins.composeCompiler)
}
kotlin {

1
compose/integrations/composable-test-cases/testcases/inheritance/composableInterface/main/build.gradle.kts

@ -1,5 +1,6 @@
plugins {
kotlin("multiplatform")
alias(libs.plugins.composeCompiler)
}
kotlin {

1
compose/integrations/composable-test-cases/testcases/inheritance/funInterface/lib/build.gradle.kts

@ -1,5 +1,6 @@
plugins {
kotlin("multiplatform")
alias(libs.plugins.composeCompiler)
}
kotlin {

1
compose/integrations/composable-test-cases/testcases/inheritance/funInterface/main/build.gradle.kts

@ -1,5 +1,6 @@
plugins {
kotlin("multiplatform")
alias(libs.plugins.composeCompiler)
}
kotlin {

1
compose/integrations/composable-test-cases/testcases/lambdas/lib/build.gradle.kts

@ -1,5 +1,6 @@
plugins {
kotlin("multiplatform")
alias(libs.plugins.composeCompiler)
}
kotlin {

1
compose/integrations/composable-test-cases/testcases/lambdas/main/build.gradle.kts

@ -1,5 +1,6 @@
plugins {
kotlin("multiplatform")
alias(libs.plugins.composeCompiler)
}
kotlin {

1
compose/integrations/composable-test-cases/testcases/rememberAnonymousObj/lib/build.gradle.kts

@ -1,5 +1,6 @@
plugins {
kotlin("multiplatform")
alias(libs.plugins.composeCompiler)
}
kotlin {

1
compose/integrations/composable-test-cases/testcases/rememberAnonymousObj/main/build.gradle.kts

@ -1,5 +1,6 @@
plugins {
kotlin("multiplatform")
alias(libs.plugins.composeCompiler)
}
kotlin {

1
compose/integrations/composable-test-cases/testcases/stability/lib/build.gradle.kts

@ -1,5 +1,6 @@
plugins {
kotlin("multiplatform")
alias(libs.plugins.composeCompiler)
}
kotlin {

1
compose/integrations/composable-test-cases/testcases/stability/main/build.gradle.kts

@ -1,5 +1,6 @@
plugins {
kotlin("multiplatform")
alias(libs.plugins.composeCompiler)
}
kotlin {

1
compose/integrations/composable-test-cases/testcases/template/lib/build.gradle.kts

@ -1,5 +1,6 @@
plugins {
kotlin("multiplatform")
alias(libs.plugins.composeCompiler)
}
kotlin {

1
compose/integrations/composable-test-cases/testcases/template/main/build.gradle.kts

@ -1,5 +1,6 @@
plugins {
kotlin("multiplatform")
alias(libs.plugins.composeCompiler)
}
kotlin {

1
compose/integrations/composable-test-cases/testcases/valueClass/lib/build.gradle.kts

@ -1,5 +1,6 @@
plugins {
kotlin("multiplatform")
alias(libs.plugins.composeCompiler)
}
kotlin {

1
compose/integrations/composable-test-cases/testcases/valueClass/main/build.gradle.kts

@ -1,5 +1,6 @@
plugins {
kotlin("multiplatform")
alias(libs.plugins.composeCompiler)
}
kotlin {

Loading…
Cancel
Save