1
0
mirror of https://github.com/mamoe/mirai.git synced 2025-04-25 13:03:35 +08:00

[build] Use language version 1.9 and enable Context Receivers for tests

This commit is contained in:
Him188 2023-04-25 11:35:17 +01:00
parent 7a5cbbcb88
commit e4ff4d108e
No known key found for this signature in database
GPG Key ID: BA439CDDCF652375
2 changed files with 33 additions and 0 deletions
buildSrc/src/main/kotlin

View File

@ -55,6 +55,22 @@ fun Project.enableLanguageFeatureForAllSourceSets(qualifiedClassname: String) {
}
}
fun Project.enableLanguageFeatureForTestSourceSets(name: String) {
allTestSourceSets {
languageSettings {
this.enableLanguageFeature(name)
}
}
}
fun Project.allTestSourceSets(action: KotlinSourceSet.() -> Unit) {
kotlinSourceSets!!.all {
if (this.name.contains("test", ignoreCase = true)) {
action()
}
}
}
fun Project.preConfigureJvmTarget() {
val defaultVer = jvmVersion()
@ -102,6 +118,7 @@ fun Project.configureJvmTarget() {
// IR cannot compile mirai. We'll wait for Kotlin 1.5 for stable IR release.
}
}
else -> {
}
}
@ -129,6 +146,7 @@ fun Project.configureKotlinTestSettings() {
"testRuntimeOnly"(`junit-jupiter-engine`)?.because(b)
}
}
isKotlinMpp -> {
kotlinSourceSets?.forEach { sourceSet ->
fun configureJvmTest(sourceSet: KotlinSourceSet) {
@ -154,6 +172,7 @@ fun Project.configureKotlinTestSettings() {
}
}
}
sourceSet.name.contains("test", ignoreCase = true) -> {
if (isJvmLikePlatform(target)) {
configureJvmTest(sourceSet)
@ -194,12 +213,24 @@ val experimentalAnnotations = arrayOf(
"io.ktor.utils.io.core.internal.DangerousInternalIoApi"
)
val testLanguageFeatures = listOf(
"ContextReceivers"
)
fun Project.configureKotlinExperimentalUsages() {
val sourceSets = kotlinSourceSets ?: return
for (target in sourceSets) {
target.configureKotlinExperimentalUsages()
}
for (name in testLanguageFeatures) {
enableLanguageFeatureForTestSourceSets(name)
}
allTestSourceSets {
languageSettings.languageVersion = Versions.kotlinLanguageVersionForTests
}
}
fun KotlinSourceSet.configureKotlinExperimentalUsages() {

View File

@ -33,6 +33,8 @@ object Versions {
const val kotlinCompiler = "1.8.10"
const val kotlinStdlib = kotlinCompiler
const val kotlinLanguageVersionForTests = "1.9" // be curious!
const val dokka = "1.8.10"
const val kotlinCompilerForIdeaPlugin = "1.8.20-RC" // 231 bundles 1.8.20