From aba00de83bbbfa9c51ffa10cc863cb253e70dd70 Mon Sep 17 00:00:00 2001 From: Filipp Zhinkin Date: Wed, 24 Jan 2024 13:21:27 +0100 Subject: [PATCH] [ABI Validation] Update ASM * Update ASM to 9.6 * Added Java versions compatibility test Pull request https://github.com/Kotlin/binary-compatibility-validator/pull/173 --- .../abi-validation/gradle/libs.versions.toml | 2 +- .../kotlin/kotlinx/validation/api/TestDsl.kt | 17 +++- .../test/JavaVersionsCompatibilityTest.kt | 96 +++++++++++++++++++ .../gradle/base/jdkCompatibility.gradle.kts | 33 +++++++ ...dkCompatibilityWithExactVersion.gradle.kts | 28 ++++++ .../settings/jdk-provisioning.gradle.kts | 8 ++ 6 files changed, 179 insertions(+), 5 deletions(-) create mode 100644 libraries/tools/abi-validation/src/functionalTest/kotlin/kotlinx/validation/test/JavaVersionsCompatibilityTest.kt create mode 100644 libraries/tools/abi-validation/src/functionalTest/resources/examples/gradle/base/jdkCompatibility.gradle.kts create mode 100644 libraries/tools/abi-validation/src/functionalTest/resources/examples/gradle/base/jdkCompatibilityWithExactVersion.gradle.kts create mode 100644 libraries/tools/abi-validation/src/functionalTest/resources/examples/gradle/settings/jdk-provisioning.gradle.kts diff --git a/libraries/tools/abi-validation/gradle/libs.versions.toml b/libraries/tools/abi-validation/gradle/libs.versions.toml index b4241171d7383..c2c0ded2262e5 100644 --- a/libraries/tools/abi-validation/gradle/libs.versions.toml +++ b/libraries/tools/abi-validation/gradle/libs.versions.toml @@ -6,7 +6,7 @@ javaDiffUtils = "4.12" junit = "5.9.2" kotest = "5.5.5" kotlinx-bcv = "0.13.1" -ow2Asm = "9.2" +ow2Asm = "9.6" gradlePluginPublishPlugin = "1.1.0" androidGradlePlugin = "7.2.2" diff --git a/libraries/tools/abi-validation/src/functionalTest/kotlin/kotlinx/validation/api/TestDsl.kt b/libraries/tools/abi-validation/src/functionalTest/kotlin/kotlinx/validation/api/TestDsl.kt index 8a70f946c1844..6c83d163619cb 100644 --- a/libraries/tools/abi-validation/src/functionalTest/kotlin/kotlinx/validation/api/TestDsl.kt +++ b/libraries/tools/abi-validation/src/functionalTest/kotlin/kotlinx/validation/api/TestDsl.kt @@ -12,7 +12,11 @@ import org.intellij.lang.annotations.Language public val API_DIR: String = ApiValidationExtension().apiDumpDirectory -internal fun BaseKotlinGradleTest.test(fn: BaseKotlinScope.() -> Unit): GradleRunner { +internal fun BaseKotlinGradleTest.test( + gradleVersion: String = "7.4.2", + injectPluginClasspath: Boolean = true, + fn: BaseKotlinScope.() -> Unit +): GradleRunner { val baseKotlinScope = BaseKotlinScope() fn(baseKotlinScope) @@ -29,12 +33,17 @@ internal fun BaseKotlinGradleTest.test(fn: BaseKotlinScope.() -> Unit): GradleRu } } - return GradleRunner.create() // + val runner = GradleRunner.create() .withProjectDir(rootProjectDir) .withPluginClasspath() .withArguments(baseKotlinScope.runner.arguments) - .withGradleVersion("7.4.2") - .addPluginTestRuntimeClasspath() + .withGradleVersion(gradleVersion) + if (injectPluginClasspath) { + // The hack dating back to https://docs.gradle.org/6.0/userguide/test_kit.html#sub:test-kit-classpath-injection + // Currently, some tests won't work without it because some classes are missing on the classpath. + runner.addPluginTestRuntimeClasspath() + } + return runner // disabled because of: https://github.com/gradle/gradle/issues/6862 // .withDebug(baseKotlinScope.runner.debug) } diff --git a/libraries/tools/abi-validation/src/functionalTest/kotlin/kotlinx/validation/test/JavaVersionsCompatibilityTest.kt b/libraries/tools/abi-validation/src/functionalTest/kotlin/kotlinx/validation/test/JavaVersionsCompatibilityTest.kt new file mode 100644 index 0000000000000..10ef82b5ce1a9 --- /dev/null +++ b/libraries/tools/abi-validation/src/functionalTest/kotlin/kotlinx/validation/test/JavaVersionsCompatibilityTest.kt @@ -0,0 +1,96 @@ +/* + * Copyright 2016-2024 JetBrains s.r.o. + * Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file. + */ + +package kotlinx.validation.test + +import kotlinx.validation.api.* +import kotlinx.validation.api.buildGradleKts +import kotlinx.validation.api.resolve +import kotlinx.validation.api.test +import org.junit.Test + +class JavaVersionsCompatibilityTest : BaseKotlinGradleTest() { + private fun checkCompatibility(useMaxVersion: Boolean) { + val runner = test(gradleVersion = "8.5", injectPluginClasspath = false) { + buildGradleKts { + resolve("/examples/gradle/base/jdkCompatibility.gradle.kts") + } + settingsGradleKts { + resolve("/examples/gradle/settings/jdk-provisioning.gradle.kts") + } + kotlin("AnotherBuildConfig.kt") { + resolve("/examples/classes/AnotherBuildConfig.kt") + } + apiFile(projectName = rootProjectDir.name) { + resolve("/examples/classes/AnotherBuildConfig.dump") + } + + runner { + arguments.add("-PuseMaxVersion=$useMaxVersion") + arguments.add(":apiCheck") + } + } + + runner.build().apply { + assertTaskSuccess(":apiCheck") + } + } + + private fun checkCompatibility(jdkVersion: String) { + val runner = test(gradleVersion = "8.5", injectPluginClasspath = false) { + buildGradleKts { + resolve("/examples/gradle/base/jdkCompatibilityWithExactVersion.gradle.kts") + } + settingsGradleKts { + resolve("/examples/gradle/settings/jdk-provisioning.gradle.kts") + } + kotlin("AnotherBuildConfig.kt") { + resolve("/examples/classes/AnotherBuildConfig.kt") + } + apiFile(projectName = rootProjectDir.name) { + resolve("/examples/classes/AnotherBuildConfig.dump") + } + + runner { + arguments.add("-PjdkVersion=$jdkVersion") + arguments.add(":apiCheck") + } + } + + runner.build().apply { + assertTaskSuccess(":apiCheck") + } + } + + @Test + fun testMaxSupportedVersion() { + checkCompatibility(true) + } + + @Test + fun testMinSupportedVersion() { + checkCompatibility(false) + } + + @Test + fun testLts8() { + checkCompatibility("1.8") + } + + @Test + fun testLts11() { + checkCompatibility("11") + } + + @Test + fun testLts17() { + checkCompatibility("17") + } + + @Test + fun testLts21() { + checkCompatibility("21") + } +} diff --git a/libraries/tools/abi-validation/src/functionalTest/resources/examples/gradle/base/jdkCompatibility.gradle.kts b/libraries/tools/abi-validation/src/functionalTest/resources/examples/gradle/base/jdkCompatibility.gradle.kts new file mode 100644 index 0000000000000..72e4d95c5768b --- /dev/null +++ b/libraries/tools/abi-validation/src/functionalTest/resources/examples/gradle/base/jdkCompatibility.gradle.kts @@ -0,0 +1,33 @@ +/* + * Copyright 2016-2024 JetBrains s.r.o. + * Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file. + */ + +import org.jetbrains.kotlin.config.JvmTarget + +plugins { + kotlin("jvm") version "1.9.22" + id("org.jetbrains.kotlinx.binary-compatibility-validator") +} + +repositories { + mavenCentral() +} + +val minTarget = JvmTarget.supportedValues().minBy { it.majorVersion } +val maxTarget = JvmTarget.supportedValues().maxBy { it.majorVersion } + +val useMax = (project.properties["useMaxVersion"]?.toString() ?: "false").toBoolean() +val target = (if (useMax) maxTarget else minTarget).toString() + +val toolchainVersion = target.split('.').last().toInt() + +kotlin { + jvmToolchain(toolchainVersion) +} + +tasks.compileKotlin { + compilerOptions { + jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.fromTarget(target)) + } +} diff --git a/libraries/tools/abi-validation/src/functionalTest/resources/examples/gradle/base/jdkCompatibilityWithExactVersion.gradle.kts b/libraries/tools/abi-validation/src/functionalTest/resources/examples/gradle/base/jdkCompatibilityWithExactVersion.gradle.kts new file mode 100644 index 0000000000000..c414415eb3287 --- /dev/null +++ b/libraries/tools/abi-validation/src/functionalTest/resources/examples/gradle/base/jdkCompatibilityWithExactVersion.gradle.kts @@ -0,0 +1,28 @@ +/* + * Copyright 2016-2024 JetBrains s.r.o. + * Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file. + */ + +import org.jetbrains.kotlin.config.JvmTarget + +plugins { + kotlin("jvm") version "1.9.22" + id("org.jetbrains.kotlinx.binary-compatibility-validator") +} + +repositories { + mavenCentral() +} + +val target = project.properties["jdkVersion"]!!.toString() +val toolchainVersion = target.split('.').last().toInt() + +kotlin { + jvmToolchain(toolchainVersion) +} + +tasks.compileKotlin { + compilerOptions { + jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.fromTarget(target)) + } +} diff --git a/libraries/tools/abi-validation/src/functionalTest/resources/examples/gradle/settings/jdk-provisioning.gradle.kts b/libraries/tools/abi-validation/src/functionalTest/resources/examples/gradle/settings/jdk-provisioning.gradle.kts new file mode 100644 index 0000000000000..3d48cfba7e07e --- /dev/null +++ b/libraries/tools/abi-validation/src/functionalTest/resources/examples/gradle/settings/jdk-provisioning.gradle.kts @@ -0,0 +1,8 @@ +/* + * Copyright 2016-2024 JetBrains s.r.o. + * Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file. + */ + +plugins { + id("org.gradle.toolchains.foojay-resolver-convention") version ("0.7.0") +}