[Gradle, JS] Deprecation of BOTH and LEGACY consts

^KT-55593 fixed
This commit is contained in:
Ilya Goncharov
2023-01-03 12:47:11 +00:00
committed by Space Team
parent 3744fbb31b
commit a0211fc5fe
9 changed files with 62 additions and 35 deletions
@@ -8,8 +8,12 @@ package org.jetbrains.kotlin.gradle.plugin
import java.util.* import java.util.*
enum class KotlinJsCompilerType { enum class KotlinJsCompilerType {
@Deprecated("Legacy compiler is deprecated. Migrate your project to the new IR-based compiler")
LEGACY, LEGACY,
IR, IR,
@Deprecated("Legacy compiler is deprecated. Migrate your project to the new IR-based compiler")
BOTH; BOTH;
companion object { companion object {
@@ -3,6 +3,8 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@file:Suppress("DEPRECATION")
package org.jetbrains.kotlin.gradle.plugin package org.jetbrains.kotlin.gradle.plugin
interface KotlinJsCompilerTypeHolder { interface KotlinJsCompilerTypeHolder {
@@ -12,12 +14,14 @@ interface KotlinJsCompilerTypeHolder {
get() = compilerTypeFromProperties ?: KotlinJsCompilerType.IR get() = compilerTypeFromProperties ?: KotlinJsCompilerType.IR
// Necessary to get rid of KotlinJsCompilerType import in build script // Necessary to get rid of KotlinJsCompilerType import in build script
@Deprecated("Legacy compiler is deprecated. Migrate your project to the new IR-based compiler")
val LEGACY: KotlinJsCompilerType val LEGACY: KotlinJsCompilerType
get() = KotlinJsCompilerType.LEGACY get() = KotlinJsCompilerType.LEGACY
val IR: KotlinJsCompilerType val IR: KotlinJsCompilerType
get() = KotlinJsCompilerType.IR get() = KotlinJsCompilerType.IR
@Deprecated("Legacy compiler is deprecated. Migrate your project to the new IR-based compiler")
val BOTH: KotlinJsCompilerType val BOTH: KotlinJsCompilerType
get() = KotlinJsCompilerType.BOTH get() = KotlinJsCompilerType.BOTH
} }
@@ -224,6 +224,7 @@ class HierarchicalMppIT : KGPBaseTest() {
@GradleTest @GradleTest
@DisplayName("Works with published JS library") @DisplayName("Works with published JS library")
fun testHmppWithPublishedJsBothDependency(gradleVersion: GradleVersion, @TempDir tempDir: Path) { fun testHmppWithPublishedJsBothDependency(gradleVersion: GradleVersion, @TempDir tempDir: Path) {
@Suppress("DEPRECATION")
publishThirdPartyLib( publishThirdPartyLib(
projectName = "hierarchical-mpp-with-js-published-modules/third-party-lib", projectName = "hierarchical-mpp-with-js-published-modules/third-party-lib",
withGranularMetadata = true, withGranularMetadata = true,
@@ -14,6 +14,7 @@ import org.junit.jupiter.api.DisplayName
import javax.inject.Inject import javax.inject.Inject
abstract class AbstractJsConfigurationCacheIT(protected val irBackend: Boolean) : KGPBaseTest() { abstract class AbstractJsConfigurationCacheIT(protected val irBackend: Boolean) : KGPBaseTest() {
@Suppress("DEPRECATION")
private val defaultJsOptions = BuildOptions.JsOptions( private val defaultJsOptions = BuildOptions.JsOptions(
useIrBackend = irBackend, useIrBackend = irBackend,
jsCompilerType = if (irBackend) KotlinJsCompilerType.IR else KotlinJsCompilerType.LEGACY, jsCompilerType = if (irBackend) KotlinJsCompilerType.IR else KotlinJsCompilerType.LEGACY,
@@ -544,6 +544,7 @@ class Kotlin2JsGradlePluginIT : AbstractKotlin2JsGradlePluginIT(false) {
@JsGradlePluginTests @JsGradlePluginTests
abstract class AbstractKotlin2JsGradlePluginIT(protected val irBackend: Boolean) : KGPBaseTest() { abstract class AbstractKotlin2JsGradlePluginIT(protected val irBackend: Boolean) : KGPBaseTest() {
@Suppress("DEPRECATION")
private val defaultJsOptions = BuildOptions.JsOptions( private val defaultJsOptions = BuildOptions.JsOptions(
useIrBackend = irBackend, useIrBackend = irBackend,
jsCompilerType = if (irBackend) KotlinJsCompilerType.IR else KotlinJsCompilerType.LEGACY, jsCompilerType = if (irBackend) KotlinJsCompilerType.IR else KotlinJsCompilerType.LEGACY,
@@ -14,7 +14,6 @@ import org.jetbrains.kotlin.gradle.native.MPPNativeTargets
import org.jetbrains.kotlin.gradle.native.transformNativeTestProject import org.jetbrains.kotlin.gradle.native.transformNativeTestProject
import org.jetbrains.kotlin.gradle.native.transformNativeTestProjectWithPluginDsl import org.jetbrains.kotlin.gradle.native.transformNativeTestProjectWithPluginDsl
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType.*
import org.jetbrains.kotlin.gradle.plugin.ProjectLocalConfigurations import org.jetbrains.kotlin.gradle.plugin.ProjectLocalConfigurations
import org.jetbrains.kotlin.gradle.plugin.lowerName import org.jetbrains.kotlin.gradle.plugin.lowerName
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmWithJavaTargetPreset import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmWithJavaTargetPreset
@@ -257,46 +256,50 @@ class NewMultiplatformIT : BaseGradleIT() {
} }
} }
@Suppress("DEPRECATION")
@Test @Test
fun testLibAndAppJsLegacy() = doTestLibAndAppJsBothCompilers( fun testLibAndAppJsLegacy() = doTestLibAndAppJsBothCompilers(
"sample-lib", "sample-lib",
"sample-app", "sample-app",
LEGACY KotlinJsCompilerType.LEGACY
) )
@Test @Test
fun testLibAndAppJsIr() = doTestLibAndAppJsBothCompilers( fun testLibAndAppJsIr() = doTestLibAndAppJsBothCompilers(
"sample-lib", "sample-lib",
"sample-app", "sample-app",
IR KotlinJsCompilerType.IR
) )
@Suppress("DEPRECATION")
@Test @Test
fun testLibAndAppJsBoth() = doTestLibAndAppJsBothCompilers( fun testLibAndAppJsBoth() = doTestLibAndAppJsBothCompilers(
"sample-lib", "sample-lib",
"sample-app", "sample-app",
BOTH KotlinJsCompilerType.BOTH
) )
@Suppress("DEPRECATION")
@Test @Test
fun testLibAndAppWithGradleKotlinDslJsLegacy() = doTestLibAndAppJsBothCompilers( fun testLibAndAppWithGradleKotlinDslJsLegacy() = doTestLibAndAppJsBothCompilers(
"sample-lib-gradle-kotlin-dsl", "sample-lib-gradle-kotlin-dsl",
"sample-app-gradle-kotlin-dsl", "sample-app-gradle-kotlin-dsl",
LEGACY KotlinJsCompilerType.LEGACY
) )
@Test @Test
fun testLibAndAppWithGradleKotlinDslJsIr() = doTestLibAndAppJsBothCompilers( fun testLibAndAppWithGradleKotlinDslJsIr() = doTestLibAndAppJsBothCompilers(
"sample-lib-gradle-kotlin-dsl", "sample-lib-gradle-kotlin-dsl",
"sample-app-gradle-kotlin-dsl", "sample-app-gradle-kotlin-dsl",
IR KotlinJsCompilerType.IR
) )
@Suppress("DEPRECATION")
@Test @Test
fun testLibAndAppWithGradleKotlinDslJsBoth() = doTestLibAndAppJsBothCompilers( fun testLibAndAppWithGradleKotlinDslJsBoth() = doTestLibAndAppJsBothCompilers(
"sample-lib-gradle-kotlin-dsl", "sample-lib-gradle-kotlin-dsl",
"sample-app-gradle-kotlin-dsl", "sample-app-gradle-kotlin-dsl",
BOTH KotlinJsCompilerType.BOTH
) )
private fun doTestLibAndAppJsBothCompilers( private fun doTestLibAndAppJsBothCompilers(
@@ -307,14 +310,15 @@ class NewMultiplatformIT : BaseGradleIT() {
val libProject = transformProjectWithPluginsDsl(libProjectName, directoryPrefix = "both-js-lib-and-app") val libProject = transformProjectWithPluginsDsl(libProjectName, directoryPrefix = "both-js-lib-and-app")
val appProject = transformProjectWithPluginsDsl(appProjectName, directoryPrefix = "both-js-lib-and-app") val appProject = transformProjectWithPluginsDsl(appProjectName, directoryPrefix = "both-js-lib-and-app")
@Suppress("DEPRECATION")
val compileTasksNames = val compileTasksNames =
listOf( listOf(
*(if (jsCompilerType != BOTH) { *(if (jsCompilerType != KotlinJsCompilerType.BOTH) {
arrayOf("NodeJs") arrayOf("NodeJs")
} else { } else {
arrayOf( arrayOf(
"NodeJs${LEGACY.lowerName.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }}", "NodeJs${KotlinJsCompilerType.LEGACY.lowerName.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }}",
"NodeJs${IR.lowerName.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }}", "NodeJs${KotlinJsCompilerType.IR.lowerName.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }}",
) )
}), }),
).map { ":compileKotlin$it" } ).map { ":compileKotlin$it" }
@@ -329,7 +333,8 @@ class NewMultiplatformIT : BaseGradleIT() {
assertTasksExecuted(*compileTasksNames.toTypedArray(), ":allMetadataJar") assertTasksExecuted(*compileTasksNames.toTypedArray(), ":allMetadataJar")
val groupDir = projectDir.resolve("repo/com/example") val groupDir = projectDir.resolve("repo/com/example")
val jsExtension = if (jsCompilerType == LEGACY) "jar" else "klib" @Suppress("DEPRECATION")
val jsExtension = if (jsCompilerType == KotlinJsCompilerType.LEGACY) "jar" else "klib"
val jsJarName = "sample-lib-nodejs/1.0/sample-lib-nodejs-1.0.$jsExtension" val jsJarName = "sample-lib-nodejs/1.0/sample-lib-nodejs-1.0.$jsExtension"
val metadataJarName = "sample-lib/1.0/sample-lib-1.0.jar" val metadataJarName = "sample-lib/1.0/sample-lib-1.0.jar"
@@ -352,8 +357,9 @@ class NewMultiplatformIT : BaseGradleIT() {
) )
} }
@Suppress("DEPRECATION")
when (jsCompilerType) { when (jsCompilerType) {
LEGACY -> { KotlinJsCompilerType.LEGACY -> {
val jsJar = ZipFile(groupDir.resolve(jsJarName)) val jsJar = ZipFile(groupDir.resolve(jsJarName))
val compiledJs = jsJar.getInputStream(jsJar.getEntry("sample-lib.js")).reader().readText() val compiledJs = jsJar.getInputStream(jsJar.getEntry("sample-lib.js")).reader().readText()
Assert.assertTrue("function id(" in compiledJs) Assert.assertTrue("function id(" in compiledJs)
@@ -361,10 +367,10 @@ class NewMultiplatformIT : BaseGradleIT() {
Assert.assertTrue("function expectedFun(" in compiledJs) Assert.assertTrue("function expectedFun(" in compiledJs)
Assert.assertTrue("function main(" in compiledJs) Assert.assertTrue("function main(" in compiledJs)
} }
IR -> { KotlinJsCompilerType.IR -> {
groupDir.resolve(jsJarName).exists() groupDir.resolve(jsJarName).exists()
} }
BOTH -> {} KotlinJsCompilerType.BOTH -> {}
} }
} }
} }
@@ -386,7 +392,8 @@ class NewMultiplatformIT : BaseGradleIT() {
} }
assertTasksExecuted(*compileTaskNames) assertTasksExecuted(*compileTaskNames)
if (jsCompilerType == LEGACY) { @Suppress("DEPRECATION")
if (jsCompilerType == KotlinJsCompilerType.LEGACY) {
projectDir.resolve(targetClassesDir("nodeJs")).resolve("sample-app.js").readText().run { projectDir.resolve(targetClassesDir("nodeJs")).resolve("sample-app.js").readText().run {
Assert.assertTrue(contains("console.info")) Assert.assertTrue(contains("console.info"))
Assert.assertTrue(contains("function nodeJsMain(")) Assert.assertTrue(contains("function nodeJsMain("))
@@ -401,10 +408,12 @@ class NewMultiplatformIT : BaseGradleIT() {
checkAppBuild(jsCompilerType) checkAppBuild(jsCompilerType)
} }
if (jsCompilerType == BOTH) { @Suppress("DEPRECATION")
if (jsCompilerType == KotlinJsCompilerType.BOTH) {
@Suppress("DEPRECATION")
listOf( listOf(
LEGACY, KotlinJsCompilerType.LEGACY,
IR KotlinJsCompilerType.IR
).forEach { ).forEach {
build( build(
"assemble", "assemble",
@@ -970,9 +979,10 @@ class NewMultiplatformIT : BaseGradleIT() {
val appProject = Project("sample-app", gradleVersion, "new-mpp-lib-and-app") val appProject = Project("sample-app", gradleVersion, "new-mpp-lib-and-app")
val buildOptions = hmppFlags.buildOptions val buildOptions = hmppFlags.buildOptions
@Suppress("DEPRECATION")
libProject.build( libProject.build(
"publish", "publish",
options = buildOptions.copy(jsCompilerType = BOTH) options = buildOptions.copy(jsCompilerType = KotlinJsCompilerType.BOTH)
) { ) {
assertSuccessful() assertSuccessful()
} }
@@ -1013,7 +1023,7 @@ class NewMultiplatformIT : BaseGradleIT() {
build( build(
"printMetadataFiles", "printMetadataFiles",
options = buildOptions.copy(jsCompilerType = IR) options = buildOptions.copy(jsCompilerType = KotlinJsCompilerType.IR)
) { ) {
assertSuccessful() assertSuccessful()
@@ -1464,6 +1474,7 @@ class NewMultiplatformIT : BaseGradleIT() {
@Test @Test
fun testJsDceInMpp() = with(Project("new-mpp-js-dce", gradleVersion)) { fun testJsDceInMpp() = with(Project("new-mpp-js-dce", gradleVersion)) {
@Suppress("DEPRECATION")
build( build(
"runRhino", "runRhino",
options = defaultBuildOptions().copy(warningMode = WarningMode.Summary, jsCompilerType = KotlinJsCompilerType.LEGACY) options = defaultBuildOptions().copy(warningMode = WarningMode.Summary, jsCompilerType = KotlinJsCompilerType.LEGACY)
@@ -44,6 +44,7 @@ class VariantAwareDependenciesMppIT : BaseGradleIT() {
assertContains(">> :${innerProject.projectName}:runtimeClasspath --> sample-lib-nodejs-1.0.klib") assertContains(">> :${innerProject.projectName}:runtimeClasspath --> sample-lib-nodejs-1.0.klib")
} }
@Suppress("DEPRECATION")
gradleProperties().appendText(jsCompilerType(KotlinJsCompilerType.LEGACY)) gradleProperties().appendText(jsCompilerType(KotlinJsCompilerType.LEGACY))
testResolveAllConfigurations( testResolveAllConfigurations(
@@ -7,7 +7,6 @@
package org.jetbrains.kotlin.gradle package org.jetbrains.kotlin.gradle
import org.gradle.api.Project
import org.gradle.api.attributes.AttributeContainer import org.gradle.api.attributes.AttributeContainer
import org.gradle.api.attributes.Category import org.gradle.api.attributes.Category
import org.gradle.api.attributes.Usage import org.gradle.api.attributes.Usage
@@ -21,8 +20,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.util.targets
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsCompilerAttribute import org.jetbrains.kotlin.gradle.targets.js.KotlinJsCompilerAttribute
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
import org.jetbrains.kotlin.util.capitalizeDecapitalize.capitalizeAsciiOnly import java.util.*
import java.util.Locale
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertEquals import kotlin.test.assertEquals
import kotlin.test.assertNotNull import kotlin.test.assertNotNull
@@ -134,6 +132,7 @@ class ConfigurationsTest : MultiplatformExtensionTest() {
fun `test js IR compilation dependencies`() { fun `test js IR compilation dependencies`() {
val project = buildProjectWithMPP { val project = buildProjectWithMPP {
kotlin { kotlin {
@Suppress("DEPRECATION")
js(BOTH) js(BOTH)
targets.withType<KotlinJsTarget> { targets.withType<KotlinJsTarget> {
irTarget!!.compilations.getByName("main").dependencies { irTarget!!.compilations.getByName("main").dependencies {
@@ -167,6 +166,7 @@ class ConfigurationsTest : MultiplatformExtensionTest() {
kotlin { kotlin {
jvm() jvm()
@Suppress("DEPRECATION")
js(BOTH) js(BOTH)
linuxX64("linux") linuxX64("linux")
android() android()
@@ -193,6 +193,7 @@ class ConfigurationsTest : MultiplatformExtensionTest() {
val project = buildProjectWithMPP { val project = buildProjectWithMPP {
kotlin { kotlin {
jvm() jvm()
@Suppress("DEPRECATION")
js(BOTH) js(BOTH)
linuxX64("linux") linuxX64("linux")
} }
@@ -225,22 +226,24 @@ class ConfigurationsTest : MultiplatformExtensionTest() {
class TestDisambiguationAttributePropagation { class TestDisambiguationAttributePropagation {
private val disambiguationAttribute = org.gradle.api.attributes.Attribute.of("disambiguationAttribute", String::class.java) private val disambiguationAttribute = org.gradle.api.attributes.Attribute.of("disambiguationAttribute", String::class.java)
private val mppProject get() = buildProjectWithMPP { private val mppProject
kotlin { get() = buildProjectWithMPP {
jvm("plainJvm") { kotlin {
attributes { attribute(disambiguationAttribute, "plainJvm") } jvm("plainJvm") {
} attributes { attribute(disambiguationAttribute, "plainJvm") }
}
jvm("jvmWithJava") { jvm("jvmWithJava") {
withJava() withJava()
attributes { attribute(disambiguationAttribute, "jvmWithJava") } attributes { attribute(disambiguationAttribute, "jvmWithJava") }
}
} }
} }
}
private val javaProject get() = buildProject { private val javaProject
project.plugins.apply("java-library") get() = buildProject {
} project.plugins.apply("java-library")
}
//NB: There is no "api" configuration registered by Java Plugin //NB: There is no "api" configuration registered by Java Plugin
private val javaConfigurations = listOf( private val javaConfigurations = listOf(
@@ -34,6 +34,7 @@ class KT55347JsProjectImport {
fun `GranularMetadataTransformation should be accessible in pure js projects -- IR`() = fun `GranularMetadataTransformation should be accessible in pure js projects -- IR`() =
`GranularMetadataTransformation should be accessible in pure js projects`(IR) `GranularMetadataTransformation should be accessible in pure js projects`(IR)
@Suppress("DEPRECATION")
@Test @Test
fun `GranularMetadataTransformation should be accessible in pure js projects -- BOTH`() = fun `GranularMetadataTransformation should be accessible in pure js projects -- BOTH`() =
`GranularMetadataTransformation should be accessible in pure js projects`(BOTH) `GranularMetadataTransformation should be accessible in pure js projects`(BOTH)