Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support default enum arguments, Kotlin 2.0.20 #11

Merged
merged 3 commits into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ jobs:
CHECK_DEPLOY:
name: Deploy locally
runs-on: ubuntu-latest
env:
GHUB_USER: ${{ secrets.GHUB_USER }}
GHUB_PERSONAL_ACCESS_TOKEN: ${{ secrets.GHUB_PERSONAL_ACCESS_TOKEN }}
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
Expand All @@ -27,11 +22,6 @@ jobs:
CHECK_TESTS:
name: Run emulator tests
runs-on: ubuntu-latest
env:
GHUB_USER: ${{ secrets.GHUB_USER }}
GHUB_PERSONAL_ACCESS_TOKEN: ${{ secrets.GHUB_PERSONAL_ACCESS_TOKEN }}
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
types: [published]
jobs:
DEPLOY:
name: Sonatype Upload
name: GitHub and Maven Central publication
runs-on: ubuntu-latest
env:
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
Expand All @@ -20,7 +20,7 @@ jobs:
java-version: 17
distribution: temurin
cache: gradle
- name: Publish to Sonatype
run: ./gradlew deploySonatype
- name: Publish to Maven Central
run: ./gradlew deployNexus
- name: Publish to GitHub Packages
run: ./gradlew deployGithub
6 changes: 2 additions & 4 deletions .github/workflows/snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@ jobs:
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
SONATYPE_USER: ${{ secrets.SONATYPE_USER }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
GHUB_USER: ${{ secrets.GHUB_USER }}
GHUB_PERSONAL_ACCESS_TOKEN: ${{ secrets.GHUB_PERSONAL_ACCESS_TOKEN }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin
cache: gradle
- name: Publish sonatype snapshot
run: ./gradlew deploySonatypeSnapshot
- name: Publish Nexus Snapshot
run: ./gradlew deployNexusSnapshot
12 changes: 8 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ subprojects {
// Publishing
plugins.withId("io.deepmedia.tools.deployer") {
extensions.configure<DeployerExtension> {
verbose.set(true)
verbose.set(providers.environmentVariable("CI").orElse("").map { it.isNotBlank() })

projectInfo {
description.set("A Kotlin Compiler Plugin for seamless communication between Kotlin/Native and Kotlin/JVM.")
Expand All @@ -31,17 +31,21 @@ subprojects {
}

// use "deployLocal" to deploy to local maven repository
localSpec()
localSpec {
// directory = rootProject.layout.buildDirectory.dir("inspect")
signing.password = absent()
signing.key = absent()
}

// use "deploySonatype" to deploy to OSSRH / maven central
sonatypeSpec {
nexusSpec {
syncToMavenCentral = true
auth.user.set(secret("SONATYPE_USER"))
auth.password.set(secret("SONATYPE_PASSWORD"))
}

// use "deploySonatypeSnapshot" to deploy to sonatype snapshots repo
sonatypeSpec("snapshot") {
nexusSpec("snapshot") {
auth.user.set(secret("SONATYPE_USER"))
auth.password.set(secret("SONATYPE_PASSWORD"))
repositoryUrl.set(ossrhSnapshots1)
Expand Down
8 changes: 8 additions & 0 deletions knee-compiler-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3")
}

kotlin {
target {
compilerOptions {
optIn.add("org.jetbrains.kotlin.ir.symbols.UnsafeDuringIrConstructionAPI")
}
}
}

// Annoying configuration needed because of https://youtrack.jetbrains.com/issue/KT-53477/
// Compiler plugins can't have dependency in Native, unless we use a fat jar.
tasks.shadowJar.configure {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import org.jetbrains.kotlin.ir.util.dumpKotlinLike
import org.jetbrains.kotlin.ir.util.getAnnotation


@ConsistentCopyVisibility
@Serializable
data class ModuleMetadata private constructor(
@Contextual private val dependencyModules_: List<IrClass_>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
import org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
import org.jetbrains.kotlin.config.CommonConfigurationKeys
import org.jetbrains.kotlin.config.CompilerConfiguration
import java.io.File

@OptIn(ExperimentalCompilerApi::class)
class KneeComponentRegistrar : CompilerPluginRegistrar() {
override fun ExtensionStorage.registerExtensions(configuration: CompilerConfiguration) {
if (configuration[KneeCommandLineProcessor.KneeEnabled] == false) return
val logs = configuration[CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY]!!
val logs = configuration[CommonConfigurationKeys.MESSAGE_COLLECTOR_KEY]!!
val verboseLogs = configuration[KneeCommandLineProcessor.KneeVerboseLogs] ?: false
val verboseRuntime = configuration[KneeCommandLineProcessor.KneeVerboseRuntime] ?: false
val verboseCodegen = configuration[KneeCommandLineProcessor.KneeVerboseSources] ?: false
Expand Down
10 changes: 9 additions & 1 deletion knee-compiler-plugin/src/main/kotlin/utils/PoetUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ package io.deepmedia.tools.knee.plugin.compiler.utils

import com.squareup.kotlinpoet.*
import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy
import io.deepmedia.tools.knee.plugin.compiler.codegen.CodegenType
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.expressions.IrConst
import org.jetbrains.kotlin.ir.expressions.IrConstKind
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
import org.jetbrains.kotlin.ir.expressions.IrGetEnumValue
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
import org.jetbrains.kotlin.ir.symbols.IrEnumEntrySymbol
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
import org.jetbrains.kotlin.ir.types.*
import org.jetbrains.kotlin.ir.util.dump
import org.jetbrains.kotlin.types.Variance


Expand Down Expand Up @@ -212,8 +216,12 @@ fun IrValueParameter.defaultValueForCodegen(functionExpects: List<IrDeclarationW
// is IrConstKind.Long -> CodeBlock.of(kind.valueOf(expression).toString() + "L")
// else -> return null
}
} else if (expression is IrGetEnumValue && type is IrSimpleType) {
// No need to check whether the type is serializable, that would throw an error somewhere else
val type: TypeName = (type as IrSimpleType).asTypeName()
val entry: String = expression.symbol.owner.name.asString()
return CodeBlock.of("%T.%N", type, entry)
}
// risky option: take expression.dumpKotlinLike() as string.
return null
}

Expand Down
8 changes: 4 additions & 4 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ pluginManagement {
}

plugins {
kotlin("multiplatform") version "2.0.0" apply false
kotlin("plugin.serialization") version "2.0.0" apply false
kotlin("jvm") version "2.0.0" apply false
id("io.deepmedia.tools.deployer") version "0.12.0" apply false
kotlin("multiplatform") version "2.0.20" apply false
kotlin("plugin.serialization") version "2.0.20" apply false
kotlin("jvm") version "2.0.20" apply false
id("io.deepmedia.tools.deployer") version "0.14.0" apply false
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/test-classes/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
@file:Suppress("UnstableApiUsage")

plugins {
kotlin("multiplatform") version "2.0.0"
kotlin("multiplatform") version "2.0.20"
id("com.android.application") version "8.1.1"
id("io.deepmedia.tools.knee") version "0.3.0-SNAPSHOT"
id("io.deepmedia.tools.knee") version "1.0.0"
}

configurations.configureEach {
Expand Down
4 changes: 2 additions & 2 deletions tests/test-coroutines/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
@file:Suppress("UnstableApiUsage")

plugins {
kotlin("multiplatform") version "2.0.0"
kotlin("multiplatform") version "2.0.20"
id("com.android.application") version "8.1.1"
id("io.deepmedia.tools.knee") version "0.3.0-SNAPSHOT"
id("io.deepmedia.tools.knee") version "1.0.0"
}

configurations.configureEach {
Expand Down
4 changes: 2 additions & 2 deletions tests/test-imports/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
@file:Suppress("UnstableApiUsage")

plugins {
kotlin("multiplatform") version "2.0.0"
kotlin("multiplatform") version "2.0.20"
id("com.android.application") version "8.1.1"
id("io.deepmedia.tools.knee") version "0.3.0-SNAPSHOT"
id("io.deepmedia.tools.knee") version "1.0.0"
}

configurations.configureEach {
Expand Down
4 changes: 2 additions & 2 deletions tests/test-interfaces/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
@file:Suppress("UnstableApiUsage")

plugins {
kotlin("multiplatform") version "2.0.0"
kotlin("multiplatform") version "2.0.20"
id("com.android.application") version "8.1.1"
id("io.deepmedia.tools.knee") version "0.3.0-SNAPSHOT"
id("io.deepmedia.tools.knee") version "1.0.0"
}

configurations.configureEach {
Expand Down
4 changes: 2 additions & 2 deletions tests/test-misc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
@file:Suppress("UnstableApiUsage")

plugins {
kotlin("multiplatform") version "2.0.0"
kotlin("multiplatform") version "2.0.20"
id("com.android.application") version "8.1.1"
id("io.deepmedia.tools.knee") version "0.3.0-SNAPSHOT"
id("io.deepmedia.tools.knee") version "1.0.0"
}

configurations.configureEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@ class DefaultValuesTests {
emptyStringDefaultValue()
}

@Test
fun testDefaultValue_enum() {
enumDefaultValue()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,13 @@ interface BaseInterfaceWithDefaultValues {

@Knee
fun emptyStringDefaultValue(foo: String = "") {
}

@Knee
fun enumDefaultValue(foo: DefaultValuesEnum = DefaultValuesEnum.First) {
}

@KneeEnum
enum class DefaultValuesEnum {
First, Second
}
4 changes: 2 additions & 2 deletions tests/test-primitives/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
@file:Suppress("UnstableApiUsage")

plugins {
kotlin("multiplatform") version "2.0.0"
kotlin("multiplatform") version "2.0.20"
id("com.android.application") version "8.1.1"
id("io.deepmedia.tools.knee") version "0.3.0-SNAPSHOT"
id("io.deepmedia.tools.knee") version "1.0.0"
}

configurations.configureEach {
Expand Down