[Gradle, JS] Fix capilatiozation for gradle attributes

This commit is contained in:
Ilya Goncharov
2020-02-03 14:32:29 +03:00
parent 54e068dee2
commit b30328a766
9 changed files with 39 additions and 37 deletions
@@ -510,7 +510,7 @@ abstract class AbstractKotlin2JsGradlePluginIT(private val irBackend: Boolean) :
gradleSettingsScript().modify(::transformBuildScriptWithPluginsDsl) gradleSettingsScript().modify(::transformBuildScriptWithPluginsDsl)
if (!irBackend) { if (!irBackend) {
gradleProperties().appendText(jsMode(JsCompilerType.LEGACY)) gradleProperties().appendText(jsMode(JsCompilerType.legacy))
} }
build("build") { build("build") {
@@ -67,42 +67,42 @@ class NewMultiplatformIT : BaseGradleIT() {
fun testLibAndApp() = doTestLibAndApp( fun testLibAndApp() = doTestLibAndApp(
"sample-lib", "sample-lib",
"sample-app", "sample-app",
JsCompilerType.LEGACY JsCompilerType.legacy
) )
@Test @Test
fun testLibAndAppJsIr() = doTestLibAndApp( fun testLibAndAppJsIr() = doTestLibAndApp(
"sample-lib", "sample-lib",
"sample-app", "sample-app",
JsCompilerType.KLIB JsCompilerType.klib
) )
@Test @Test
fun testLibAndAppJsMixed() = doTestLibAndApp( fun testLibAndAppJsMixed() = doTestLibAndApp(
"sample-lib", "sample-lib",
"sample-app", "sample-app",
JsCompilerType.BOTH JsCompilerType.both
) )
@Test @Test
fun testLibAndAppWithGradleKotlinDsl() = doTestLibAndApp( fun testLibAndAppWithGradleKotlinDsl() = doTestLibAndApp(
"sample-lib-gradle-kotlin-dsl", "sample-lib-gradle-kotlin-dsl",
"sample-app-gradle-kotlin-dsl", "sample-app-gradle-kotlin-dsl",
JsCompilerType.LEGACY JsCompilerType.legacy
) )
@Test @Test
fun testLibAndAppWithGradleKotlinDslJsIr() = doTestLibAndApp( fun testLibAndAppWithGradleKotlinDslJsIr() = doTestLibAndApp(
"sample-lib-gradle-kotlin-dsl", "sample-lib-gradle-kotlin-dsl",
"sample-app-gradle-kotlin-dsl", "sample-app-gradle-kotlin-dsl",
JsCompilerType.KLIB JsCompilerType.klib
) )
@Test @Test
fun testLibAndAppWithGradleKotlinDslJsMixed() = doTestLibAndApp( fun testLibAndAppWithGradleKotlinDslJsMixed() = doTestLibAndApp(
"sample-lib-gradle-kotlin-dsl", "sample-lib-gradle-kotlin-dsl",
"sample-app-gradle-kotlin-dsl", "sample-app-gradle-kotlin-dsl",
JsCompilerType.BOTH JsCompilerType.both
) )
private fun doTestLibAndApp( private fun doTestLibAndApp(
@@ -127,7 +127,7 @@ class NewMultiplatformIT : BaseGradleIT() {
val groupDir = projectDir.resolve("repo/com/example") val groupDir = projectDir.resolve("repo/com/example")
val jvmJarName = "sample-lib-jvm6/1.0/sample-lib-jvm6-1.0.jar" val jvmJarName = "sample-lib-jvm6/1.0/sample-lib-jvm6-1.0.jar"
val jsExtension = if (jsCompilerType == JsCompilerType.LEGACY) "jar" else "klib" val jsExtension = if (jsCompilerType == JsCompilerType.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-metadata/1.0/sample-lib-metadata-1.0.jar" val metadataJarName = "sample-lib-metadata/1.0/sample-lib-metadata-1.0.jar"
val wasmKlibName = "sample-lib-wasm32/1.0/sample-lib-wasm32-1.0.klib" val wasmKlibName = "sample-lib-wasm32/1.0/sample-lib-wasm32-1.0.klib"
@@ -157,7 +157,7 @@ class NewMultiplatformIT : BaseGradleIT() {
Assert.assertTrue("com/example/lib/MainKt.class" in jvmJarEntries) Assert.assertTrue("com/example/lib/MainKt.class" in jvmJarEntries)
when (jsCompilerType) { when (jsCompilerType) {
JsCompilerType.LEGACY -> { JsCompilerType.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)
@@ -165,7 +165,7 @@ 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)
} }
JsCompilerType.KLIB -> { JsCompilerType.klib -> {
groupDir.resolve(jsJarName).exists() groupDir.resolve(jsJarName).exists()
} }
} }
@@ -213,7 +213,7 @@ class NewMultiplatformIT : BaseGradleIT() {
Assert.assertTrue(resolve("com/example/app/AKt.kotlin_metadata").exists()) Assert.assertTrue(resolve("com/example/app/AKt.kotlin_metadata").exists())
} }
if (jsCompilerType == JsCompilerType.LEGACY) { if (jsCompilerType == JsCompilerType.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("))
@@ -248,10 +248,10 @@ class NewMultiplatformIT : BaseGradleIT() {
assertTasksExecuted(":resolveRuntimeDependencies") // KT-26301 assertTasksExecuted(":resolveRuntimeDependencies") // KT-26301
} }
if (jsCompilerType == JsCompilerType.BOTH) { if (jsCompilerType == JsCompilerType.both) {
listOf( listOf(
JsCompilerType.LEGACY, JsCompilerType.legacy,
JsCompilerType.KLIB JsCompilerType.klib
).forEach { ).forEach {
build( build(
"assemble", "assemble",
@@ -284,7 +284,7 @@ class NewMultiplatformIT : BaseGradleIT() {
} }
} }
if (jsCompilerType != JsCompilerType.LEGACY) return if (jsCompilerType != JsCompilerType.legacy) return
with(oldStyleAppProject) { with(oldStyleAppProject) {
setupWorkingDir() setupWorkingDir()
@@ -898,7 +898,7 @@ class NewMultiplatformIT : BaseGradleIT() {
projectDir.resolve("settings.gradle").modify { it.replace("enableFeaturePreview", "// enableFeaturePreview") } projectDir.resolve("settings.gradle").modify { it.replace("enableFeaturePreview", "// enableFeaturePreview") }
build( build(
"publish", "publish",
options = defaultBuildOptions().copy(jsCompilerType = JsCompilerType.LEGACY) options = defaultBuildOptions().copy(jsCompilerType = JsCompilerType.legacy)
) { assertSuccessful() } ) { assertSuccessful() }
projectDir.resolve("repo") projectDir.resolve("repo")
} }
@@ -2310,7 +2310,7 @@ class NewMultiplatformIT : BaseGradleIT() {
setupWorkingDir() setupWorkingDir()
gradleBuildScript().modify(::transformBuildScriptWithPluginsDsl) gradleBuildScript().modify(::transformBuildScriptWithPluginsDsl)
if (!jsIr) { if (!jsIr) {
gradleProperties().appendText(jsMode(JsCompilerType.LEGACY)) gradleProperties().appendText(jsMode(JsCompilerType.legacy))
} }
val tasks = listOf("jvm", "js", nativeHostTargetName).map { ":compileIntegrationTestKotlin${it.capitalize()}" } val tasks = listOf("jvm", "js", nativeHostTargetName).map { ":compileIntegrationTestKotlin${it.capitalize()}" }
@@ -40,7 +40,7 @@ class VariantAwareDependenciesIT : BaseGradleIT() {
assertContains(">> :${innerProject.projectName}:runtime --> sample-lib-nodejs-1.0.klib") assertContains(">> :${innerProject.projectName}:runtime --> sample-lib-nodejs-1.0.klib")
} }
gradleProperties().appendText(jsMode(JsCompilerType.LEGACY)) gradleProperties().appendText(jsMode(JsCompilerType.legacy))
testResolveAllConfigurations( testResolveAllConfigurations(
subproject = innerProject.projectName, subproject = innerProject.projectName,
@@ -13,7 +13,7 @@ class WorkersIT : BaseGradleIT() {
fun testParallelTasks() { fun testParallelTasks() {
parallelTasksImpl( parallelTasksImpl(
isParallel = true, isParallel = true,
jsCompilerType = JsCompilerType.LEGACY jsCompilerType = JsCompilerType.legacy
) )
} }
@@ -21,7 +21,7 @@ class WorkersIT : BaseGradleIT() {
fun testParallelTasksJsIr() { fun testParallelTasksJsIr() {
parallelTasksImpl( parallelTasksImpl(
isParallel = true, isParallel = true,
jsCompilerType = JsCompilerType.KLIB jsCompilerType = JsCompilerType.klib
) )
} }
@@ -29,7 +29,7 @@ class WorkersIT : BaseGradleIT() {
fun testNoParallelTasks() { fun testNoParallelTasks() {
parallelTasksImpl( parallelTasksImpl(
isParallel = false, isParallel = false,
jsCompilerType = JsCompilerType.LEGACY jsCompilerType = JsCompilerType.legacy
) )
} }
@@ -37,7 +37,7 @@ class WorkersIT : BaseGradleIT() {
fun testNoParallelTasksJsIr() { fun testNoParallelTasksJsIr() {
parallelTasksImpl( parallelTasksImpl(
isParallel = false, isParallel = false,
jsCompilerType = JsCompilerType.KLIB jsCompilerType = JsCompilerType.klib
) )
} }
@@ -64,7 +64,7 @@ class WorkersIT : BaseGradleIT() {
kotlinClassesDir(sourceSet = "metadata/main") + "common/A.kotlin_metadata", kotlinClassesDir(sourceSet = "metadata/main") + "common/A.kotlin_metadata",
kotlinClassesDir(sourceSet = "jvm/main") + "common/A.class", kotlinClassesDir(sourceSet = "jvm/main") + "common/A.class",
kotlinClassesDir(sourceSet = "js/main") + kotlinClassesDir(sourceSet = "js/main") +
if (jsCompilerType == JsCompilerType.KLIB) "default/manifest" else "new-mpp-parallel.js" if (jsCompilerType == JsCompilerType.klib) "default/manifest" else "new-mpp-parallel.js"
) )
expectedKotlinOutputFiles.forEach { assertFileExists(it) } expectedKotlinOutputFiles.forEach { assertFileExists(it) }
assertSubstringCount("Loaded GradleKotlinCompilerWork", 1) assertSubstringCount("Loaded GradleKotlinCompilerWork", 1)
@@ -168,9 +168,9 @@ open class KotlinJsPluginWrapper @Inject constructor(
val propertiesProvider = PropertiesProvider(project) val propertiesProvider = PropertiesProvider(project)
return when (propertiesProvider.jsCompiler) { return when (propertiesProvider.jsCompiler) {
JsCompilerType.KLIB -> KotlinJsIrPlugin(kotlinPluginVersion) JsCompilerType.klib -> KotlinJsIrPlugin(kotlinPluginVersion)
JsCompilerType.LEGACY -> KotlinJsPlugin(kotlinPluginVersion, false) JsCompilerType.legacy -> KotlinJsPlugin(kotlinPluginVersion, false)
JsCompilerType.BOTH -> KotlinJsPlugin(kotlinPluginVersion, true) JsCompilerType.both -> KotlinJsPlugin(kotlinPluginVersion, true)
} }
} }
@@ -180,8 +180,8 @@ open class KotlinJsPluginWrapper @Inject constructor(
val propertiesProvider = PropertiesProvider(project) val propertiesProvider = PropertiesProvider(project)
projectExtensionClass = when (propertiesProvider.jsCompiler) { projectExtensionClass = when (propertiesProvider.jsCompiler) {
JsCompilerType.KLIB -> KotlinJsIrProjectExtension::class JsCompilerType.klib -> KotlinJsIrProjectExtension::class
JsCompilerType.LEGACY, JsCompilerType.BOTH -> KotlinJsProjectExtension::class JsCompilerType.legacy, JsCompilerType.both -> KotlinJsProjectExtension::class
} }
} }
@@ -174,7 +174,7 @@ internal class PropertiesProvider private constructor(private val project: Proje
* Use Kotlin/JS backend mode * Use Kotlin/JS backend mode
*/ */
val jsCompiler: JsCompilerType val jsCompiler: JsCompilerType
get() = property(jsCompilerProperty)?.let { JsCompilerType.byArgument(it) } ?: JsCompilerType.KLIB get() = property(jsCompilerProperty)?.let { JsCompilerType.byArgument(it) } ?: JsCompilerType.klib
private fun propertyWithDeprecatedVariant(propName: String, deprecatedPropName: String): String? { private fun propertyWithDeprecatedVariant(propName: String, deprecatedPropName: String): String? {
val deprecatedProperty = property(deprecatedPropName) val deprecatedProperty = property(deprecatedPropName)
@@ -449,11 +449,11 @@ fun Configuration.usesPlatformOf(target: KotlinTarget): Configuration {
attributes.attribute(KotlinPlatformType.attribute, target.platformType) attributes.attribute(KotlinPlatformType.attribute, target.platformType)
if (target is KotlinJsTarget) { if (target is KotlinJsTarget) {
attributes.attribute(KotlinJsTarget.jsCompilerAttribute, JsCompilerType.LEGACY) attributes.attribute(KotlinJsTarget.jsCompilerAttribute, JsCompilerType.legacy)
} }
if (target is KotlinJsIrTarget) { if (target is KotlinJsIrTarget) {
attributes.attribute(KotlinJsTarget.jsCompilerAttribute, JsCompilerType.KLIB) attributes.attribute(KotlinJsTarget.jsCompilerAttribute, JsCompilerType.klib)
} }
// TODO: Provide an universal way to copy attributes from the target. // TODO: Provide an universal way to copy attributes from the target.
@@ -159,9 +159,9 @@ class KotlinMultiplatformPlugin(
with(project.multiplatformExtension.presets) { with(project.multiplatformExtension.presets) {
add(KotlinJvmTargetPreset(project, kotlinPluginVersion)) add(KotlinJvmTargetPreset(project, kotlinPluginVersion))
when (propertiesProvider.jsCompiler) { when (propertiesProvider.jsCompiler) {
JsCompilerType.LEGACY -> add(KotlinJsTargetPreset(project, kotlinPluginVersion, null)) JsCompilerType.legacy -> add(KotlinJsTargetPreset(project, kotlinPluginVersion, null))
JsCompilerType.KLIB -> add(KotlinJsIrTargetPreset(project, kotlinPluginVersion, false)) JsCompilerType.klib -> add(KotlinJsIrTargetPreset(project, kotlinPluginVersion, false))
JsCompilerType.BOTH -> add( JsCompilerType.both -> add(
KotlinJsTargetPreset( KotlinJsTargetPreset(
project, project,
kotlinPluginVersion, kotlinPluginVersion,
@@ -8,10 +8,12 @@ package org.jetbrains.kotlin.gradle.targets.js
import org.gradle.api.Named import org.gradle.api.Named
import java.io.Serializable import java.io.Serializable
// For Gradle attributes
@Suppress("EnumEntryName")
enum class JsCompilerType : Named, Serializable { enum class JsCompilerType : Named, Serializable {
LEGACY, legacy,
KLIB, klib,
BOTH; both;
override fun getName(): String = override fun getName(): String =
name.toLowerCase() name.toLowerCase()