Skip to content

Commit ec75285

Browse files
authored
Merge pull request #45 from ForteScarlet/dev-k2
Support K2
2 parents 7795d55 + 2e82f83 commit ec75285

File tree

60 files changed

+3851
-281
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+3851
-281
lines changed

.github/workflows/publish-release.yml

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ env:
2121
jobs:
2222
test-build-publish:
2323
name: Test and build
24-
# runs-on: ubuntu-latest
24+
# runs-on: ubuntu-latest
2525
strategy:
2626
matrix:
2727
os: [ macos-latest, windows-latest, ubuntu-latest ]
@@ -96,17 +96,35 @@ jobs:
9696
create-release:
9797
name: Create release
9898
runs-on: ubuntu-latest
99-
needs: [test-build-publish, publish-gradle-plugin]
99+
needs: [ test-build-publish, publish-gradle-plugin ]
100100
permissions:
101101
contents: write
102102
steps:
103+
# 检出仓库代码
104+
- name: Check out repo
105+
uses: actions/checkout@v3
106+
107+
# Setup java
108+
# https://github.com/marketplace/actions/setup-java-jdk
109+
- name: Setup Java
110+
uses: actions/setup-java@v3
111+
with:
112+
distribution: 'zulu'
113+
java-version: 11
114+
115+
- name: Create changelog
116+
uses: gradle/gradle-build-action@v2
117+
with:
118+
gradle-version: 8.5
119+
arguments: createChangelog
120+
103121
# https://github.com/softprops/action-gh-release
104122
# Create gitHub release
105123
- name: Create Github Release
106124
uses: softprops/action-gh-release@v1
107125
with:
108126
token: ${{ secrets.FORTE_TOKEN }}
109127
draft: true
110-
# body_path: .changelog/${{ github.ref_name }}.md
128+
body_path: .changelog/${{ github.ref_name }}.md
111129
generate_release_notes: true
112130
prerelease: ${{ contains(github.ref_name, 'preview') || contains(github.ref_name, 'beta') || contains(github.ref_name, 'alpha') }}

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.gradle
2+
.kotlin
23
build/
34
!gradle/wrapper/gradle-wrapper.jar
45
!**/src/main/**/build/
@@ -28,4 +29,4 @@ out/
2829
.vscode/
2930

3031
### Mac OS ###
31-
.DS_Store
32+
.DS_Store

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class Foo {
7474
7575
### WasmJS
7676

77+
> [!warning]
7778
> Since `v0.6.0`, In experiments, immature and unstable
7879
7980
```kotlin
@@ -258,6 +259,13 @@ suspendTransform {
258259

259260
**Gradle JVM** must be JDK11+
260261

262+
### K2
263+
264+
K2 is supported since `v0.7.0`.
265+
266+
> [!warning]
267+
> In experiments.
268+
261269
## Effect
262270

263271
**source:**

README_CN.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class Foo {
7373
7474
### WasmJS
7575

76+
> [!warning]
7677
> `v0.6.0` 开始支持,实验中,不成熟、不稳定。
7778
7879
```kotlin
@@ -257,6 +258,13 @@ suspendTransform {
257258

258259
Gradle JVM 必须满足 JDK11+
259260

261+
### K2
262+
263+
K2 编译器从 `v0.7.0` 开始支持。
264+
265+
> [!warning]
266+
> 实验中。
267+
260268
## 效果
261269

262270
**源代码:**

build.gradle.kts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,16 @@ allprojects {
3030

3131
apply(plugin = "suspend-transform.nexus-publish")
3232

33+
tasks.create("createChangelog") {
34+
group = "documentation"
35+
doFirst {
36+
val tag = "v${IProject.version}"
37+
val changelogDir = rootProject.file(".changelog").apply { mkdirs() }
38+
with(File(changelogDir, "$tag.md")) {
39+
if (!exists()) {
40+
createNewFile()
41+
}
42+
writeText("Kotlin version: `v${libs.versions.kotlin.get()}`")
43+
}
44+
}
45+
}

buildSrc/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ repositories {
88
gradlePluginPortal()
99
}
1010

11-
val kotlinVersion = "1.9.21"
11+
val kotlinVersion: String = libs.versions.kotlin.get()
1212
val dokkaPluginVersion = "1.9.10"
1313
val gradleCommon = "0.2.0"
1414
val nexusPublishPlugin = "1.3.0"

buildSrc/settings.gradle.kts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
dependencyResolutionManagement {
3+
versionCatalogs {
4+
create("libs") {
5+
from(files("../gradle/libs.versions.toml"))
6+
}
7+
}
8+
}

buildSrc/src/main/kotlin/IProject.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import love.forte.gradle.common.core.project.ProjectDetail
22
import love.forte.gradle.common.core.project.Version
3+
import love.forte.gradle.common.core.project.minus
34
import love.forte.gradle.common.core.project.version
45

56
object IProject : ProjectDetail() {
@@ -8,7 +9,7 @@ object IProject : ProjectDetail() {
89
const val DESCRIPTION = "Generate platform-compatible functions for Kotlin suspend functions"
910
const val HOMEPAGE = "https://github.com/ForteScarlet/kotlin-suspend-transform-compiler-plugin"
1011

11-
override val version: Version = version(0, 6, 0)
12+
override val version: Version = version(0, 7, 0) - version("dev2")
1213

1314
override val homepage: String get() = HOMEPAGE
1415

compiler/suspend-transform-plugin/build.gradle.kts

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ plugins {
1111

1212
//testWithEmbedded0()
1313

14+
1415
dependencies {
1516
compileOnly(kotlin("stdlib"))
1617
compileOnly(kotlin("compiler"))
@@ -22,25 +23,41 @@ dependencies {
2223
kapt(libs.google.auto.service)
2324
compileOnly(libs.google.auto.service.annotations)
2425

26+
testImplementation("junit:junit:4.13.2")
2527
testImplementation(kotlin("stdlib"))
26-
testImplementation(kotlin("test-junit"))
27-
testImplementation(kotlin("compiler-embeddable"))
28-
testImplementation(kotlin("reflect"))
29-
// testImplementation("org.jetbrains.kotlin:kotlin-compiler-embeddable")
28+
testImplementation(kotlin("test-junit5"))
3029

30+
testImplementation(kotlin("compiler"))
31+
testImplementation(kotlin("reflect"))
32+
// see https://github.com/Icyrockton/xjson
33+
testImplementation(kotlin("compiler-internal-test-framework")) // compiler plugin test generator / test utils
34+
testRuntimeOnly(kotlin("test"))
35+
testRuntimeOnly(kotlin("script-runtime"))
36+
testRuntimeOnly(kotlin("annotations-jvm"))
3137
testImplementation(project(":runtime:suspend-transform-annotation"))
3238
testImplementation(project(":runtime:suspend-transform-runtime"))
3339

34-
testImplementation("com.github.tschuchortdev:kotlin-compile-testing:1.4.9")
40+
// testImplementation("com.github.tschuchortdev:kotlin-compile-testing:1.4.9")
3541
// testImplementation("org.bitbucket.mstrobel:procyon-compilertools:0.6.0")
36-
// testImplementation("com.bennyhuo.kotlin:kotlin-compile-testing-extensions:1.7.10.2-SNAPSHOT")
3742

3843
testImplementation(libs.kotlinx.coroutines.core)
39-
// testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.6.4")
4044
}
4145

4246
val compileKotlin: KotlinCompile by tasks
43-
compileKotlin.kotlinOptions.freeCompilerArgs += listOf("-Xjvm-default=all", "-opt-in=kotlin.RequiresOptIn")
47+
compileKotlin.kotlinOptions.freeCompilerArgs += listOf(
48+
"-Xjvm-default=all",
49+
"-opt-in=kotlin.RequiresOptIn",
50+
"-opt-in=org.jetbrains.kotlin.ir.symbols.UnsafeDuringIrConstructionAPI",
51+
)
52+
53+
tasks.withType(KotlinCompile::class.java).configureEach {
54+
// see https://youtrack.jetbrains.com/issue/KTIJ-21563
55+
// see https://youtrack.jetbrains.com/issue/KT-57297
56+
// kotlinOptions {
57+
// languageVersion = "1.9"
58+
// apiVersion = "1.9"
59+
// }
60+
}
4461

4562
repositories {
4663
maven {
@@ -62,3 +79,44 @@ buildConfig {
6279
tasks.withType<KotlinCompile> {
6380
kotlinOptions.jvmTarget = "1.8"
6481
}
82+
83+
84+
sourceSets {
85+
test{
86+
kotlin.srcDir("src/test")
87+
kotlin.srcDir("src/test-gen")
88+
java.srcDir("src/test-gen")
89+
}
90+
}
91+
92+
task<JavaExec>("generateTest") {
93+
classpath = sourceSets.test.get().runtimeClasspath
94+
mainClass = "love.forte.plugin.suspendtrans.GenerateTestsKt"
95+
}
96+
97+
// add following properties for test
98+
tasks.test {
99+
useJUnitPlatform()
100+
doFirst {
101+
setLibraryProperty("org.jetbrains.kotlin.test.kotlin-stdlib", "kotlin-stdlib")
102+
setLibraryProperty("org.jetbrains.kotlin.test.kotlin-stdlib-jdk8", "kotlin-stdlib-jdk8")
103+
setLibraryProperty("org.jetbrains.kotlin.test.kotlin-reflect", "kotlin-reflect")
104+
setLibraryProperty("org.jetbrains.kotlin.test.kotlin-test", "kotlin-test")
105+
setLibraryProperty("org.jetbrains.kotlin.test.kotlin-script-runtime", "kotlin-script-runtime")
106+
setLibraryProperty("org.jetbrains.kotlin.test.kotlin-annotations-jvm", "kotlin-annotations-jvm")
107+
}
108+
}
109+
110+
fun Test.setLibraryProperty(propName: String, jarName: String) {
111+
val path = project.configurations
112+
.testRuntimeClasspath.get()
113+
.files
114+
.find { """$jarName-\d.*jar""".toRegex().matches(it.name) }
115+
?.absolutePath
116+
?: return
117+
systemProperty(propName, path)
118+
}
119+
120+
/*
121+
上面与测试相关的一些内容参考自 https://github.com/Icyrockton/xjson
122+
*/
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package love.forte.plugin.suspendtrans
2+
3+
const val PLUGIN_REPORT_ID = "love.forte.plugin.suspendtrans.SuspendTransform"

0 commit comments

Comments
 (0)