[stdlib] Set AV to 2.0, LV to 1.9 for main compilations, build tests with K2

This commit is contained in:
Ilya Gorbunov
2024-02-20 03:38:22 +01:00
committed by Space Team
parent 6152022838
commit 0ecbbbf1ca
7 changed files with 38 additions and 10 deletions
+3
View File
@@ -588,6 +588,9 @@ konanArtifacts {
"-opt-in=kotlin.native.internal.InternalForKotlinNative", "-opt-in=kotlin.native.internal.InternalForKotlinNative",
"-language-version", "-language-version",
"1.9", "1.9",
"-api-version",
"2.0",
"-Xsuppress-api-version-greater-than-language-version-error",
) )
commonStdlibSrcDirs.forEach { commonSrcDir(it) } commonStdlibSrcDirs.forEach { commonSrcDir(it) }
+24 -7
View File
@@ -1,6 +1,7 @@
@file:Suppress("UNUSED_VARIABLE", "NAME_SHADOWING") @file:Suppress("UNUSED_VARIABLE", "NAME_SHADOWING")
import org.gradle.jvm.tasks.Jar import org.gradle.jvm.tasks.Jar
import org.jetbrains.kotlin.gradle.dsl.JvmTarget import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
import org.jetbrains.kotlin.gradle.plugin.mpp.GenerateProjectStructureMetadata import org.jetbrains.kotlin.gradle.plugin.mpp.GenerateProjectStructureMetadata
@@ -40,6 +41,12 @@ fun outgoingConfiguration(name: String, configure: Action<Configuration> = Actio
configure(this) configure(this)
} }
fun KotlinCommonCompilerOptions.mainCompilationWithK1() {
languageVersion = KotlinVersion.KOTLIN_1_9
apiVersion = KotlinVersion.KOTLIN_2_0
freeCompilerArgs.add("-Xsuppress-api-version-greater-than-language-version-error")
}
val configurationBuiltins = resolvingConfiguration("builtins") { val configurationBuiltins = resolvingConfiguration("builtins") {
attributes.attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, project.objects.named(LibraryElements.JAR)) attributes.attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, project.objects.named(LibraryElements.JAR))
} }
@@ -83,9 +90,10 @@ kotlin {
diagnosticNamesArg, diagnosticNamesArg,
) )
) )
mainCompilationWithK1()
// workaround for compiling legacy MPP metadata, remove when this compilation is not needed anymore // workaround for compiling legacy MPP metadata, remove when this compilation is not needed anymore
// restate the list of opt-ins // restate the list of opt-ins
compilerOptions.optIn.addAll(commonOptIns) optIn.addAll(commonOptIns)
} }
} }
} }
@@ -122,6 +130,7 @@ kotlin {
diagnosticNamesArg, diagnosticNamesArg,
) )
) )
mainCompilationWithK1()
} }
} }
defaultSourceSet { defaultSourceSet {
@@ -147,6 +156,7 @@ kotlin {
diagnosticNamesArg, diagnosticNamesArg,
) )
) )
mainCompilationWithK1()
} }
} }
} }
@@ -165,6 +175,7 @@ kotlin {
diagnosticNamesArg, diagnosticNamesArg,
) )
) )
mainCompilationWithK1()
} }
} }
} }
@@ -219,15 +230,16 @@ kotlin {
compilations { compilations {
all { all {
kotlinOptions { kotlinOptions {
freeCompilerArgs += "-Xallow-kotlin-package" freeCompilerArgs += listOf(
"-Xallow-kotlin-package",
"-Xexpect-actual-classes",
)
} }
} }
val main by getting val main by getting {
main.apply {
kotlinOptions { kotlinOptions {
freeCompilerArgs += listOfNotNull( freeCompilerArgs += listOfNotNull(
"-Xir-module-name=kotlin", "-Xir-module-name=kotlin",
"-Xexpect-actual-classes",
diagnosticNamesArg, diagnosticNamesArg,
) )
@@ -235,6 +247,9 @@ kotlin {
allWarningsAsErrors = true allWarningsAsErrors = true
} }
} }
compileTaskProvider.configure {
compilerOptions.mainCompilationWithK1()
}
} }
} }
} }
@@ -251,10 +266,12 @@ kotlin {
diagnosticNamesArg diagnosticNamesArg
) )
} }
val main by getting val main by getting {
main.apply {
kotlinOptions.freeCompilerArgs += "-Xir-module-name=kotlin" kotlinOptions.freeCompilerArgs += "-Xir-module-name=kotlin"
kotlinOptions.allWarningsAsErrors = true kotlinOptions.allWarningsAsErrors = true
compileTaskProvider.configure {
compilerOptions.mainCompilationWithK1()
}
} }
} }
} }
+3
View File
@@ -37,6 +37,8 @@ compileKotlinCommon {
compileKotlinCommon { compileKotlinCommon {
kotlinOptions { kotlinOptions {
languageVersion = "1.9"
apiVersion = "2.0"
freeCompilerArgs = [ freeCompilerArgs = [
"-module-name", project.name, "-module-name", project.name,
"-opt-in=kotlin.RequiresOptIn", "-opt-in=kotlin.RequiresOptIn",
@@ -44,6 +46,7 @@ compileKotlinCommon {
"-opt-in=kotlin.contracts.ExperimentalContracts", "-opt-in=kotlin.contracts.ExperimentalContracts",
"-Xallow-kotlin-package", "-Xallow-kotlin-package",
"-Xexpect-actual-classes", "-Xexpect-actual-classes",
"-Xsuppress-api-version-greater-than-language-version-error",
] ]
} }
} }
@@ -148,6 +148,8 @@ kotlin {
} }
tasks.withType<KotlinCompile<*>> { tasks.withType<KotlinCompile<*>> {
kotlinOptions.languageVersion = "1.9"
kotlinOptions.apiVersion = "2.0"
kotlinOptions.freeCompilerArgs += listOf( kotlinOptions.freeCompilerArgs += listOf(
"-Xallow-kotlin-package", "-Xallow-kotlin-package",
"-Xexpect-actual-classes", "-Xexpect-actual-classes",
@@ -156,6 +158,7 @@ tasks.withType<KotlinCompile<*>> {
"-opt-in=kotlin.RequiresOptIn", "-opt-in=kotlin.RequiresOptIn",
"-opt-in=kotlin.ExperimentalUnsignedTypes", "-opt-in=kotlin.ExperimentalUnsignedTypes",
"-opt-in=kotlin.ExperimentalStdlibApi", "-opt-in=kotlin.ExperimentalStdlibApi",
"-Xsuppress-api-version-greater-than-language-version-error",
) )
} }
@@ -55,6 +55,8 @@ tasks.compileKotlin {
"kotlin/enums/EnumEntries.kt" "kotlin/enums/EnumEntries.kt"
).map { copySources.get().destinationDir.resolve(it) } ).map { copySources.get().destinationDir.resolve(it) }
kotlinOptions { kotlinOptions {
languageVersion = "1.9"
apiVersion = "2.0"
freeCompilerArgs += listOf( freeCompilerArgs += listOf(
"-Xallow-kotlin-package", "-Xallow-kotlin-package",
"-Xexpect-actual-classes", "-Xexpect-actual-classes",
@@ -62,6 +64,7 @@ tasks.compileKotlin {
"-opt-in=kotlin.RequiresOptIn", "-opt-in=kotlin.RequiresOptIn",
"-opt-in=kotlin.contracts.ExperimentalContracts", "-opt-in=kotlin.contracts.ExperimentalContracts",
"-opt-in=kotlin.ExperimentalMultiplatform", "-opt-in=kotlin.ExperimentalMultiplatform",
"-Xsuppress-api-version-greater-than-language-version-error",
) )
moduleName = "kotlin-stdlib" moduleName = "kotlin-stdlib"
} }
@@ -543,6 +543,7 @@ abstract class IterableTests<T : Iterable<String>>(val createFrom: (Array<out St
} }
@Test @Test
@Suppress("USELESS_CAST") // remove suppress and casts when tests are finally compiled only with K2
fun minusAssign() { fun minusAssign() {
// lets use a mutable variable // lets use a mutable variable
var result: Iterable<String> = data var result: Iterable<String> = data
@@ -133,10 +133,8 @@ fun Project.configureKotlinCompilationOptions() {
val coreLibProjects: List<String> by rootProject.extra val coreLibProjects: List<String> by rootProject.extra
val projectsWithForced19LanguageVersion = coreLibProjects + listOf( val projectsWithForced19LanguageVersion = coreLibProjects + listOf(
":kotlin-stdlib-jvm-minimal-for-test",
":kotlin-stdlib-js-ir-minimal-for-test",
":kotlin-dom-api-compat", ":kotlin-dom-api-compat",
) ) - listOf(":kotlin-stdlib", ":kotlin-stdlib-common")
tasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinCompile<*>>().configureEach { tasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinCompile<*>>().configureEach {
kotlinOptions { kotlinOptions {