Skip to content

Commit

Permalink
Merge pull request #977 from simple-robot/upgrade-kt
Browse files Browse the repository at this point in the history
Update Kotlin to 2.1.0; Update Gradle to 8.6; Update kcp: KSP, SuspendTransform
  • Loading branch information
ForteScarlet authored Dec 3, 2024
2 parents 5c3bd51 + 2fe778c commit 9d93d59
Show file tree
Hide file tree
Showing 17 changed files with 271 additions and 336 deletions.
60 changes: 30 additions & 30 deletions .github/workflows/publish-v4-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
test-and-publish-v4-release:
name: Publish v4 Release
needs: test-pre-release
runs-on: macos-latest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
Expand Down Expand Up @@ -82,35 +82,35 @@ jobs:
SIMBOT_RELEASES_ONLY: true
SIMBOT_SNAPSHOT_ONLY: false

publish-v4-snapshot:
name: Publish V4 snapshot
runs-on: macos-latest
needs: test-and-publish-v4-release
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: ${{ env.JAVA_DISTRIBUTION }}
java-version: ${{ env.JAVA_VERSION }}
cache: 'gradle'

# setup Gradle
- name: Gradle publish snapshot
uses: gradle/actions/setup-gradle@v3
with:
gradle-version: ${{ env.GRADLE_VERSION }}
arguments: |
publishToSonatype
closeAndReleaseStagingRepositories
-s
--warning-mode all
-x test
--build-cache
-Porg.gradle.jvmargs="-XX:MaxMetaspaceSize=1g -Dfile.encoding=UTF-8"
env:
SIMBOT_IS_SNAPSHOT: true
SIMBOT_SNAPSHOT_ONLY: true
SIMBOT_RELEASES_ONLY: false
# publish-v4-snapshot:
# name: Publish V4 snapshot
# runs-on: ubuntu-latest
# needs: test-and-publish-v4-release
# steps:
# - uses: actions/checkout@v4
# - uses: actions/setup-java@v4
# with:
# distribution: ${{ env.JAVA_DISTRIBUTION }}
# java-version: ${{ env.JAVA_VERSION }}
# cache: 'gradle'
#
# # setup Gradle
# - name: Gradle publish snapshot
# uses: gradle/actions/setup-gradle@v3
# with:
# gradle-version: ${{ env.GRADLE_VERSION }}
# arguments: |
# publishToSonatype
# closeAndReleaseStagingRepositories
# -s
# --warning-mode all
# -x test
# --build-cache
# -Porg.gradle.jvmargs="-XX:MaxMetaspaceSize=1g -Dfile.encoding=UTF-8"
# env:
# SIMBOT_IS_SNAPSHOT: true
# SIMBOT_SNAPSHOT_ONLY: true
# SIMBOT_RELEASES_ONLY: false

deploy-doc:
name: Deploy V4 API Doc
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-v4-snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
publish-v4-snapshot:
name: Publish v4 snapshot
needs: run-tests
runs-on: macos-latest
runs-on: ubuntu-latest
steps:
# 检出仓库代码
- uses: actions/checkout@v4
Expand Down
6 changes: 5 additions & 1 deletion .idea/dictionaries/forte.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

211 changes: 203 additions & 8 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*/

import io.gitlab.arturbosch.detekt.Detekt
import love.forte.plugin.suspendtrans.*
import love.forte.plugin.suspendtrans.gradle.SuspendTransformGradleExtension

plugins {
idea
Expand All @@ -30,6 +32,9 @@ plugins {
alias(libs.plugins.detekt)
id("simbot.nexus-publish")
id("simbot.changelog-generator")
alias(libs.plugins.suspendTransform) apply false
// id("love.forte.plugin.suspend-transform") version "2.1.0-0.9.4" apply false


// https://www.jetbrains.com/help/qodana/code-coverage.html
// https://github.com/Kotlin/kotlinx-kover
Expand Down Expand Up @@ -81,8 +86,11 @@ subprojects {
}

applyKover(root)
}

if (plugins.hasPlugin(libs.plugins.suspendTransform.get().pluginId)) {
configureSuspendTransform()
}
}
}

dependencies {
Expand Down Expand Up @@ -173,12 +181,199 @@ idea {
}

// https://kotlinlang.org/docs/js-project-setup.html#node-js
rootProject.plugins.withType<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin> {
rootProject.the<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension>().apply {
// CI 中配置环境,不再单独下载
if (isCi) {
download = false
}
// rootProject.plugins.withType<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin> {
// rootProject.the<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension>().apply {
// // CI 中配置环境,不再单独下载
// // if (isCi) {
// // download = false
// // }
// }
// // "true" for default behavior
// }

// region Suspend Transform configs
@Suppress("MaxLineLength")
object SuspendTransforms {
private val javaIncludeAnnotationApi4JClassInfo = ClassInfo("love.forte.simbot.annotations", "Api4J")
private val javaIncludeAnnotationApi4J = IncludeAnnotation(javaIncludeAnnotationApi4JClassInfo).apply {
includeProperty = true
}
private val javaIncludeAnnotations = listOf(javaIncludeAnnotationApi4J)

private val jsIncludeAnnotationApi4JsClassInfo = ClassInfo("love.forte.simbot.annotations", "Api4Js")
private val jsIncludeAnnotationApi4Js = IncludeAnnotation(jsIncludeAnnotationApi4JsClassInfo).apply {
includeProperty = true
}
private val jsIncludeAnnotations = listOf(jsIncludeAnnotationApi4Js)


private val SuspendReserveClassInfo = ClassInfo(
packageName = "love.forte.simbot.suspendrunner.reserve",
className = "SuspendReserve",
)

/**
* JvmBlocking
*/
val jvmBlockingTransformer = SuspendTransformConfiguration.jvmBlockingTransformer.copy(
syntheticFunctionIncludeAnnotations = javaIncludeAnnotations,
transformFunctionInfo = FunctionInfo("love.forte.simbot.suspendrunner", null, "$\$runInBlocking"),
copyAnnotationExcludes = SuspendTransformConfiguration.jvmBlockingTransformer.copyAnnotationExcludes + SuspendTransformConfiguration.jvmBlockingTransformer.markAnnotation.classInfo
)

/**
* JvmAsync
*/
val jvmAsyncTransformer = SuspendTransformConfiguration.jvmAsyncTransformer.copy(
syntheticFunctionIncludeAnnotations = javaIncludeAnnotations,
transformFunctionInfo = FunctionInfo("love.forte.simbot.suspendrunner", null, "$\$runInAsyncNullable"),
copyAnnotationExcludes = SuspendTransformConfiguration.jvmAsyncTransformer.copyAnnotationExcludes + SuspendTransformConfiguration.jvmAsyncTransformer.markAnnotation.classInfo
)

/**
* JvmReserve
*/
val jvmReserveTransformer = SuspendTransformConfiguration.jvmAsyncTransformer.copy(
syntheticFunctionIncludeAnnotations = javaIncludeAnnotations,
transformFunctionInfo = FunctionInfo("love.forte.simbot.suspendrunner", null, "$\$asReserve"),
copyAnnotationExcludes = SuspendTransformConfiguration.jvmAsyncTransformer.copyAnnotationExcludes + SuspendTransformConfiguration.jvmAsyncTransformer.markAnnotation.classInfo,
transformReturnType = SuspendReserveClassInfo,
transformReturnTypeGeneric = true,
)

/**
* JsPromise
*/
val jsPromiseTransformer = SuspendTransformConfiguration.jsPromiseTransformer.copy(
syntheticFunctionIncludeAnnotations = javaIncludeAnnotations,
transformFunctionInfo = FunctionInfo("love.forte.simbot.suspendrunner", null, "$\$runInPromise"),
copyAnnotationExcludes = SuspendTransformConfiguration.jsPromiseTransformer.copyAnnotationExcludes + SuspendTransformConfiguration.jsPromiseTransformer.markAnnotation.classInfo,
)

//region @JvmSuspendTrans
private val suspendTransMarkAnnotationClassInfo = ClassInfo("love.forte.simbot.suspendrunner", "SuspendTrans")

private val jvmSuspendTransMarkAnnotationForBlocking = MarkAnnotation(
suspendTransMarkAnnotationClassInfo,
baseNameProperty = "blockingBaseName",
suffixProperty = "blockingSuffix",
asPropertyProperty = "blockingAsProperty",
defaultSuffix = SuspendTransformConfiguration.jvmBlockingAnnotationInfo.defaultSuffix,
)
private val jvmSuspendTransMarkAnnotationForAsync = MarkAnnotation(
suspendTransMarkAnnotationClassInfo,
baseNameProperty = "asyncBaseName",
suffixProperty = "asyncSuffix",
asPropertyProperty = "asyncAsProperty",
defaultSuffix = SuspendTransformConfiguration.jvmAsyncAnnotationInfo.defaultSuffix,
)
private val jvmSuspendTransMarkAnnotationForReserve = MarkAnnotation(
suspendTransMarkAnnotationClassInfo,
baseNameProperty = "reserveBaseName",
suffixProperty = "reserveSuffix",
asPropertyProperty = "reserveAsProperty",
defaultSuffix = "Reserve",
)
private val jsSuspendTransMarkAnnotationForPromise = MarkAnnotation(
suspendTransMarkAnnotationClassInfo,
baseNameProperty = "jsPromiseBaseName",
suffixProperty = "jsPromiseSuffix",
asPropertyProperty = "jsPromiseAsProperty",
defaultSuffix = "Async",
)

val suspendTransTransformerForJvmBlocking = jvmBlockingTransformer.copy(
markAnnotation = jvmSuspendTransMarkAnnotationForBlocking,
copyAnnotationExcludes = SuspendTransformConfiguration.jvmBlockingTransformer.copyAnnotationExcludes + jvmSuspendTransMarkAnnotationForBlocking.classInfo
)

val suspendTransTransformerForJvmAsync = jvmAsyncTransformer.copy(
markAnnotation = jvmSuspendTransMarkAnnotationForAsync,
copyAnnotationExcludes = SuspendTransformConfiguration.jvmAsyncTransformer.copyAnnotationExcludes + jvmSuspendTransMarkAnnotationForAsync.classInfo
)

val suspendTransTransformerForJvmReserve = jvmReserveTransformer.copy(
markAnnotation = jvmSuspendTransMarkAnnotationForReserve,
copyAnnotationExcludes = jvmReserveTransformer.copyAnnotationExcludes + jvmSuspendTransMarkAnnotationForReserve.classInfo,
)

val suspendTransTransformerForJsPromise = jsPromiseTransformer.copy(
markAnnotation = jvmSuspendTransMarkAnnotationForReserve,
copyAnnotationExcludes = jsPromiseTransformer.copyAnnotationExcludes + jsSuspendTransMarkAnnotationForPromise.classInfo,
)
//endregion

//region @JvmSuspendTransProperty
private val jvmSuspendTransPropMarkAnnotationClassInfo =
ClassInfo("love.forte.simbot.suspendrunner", "SuspendTransProperty")

private val jvmSuspendTransPropMarkAnnotationForBlocking = MarkAnnotation(
jvmSuspendTransPropMarkAnnotationClassInfo,
baseNameProperty = "blockingBaseName",
suffixProperty = "blockingSuffix",
asPropertyProperty = "blockingAsProperty",
defaultSuffix = "",
defaultAsProperty = true
)
private val jvmSuspendTransPropMarkAnnotationForAsync = MarkAnnotation(
jvmSuspendTransPropMarkAnnotationClassInfo,
baseNameProperty = "asyncBaseName",
suffixProperty = "asyncSuffix",
asPropertyProperty = "asyncAsProperty",
defaultSuffix = SuspendTransformConfiguration.jvmAsyncAnnotationInfo.defaultSuffix,
defaultAsProperty = true
)
private val jvmSuspendTransPropMarkAnnotationForReserve = MarkAnnotation(
jvmSuspendTransPropMarkAnnotationClassInfo,
baseNameProperty = "reserveBaseName",
suffixProperty = "reserveSuffix",
asPropertyProperty = "reserveAsProperty",
defaultSuffix = "Reserve",
defaultAsProperty = true
)

val jvmSuspendTransPropTransformerForBlocking = jvmBlockingTransformer.copy(
markAnnotation = jvmSuspendTransPropMarkAnnotationForBlocking,
copyAnnotationExcludes = SuspendTransformConfiguration.jvmBlockingTransformer.copyAnnotationExcludes + jvmSuspendTransPropMarkAnnotationForBlocking.classInfo
)

val jvmSuspendTransPropTransformerForAsync = jvmAsyncTransformer.copy(
markAnnotation = jvmSuspendTransPropMarkAnnotationForAsync,
copyAnnotationExcludes = SuspendTransformConfiguration.jvmAsyncTransformer.copyAnnotationExcludes + jvmSuspendTransPropMarkAnnotationForAsync.classInfo
)

val jvmSuspendTransPropTransformerForReserve = jvmReserveTransformer.copy(
markAnnotation = jvmSuspendTransPropMarkAnnotationForReserve,
copyAnnotationExcludes = jvmReserveTransformer.copyAnnotationExcludes + jvmSuspendTransPropMarkAnnotationForReserve.classInfo
)
//endregion
}

fun Project.configureSuspendTransform() {
extensions.configure<SuspendTransformGradleExtension>("suspendTransform") {
includeRuntime = false
includeAnnotation = false

addJvmTransformers(
// @JvmBlocking
SuspendTransforms.jvmBlockingTransformer,
// @JvmAsync
SuspendTransforms.jvmAsyncTransformer,

// @JvmSuspendTrans
SuspendTransforms.suspendTransTransformerForJvmBlocking,
SuspendTransforms.suspendTransTransformerForJvmAsync,
SuspendTransforms.suspendTransTransformerForJvmReserve,

// @JvmSuspendTransProperty
SuspendTransforms.jvmSuspendTransPropTransformerForBlocking,
SuspendTransforms.jvmSuspendTransPropTransformerForAsync,
SuspendTransforms.jvmSuspendTransPropTransformerForReserve,
)

// addJsTransformers(
// SuspendTransforms.suspendTransTransformerForJsPromise,
// )
}
// "true" for default behavior
}
// endregion
6 changes: 4 additions & 2 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ plugins {
repositories {
mavenCentral()
gradlePluginPortal()
mavenLocal()
// mavenLocal()
}

val kotlinVersion: String = libs.versions.kotlin.get()
Expand All @@ -38,13 +38,15 @@ dependencies {
implementation(kotlin("gradle-plugin", kotlinVersion))
implementation(kotlin("serialization", kotlinVersion))
implementation(kotlin("power-assert", kotlinVersion))
// compileOnly(kotlin("compiler", kotlinVersion))
// compileOnly(kotlin("compiler-embeddable", kotlinVersion))
implementation(libs.bundles.dokka)

// see https://github.com/gradle-nexus/publish-plugin
implementation(libs.gradleNexusPublishPlugin)

// suspend transform
implementation(libs.suspend.transform.gradle)
// implementation(libs.suspend.transform.gradle)

// gradle common
implementation(libs.bundles.gradle.common)
Expand Down
6 changes: 2 additions & 4 deletions buildSrc/src/main/kotlin/JvmConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,13 @@ import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.getByName
import org.gradle.kotlin.dsl.withType
import org.gradle.process.CommandLineArgumentProvider
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinBaseExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinTopLevelExtension
import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget


@OptIn(ExperimentalKotlinGradlePluginApi::class)
inline fun KotlinJvmTarget.configJava(crossinline block: KotlinJvmTarget.() -> Unit = {}) {
withJava()
compilerOptions {
Expand All @@ -56,7 +54,7 @@ inline fun KotlinJvmTarget.configJava(crossinline block: KotlinJvmTarget.() -> U
}


fun KotlinTopLevelExtension.configJavaToolchain(jdkVersion: Int) {
fun KotlinBaseExtension.configJavaToolchain(jdkVersion: Int) {
jvmToolchain(jdkVersion)
}

Expand Down
4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/P.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ fun isSnapshot(): Boolean = _isSnapshot
@Suppress("MemberVisibilityCanBePrivate")
sealed class P(override val group: String) : ProjectDetail() {
companion object {
const val VERSION = "4.8.0"
const val NEXT_VERSION = "4.8.1"
const val VERSION = "4.9.0"
const val NEXT_VERSION = "4.9.0"
const val SNAPSHOT_VERSION = "$VERSION-SNAPSHOT"
const val NEXT_SNAPSHOT_VERSION = "$NEXT_VERSION-SNAPSHOT"

Expand Down
Loading

0 comments on commit 9d93d59

Please sign in to comment.