[Gradle, JS] UpperCased KotlinJsCompilerType

This commit is contained in:
Ilya Goncharov
2020-02-20 17:26:52 +03:00
parent 9acd98071e
commit 068d547375
12 changed files with 56 additions and 62 deletions
@@ -5,21 +5,10 @@
package org.jetbrains.kotlin.gradle.plugin
import org.gradle.api.Named
import java.io.Serializable
// For Gradle attributes
@Suppress("EnumEntryName")
enum class KotlinJsCompilerType : Named, Serializable {
legacy,
ir,
both;
override fun getName(): String =
name.toLowerCase()
override fun toString(): String =
getName()
enum class KotlinJsCompilerType {
LEGACY,
IR,
BOTH;
companion object {
const val jsCompilerProperty = "kotlin.js.compiler"
@@ -29,11 +18,14 @@ enum class KotlinJsCompilerType : Named, Serializable {
}
}
val KotlinJsCompilerType.lowerName
get() = name.toLowerCase()
fun String.removeJsCompilerSuffix(compilerType: KotlinJsCompilerType): String {
val truncatedString = removeSuffix(compilerType.name)
val truncatedString = removeSuffix(compilerType.lowerName)
if (this != truncatedString) {
return truncatedString
}
return removeSuffix(compilerType.name.capitalize())
return removeSuffix(compilerType.lowerName.capitalize())
}
@@ -39,7 +39,7 @@ class Kotlin2JsIrGradlePluginIT : AbstractKotlin2JsGradlePluginIT(true) {
build(
"build",
options = defaultBuildOptions().copy(jsCompilerType = KotlinJsCompilerType.ir)
options = defaultBuildOptions().copy(jsCompilerType = KotlinJsCompilerType.IR)
) {
assertSuccessful()
@@ -63,7 +63,7 @@ class Kotlin2JsIrGradlePluginIT : AbstractKotlin2JsGradlePluginIT(true) {
build(
"build",
options = defaultBuildOptions().copy(jsCompilerType = KotlinJsCompilerType.ir)
options = defaultBuildOptions().copy(jsCompilerType = KotlinJsCompilerType.IR)
) {
assertSuccessful()
@@ -552,7 +552,7 @@ abstract class AbstractKotlin2JsGradlePluginIT(private val irBackend: Boolean) :
gradleSettingsScript().modify(::transformBuildScriptWithPluginsDsl)
if (irBackend) {
gradleProperties().appendText(jsCompilerType(KotlinJsCompilerType.ir))
gradleProperties().appendText(jsCompilerType(KotlinJsCompilerType.IR))
}
build("build") {
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.gradle.internals.*
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.lowerName
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmWithJavaTargetPreset
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMultiplatformPlugin
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeOutputKind
@@ -248,42 +249,42 @@ class NewMultiplatformIT : BaseGradleIT() {
fun testLibAndAppJsLegacy() = doTestLibAndAppJsBothCompilers(
"sample-lib",
"sample-app",
legacy
LEGACY
)
@Test
fun testLibAndAppJsIr() = doTestLibAndAppJsBothCompilers(
"sample-lib",
"sample-app",
ir
IR
)
@Test
fun testLibAndAppJsBoth() = doTestLibAndAppJsBothCompilers(
"sample-lib",
"sample-app",
both
BOTH
)
@Test
fun testLibAndAppWithGradleKotlinDslJsLegacy() = doTestLibAndAppJsBothCompilers(
"sample-lib-gradle-kotlin-dsl",
"sample-app-gradle-kotlin-dsl",
legacy
LEGACY
)
@Test
fun testLibAndAppWithGradleKotlinDslJsIr() = doTestLibAndAppJsBothCompilers(
"sample-lib-gradle-kotlin-dsl",
"sample-app-gradle-kotlin-dsl",
ir
IR
)
@Test
fun testLibAndAppWithGradleKotlinDslJsBoth() = doTestLibAndAppJsBothCompilers(
"sample-lib-gradle-kotlin-dsl",
"sample-app-gradle-kotlin-dsl",
both
BOTH
)
private fun doTestLibAndAppJsBothCompilers(
@@ -296,12 +297,12 @@ class NewMultiplatformIT : BaseGradleIT() {
val compileTasksNames =
listOf(
*(if (jsCompilerType != both) {
*(if (jsCompilerType != BOTH) {
arrayOf("NodeJs")
} else {
arrayOf(
"NodeJs${legacy.name.capitalize()}",
"NodeJs${ir.name.capitalize()}",
"NodeJs${LEGACY.lowerName.capitalize()}",
"NodeJs${IR.lowerName.capitalize()}",
)
}),
"Metadata"
@@ -316,7 +317,7 @@ class NewMultiplatformIT : BaseGradleIT() {
assertTasksExecuted(*compileTasksNames.toTypedArray(), ":metadataJar")
val groupDir = projectDir.resolve("repo/com/example")
val jsExtension = if (jsCompilerType == legacy) "jar" else "klib"
val jsExtension = if (jsCompilerType == LEGACY) "jar" else "klib"
val jsJarName = "sample-lib-nodejs/1.0/sample-lib-nodejs-1.0.$jsExtension"
val metadataJarName = "sample-lib-metadata/1.0/sample-lib-metadata-1.0.jar"
@@ -340,7 +341,7 @@ class NewMultiplatformIT : BaseGradleIT() {
}
when (jsCompilerType) {
legacy -> {
LEGACY -> {
val jsJar = ZipFile(groupDir.resolve(jsJarName))
val compiledJs = jsJar.getInputStream(jsJar.getEntry("sample-lib.js")).reader().readText()
Assert.assertTrue("function id(" in compiledJs)
@@ -348,7 +349,7 @@ class NewMultiplatformIT : BaseGradleIT() {
Assert.assertTrue("function expectedFun(" in compiledJs)
Assert.assertTrue("function main(" in compiledJs)
}
ir -> {
IR -> {
groupDir.resolve(jsJarName).exists()
}
}
@@ -382,7 +383,7 @@ class NewMultiplatformIT : BaseGradleIT() {
Assert.assertTrue(resolve("com/example/app/AKt.kotlin_metadata").exists())
}
if (jsCompilerType == legacy) {
if (jsCompilerType == LEGACY) {
projectDir.resolve(targetClassesDir("nodeJs")).resolve("sample-app.js").readText().run {
Assert.assertTrue(contains("console.info"))
Assert.assertTrue(contains("function nodeJsMain("))
@@ -397,10 +398,10 @@ class NewMultiplatformIT : BaseGradleIT() {
checkAppBuild(jsCompilerType)
}
if (jsCompilerType == both) {
if (jsCompilerType == BOTH) {
listOf(
legacy,
ir
LEGACY,
IR
).forEach {
build(
"assemble",
@@ -42,7 +42,7 @@ class VariantAwareDependenciesIT : BaseGradleIT() {
assertContains(">> :${innerProject.projectName}:runtime --> sample-lib-nodejs-1.0.jar")
}
gradleProperties().appendText(jsCompilerType(KotlinJsCompilerType.ir))
gradleProperties().appendText(jsCompilerType(KotlinJsCompilerType.IR))
testResolveAllConfigurations(
subproject = innerProject.projectName,
@@ -13,7 +13,7 @@ class WorkersIT : BaseGradleIT() {
fun testParallelTasks() {
parallelTasksImpl(
isParallel = true,
jsCompilerType = KotlinJsCompilerType.legacy
jsCompilerType = KotlinJsCompilerType.LEGACY
)
}
@@ -21,7 +21,7 @@ class WorkersIT : BaseGradleIT() {
fun testParallelTasksJsIr() {
parallelTasksImpl(
isParallel = true,
jsCompilerType = KotlinJsCompilerType.ir
jsCompilerType = KotlinJsCompilerType.IR
)
}
@@ -29,7 +29,7 @@ class WorkersIT : BaseGradleIT() {
fun testNoParallelTasks() {
parallelTasksImpl(
isParallel = false,
jsCompilerType = KotlinJsCompilerType.legacy
jsCompilerType = KotlinJsCompilerType.LEGACY
)
}
@@ -37,7 +37,7 @@ class WorkersIT : BaseGradleIT() {
fun testNoParallelTasksJsIr() {
parallelTasksImpl(
isParallel = false,
jsCompilerType = KotlinJsCompilerType.ir
jsCompilerType = KotlinJsCompilerType.IR
)
}
@@ -64,7 +64,7 @@ class WorkersIT : BaseGradleIT() {
kotlinClassesDir(sourceSet = "metadata/main") + "common/A.kotlin_metadata",
kotlinClassesDir(sourceSet = "jvm/main") + "common/A.class",
kotlinClassesDir(sourceSet = "js/main") +
if (jsCompilerType == KotlinJsCompilerType.ir) "default/manifest" else "new-mpp-parallel.js"
if (jsCompilerType == KotlinJsCompilerType.IR) "default/manifest" else "new-mpp-parallel.js"
)
expectedKotlinOutputFiles.forEach { assertFileExists(it) }
assertSubstringCount("Loaded GradleKotlinCompilerWork", 1)
@@ -120,13 +120,13 @@ open class KotlinJsProjectExtension :
) {
if (_target == null) {
val target: KotlinJsTargetDsl = when (compiler) {
legacy -> legacyPreset
LEGACY -> legacyPreset
.also { it.irPreset = null }
.createTarget("js")
ir -> irPreset
IR -> irPreset
.also { it.mixedMode = false }
.createTarget("js")
both -> legacyPreset
BOTH -> legacyPreset
.also {
irPreset.mixedMode = true
it.irPreset = irPreset
@@ -134,7 +134,7 @@ open class KotlinJsProjectExtension :
.createTarget(
lowerCamelCaseName(
"js",
legacy.name
LEGACY.lowerName
)
)
}
@@ -5,6 +5,7 @@ import org.gradle.util.ConfigureUtil
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerTypeHolder
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetPreset
import org.jetbrains.kotlin.gradle.plugin.lowerName
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsTargetDsl
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
@@ -17,11 +18,11 @@ interface KotlinTargetContainerWithJsPresetFunctions :
configure: KotlinJsTargetDsl.() -> Unit = { }
): KotlinJsTargetDsl =
configureOrCreate(
lowerCamelCaseName(name, if (compiler == KotlinJsCompilerType.both) KotlinJsCompilerType.legacy.name else null),
lowerCamelCaseName(name, if (compiler == KotlinJsCompilerType.BOTH) KotlinJsCompilerType.LEGACY.lowerName else null),
presets.getByName(
lowerCamelCaseName(
"js",
if (compiler == KotlinJsCompilerType.legacy) null else compiler.name
if (compiler == KotlinJsCompilerType.LEGACY) null else compiler.lowerName
)
) as KotlinTargetPreset<KotlinJsTargetDsl>,
configure
@@ -170,10 +170,10 @@ internal class PropertiesProvider private constructor(private val project: Proje
get() = booleanProperty("kotlin.js.experimental.discoverTypes")
/**
* Use Kotlin/JS backend mode
* Use Kotlin/JS backend compiler type
*/
val jsCompiler: KotlinJsCompilerType
get() = property(jsCompilerProperty)?.let { KotlinJsCompilerType.byArgument(it) } ?: KotlinJsCompilerType.legacy
get() = property(jsCompilerProperty)?.let { KotlinJsCompilerType.byArgument(it) } ?: KotlinJsCompilerType.LEGACY
private fun propertyWithDeprecatedVariant(propName: String, deprecatedPropName: String): String? {
val deprecatedProperty = property(deprecatedPropName)
@@ -39,7 +39,7 @@ constructor(
internal set
val disambiguationClassifierInPlatform: String?
get() = disambiguationClassifier?.removeJsCompilerSuffix(KotlinJsCompilerType.legacy)
get() = disambiguationClassifier?.removeJsCompilerSuffix(KotlinJsCompilerType.LEGACY)
override val kotlinComponents: Set<KotlinTargetComponent> by lazy {
if (irTarget == null)
@@ -71,7 +71,7 @@ constructor(
): KotlinVariant {
return super.createKotlinVariant(componentName, compilation, usageContexts).apply {
irTarget?.let {
artifactTargetName = targetName.removeJsCompilerSuffix(KotlinJsCompilerType.legacy)
artifactTargetName = targetName.removeJsCompilerSuffix(KotlinJsCompilerType.LEGACY)
}
}
}
@@ -9,10 +9,7 @@
package org.jetbrains.kotlin.gradle.plugin.mpp
import org.gradle.api.Project
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
import org.jetbrains.kotlin.gradle.plugin.removeJsCompilerSuffix
import org.jetbrains.kotlin.gradle.plugin.whenEvaluated
import org.jetbrains.kotlin.gradle.plugin.*
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTargetConfigurator
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTargetPreset
@@ -38,7 +35,10 @@ open class KotlinJsTargetPreset(
platformType
).apply {
this.irTarget = irPreset?.createTarget(
lowerCamelCaseName(name.removeJsCompilerSuffix(KotlinJsCompilerType.legacy), KotlinJsCompilerType.ir.name)
lowerCamelCaseName(
name.removeJsCompilerSuffix(KotlinJsCompilerType.LEGACY),
KotlinJsCompilerType.IR.lowerName
)
)
project.whenEvaluated {
@@ -68,7 +68,7 @@ open class KotlinJsTargetPreset(
override fun getName(): String {
return lowerCamelCaseName(
PRESET_NAME,
irPreset?.let { KotlinJsCompilerType.both.name }
irPreset?.let { KotlinJsCompilerType.BOTH.lowerName }
)
}
@@ -92,7 +92,7 @@ class KotlinJsSingleTargetPreset(
override fun provideTargetDisambiguationClassifier(target: KotlinOnlyTarget<KotlinJsCompilation>): String? =
irPreset?.let {
super.provideTargetDisambiguationClassifier(target)
?.removePrefix(target.name.removeJsCompilerSuffix(KotlinJsCompilerType.legacy))
?.removePrefix(target.name.removeJsCompilerSuffix(KotlinJsCompilerType.LEGACY))
?.decapitalize()
}
@@ -37,7 +37,7 @@ constructor(
internal set
val disambiguationClassifierInPlatform: String?
get() = disambiguationClassifier?.removeJsCompilerSuffix(KotlinJsCompilerType.ir)
get() = disambiguationClassifier?.removeJsCompilerSuffix(KotlinJsCompilerType.IR)
var producingType: KotlinJsProducingType? = null
@@ -62,7 +62,7 @@ open class KotlinJsIrTargetPreset(
companion object {
val PRESET_NAME = lowerCamelCaseName(
"js",
KotlinJsCompilerType.ir.name
KotlinJsCompilerType.IR.lowerName
)
}
}
@@ -78,7 +78,7 @@ class KotlinJsIrSingleTargetPreset(
override fun provideTargetDisambiguationClassifier(target: KotlinOnlyTarget<KotlinJsIrCompilation>): String? {
return if (mixedMode!!) {
super.provideTargetDisambiguationClassifier(target)
?.removePrefix(target.name.removeJsCompilerSuffix(KotlinJsCompilerType.ir))
?.removePrefix(target.name.removeJsCompilerSuffix(KotlinJsCompilerType.IR))
?.decapitalize()
} else {
null