[Gradle, JS] Js default compiler type for mpp
This commit is contained in:
+10
-5
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.generators.gradle.dsl
|
|||||||
|
|
||||||
import groovy.lang.Closure
|
import groovy.lang.Closure
|
||||||
import org.gradle.util.ConfigureUtil
|
import org.gradle.util.ConfigureUtil
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerTypeHolder
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetsContainerWithPresets
|
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetsContainerWithPresets
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
@@ -14,7 +15,10 @@ fun main() {
|
|||||||
generateKotlinTargetContainerWithPresetFunctionsInterface()
|
generateKotlinTargetContainerWithPresetFunctionsInterface()
|
||||||
}
|
}
|
||||||
|
|
||||||
private val parentInterface = KotlinTargetsContainerWithPresets::class
|
private val parentInterfaces = listOf(
|
||||||
|
KotlinTargetsContainerWithPresets::class,
|
||||||
|
KotlinJsCompilerTypeHolder::class
|
||||||
|
)
|
||||||
|
|
||||||
private val presetsProperty = KotlinTargetsContainerWithPresets::presets.name
|
private val presetsProperty = KotlinTargetsContainerWithPresets::presets.name
|
||||||
|
|
||||||
@@ -24,15 +28,16 @@ private fun generateKotlinTargetContainerWithPresetFunctionsInterface() {
|
|||||||
it.generatePresetFunctions(presetsProperty, "configureOrCreate")
|
it.generatePresetFunctions(presetsProperty, "configureOrCreate")
|
||||||
}
|
}
|
||||||
|
|
||||||
val parentInterfaceName =
|
val parentInterfaceNames =
|
||||||
typeName(parentInterface.java.canonicalName)
|
parentInterfaces.map { typeName(it.java.canonicalName) }
|
||||||
|
|
||||||
|
|
||||||
val className =
|
val className =
|
||||||
typeName("org.jetbrains.kotlin.gradle.dsl.KotlinTargetContainerWithPresetFunctions")
|
typeName("org.jetbrains.kotlin.gradle.dsl.KotlinTargetContainerWithPresetFunctions")
|
||||||
|
|
||||||
val imports = allPresetEntries
|
val imports = allPresetEntries
|
||||||
.flatMap { it.typeNames() }
|
.flatMap { it.typeNames() }
|
||||||
.plus(parentInterfaceName)
|
.plus(parentInterfaceNames)
|
||||||
.plus(typeName(ConfigureUtil::class.java.canonicalName))
|
.plus(typeName(ConfigureUtil::class.java.canonicalName))
|
||||||
.plus(typeName(Closure::class.java.canonicalName))
|
.plus(typeName(Closure::class.java.canonicalName))
|
||||||
.filter { it.packageName() != className.packageName() }
|
.filter { it.packageName() != className.packageName() }
|
||||||
@@ -46,7 +51,7 @@ private fun generateKotlinTargetContainerWithPresetFunctionsInterface() {
|
|||||||
"package ${className.packageName()}",
|
"package ${className.packageName()}",
|
||||||
imports,
|
imports,
|
||||||
generatedCodeWarning,
|
generatedCodeWarning,
|
||||||
"interface ${className.renderShort()} : ${parentInterfaceName.renderShort()} {",
|
"interface ${className.renderShort()} : ${parentInterfaceNames.joinToString { it.renderShort() }} {",
|
||||||
functions.joinToString("\n\n") { it.indented(4) },
|
functions.joinToString("\n\n") { it.indented(4) },
|
||||||
"}"
|
"}"
|
||||||
).joinToString("\n\n")
|
).joinToString("\n\n")
|
||||||
|
|||||||
+2
-2
@@ -69,7 +69,7 @@ internal class KotlinJsPresetEntry(
|
|||||||
return """
|
return """
|
||||||
fun $presetName(
|
fun $presetName(
|
||||||
name: String = "$presetName",
|
name: String = "$presetName",
|
||||||
compiler: JsCompilerType = JsCompilerType.legacy,
|
compiler: JsCompilerType = defaultJsCompilerType,
|
||||||
configure: ${targetType.renderShort()}.() -> Unit = { }
|
configure: ${targetType.renderShort()}.() -> Unit = { }
|
||||||
): ${targetType.renderShort()} =
|
): ${targetType.renderShort()} =
|
||||||
$configureOrCreateFunctionName(
|
$configureOrCreateFunctionName(
|
||||||
@@ -86,7 +86,7 @@ internal class KotlinJsPresetEntry(
|
|||||||
fun $presetName(
|
fun $presetName(
|
||||||
name: String = "$presetName",
|
name: String = "$presetName",
|
||||||
configure: ${targetType.renderShort()}.() -> Unit = { }
|
configure: ${targetType.renderShort()}.() -> Unit = { }
|
||||||
) = $presetName(name = "$presetName", compiler = JsCompilerType.legacy, configure = configure)
|
) = $presetName(name = "$presetName", compiler = defaultJsCompilerType, configure = configure)
|
||||||
|
|
||||||
fun $presetName(
|
fun $presetName(
|
||||||
compiler: JsCompilerType,
|
compiler: JsCompilerType,
|
||||||
|
|||||||
+3
@@ -25,6 +25,9 @@ open class KotlinMultiplatformExtension :
|
|||||||
override lateinit var targets: NamedDomainObjectCollection<KotlinTarget>
|
override lateinit var targets: NamedDomainObjectCollection<KotlinTarget>
|
||||||
internal set
|
internal set
|
||||||
|
|
||||||
|
override lateinit var defaultJsCompilerType: JsCompilerType
|
||||||
|
internal set
|
||||||
|
|
||||||
@Suppress("unused") // DSL
|
@Suppress("unused") // DSL
|
||||||
val testableTargets: NamedDomainObjectCollection<KotlinTargetWithTests<*, *>>
|
val testableTargets: NamedDomainObjectCollection<KotlinTargetWithTests<*, *>>
|
||||||
get() = targets.withType(KotlinTargetWithTests::class.java)
|
get() = targets.withType(KotlinTargetWithTests::class.java)
|
||||||
|
|||||||
+5
-4
@@ -3,6 +3,7 @@ package org.jetbrains.kotlin.gradle.dsl
|
|||||||
import groovy.lang.Closure
|
import groovy.lang.Closure
|
||||||
import org.gradle.util.ConfigureUtil
|
import org.gradle.util.ConfigureUtil
|
||||||
import org.jetbrains.kotlin.gradle.plugin.JsCompilerType
|
import org.jetbrains.kotlin.gradle.plugin.JsCompilerType
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerTypeHolder
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetPreset
|
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetPreset
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetsContainerWithPresets
|
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetsContainerWithPresets
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.*
|
import org.jetbrains.kotlin.gradle.plugin.mpp.*
|
||||||
@@ -12,7 +13,7 @@ import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
|||||||
|
|
||||||
// DO NOT EDIT MANUALLY! Generated by org.jetbrains.kotlin.generators.gradle.dsl.MppPresetFunctionsCodegenKt
|
// DO NOT EDIT MANUALLY! Generated by org.jetbrains.kotlin.generators.gradle.dsl.MppPresetFunctionsCodegenKt
|
||||||
|
|
||||||
interface KotlinTargetContainerWithPresetFunctions : KotlinTargetsContainerWithPresets {
|
interface KotlinTargetContainerWithPresetFunctions : KotlinTargetsContainerWithPresets, KotlinJsCompilerTypeHolder {
|
||||||
|
|
||||||
fun jvm(
|
fun jvm(
|
||||||
name: String = "jvm",
|
name: String = "jvm",
|
||||||
@@ -31,11 +32,11 @@ interface KotlinTargetContainerWithPresetFunctions : KotlinTargetsContainerWithP
|
|||||||
|
|
||||||
fun js(
|
fun js(
|
||||||
name: String = "js",
|
name: String = "js",
|
||||||
compiler: JsCompilerType = JsCompilerType.legacy,
|
compiler: JsCompilerType = defaultJsCompilerType,
|
||||||
configure: KotlinJsTargetDsl.() -> Unit = { }
|
configure: KotlinJsTargetDsl.() -> Unit = { }
|
||||||
): KotlinJsTargetDsl =
|
): KotlinJsTargetDsl =
|
||||||
configureOrCreate(
|
configureOrCreate(
|
||||||
lowerCamelCaseName(name, if (compiler == JsCompilerType.both) JsCompilerType.legacy.name else ""),
|
lowerCamelCaseName(name, if (compiler == JsCompilerType.both) JsCompilerType.legacy.name else null),
|
||||||
presets.getByName(
|
presets.getByName(
|
||||||
lowerCamelCaseName(
|
lowerCamelCaseName(
|
||||||
"js",
|
"js",
|
||||||
@@ -48,7 +49,7 @@ interface KotlinTargetContainerWithPresetFunctions : KotlinTargetsContainerWithP
|
|||||||
fun js(
|
fun js(
|
||||||
name: String = "js",
|
name: String = "js",
|
||||||
configure: KotlinJsTargetDsl.() -> Unit = { }
|
configure: KotlinJsTargetDsl.() -> Unit = { }
|
||||||
) = js(name = "js", compiler = JsCompilerType.legacy, configure = configure)
|
) = js(name = "js", compiler = defaultJsCompilerType, configure = configure)
|
||||||
|
|
||||||
fun js(
|
fun js(
|
||||||
compiler: JsCompilerType,
|
compiler: JsCompilerType,
|
||||||
|
|||||||
+2
@@ -73,6 +73,8 @@ class KotlinMultiplatformPlugin(
|
|||||||
presets = project.container(KotlinTargetPreset::class.java)
|
presets = project.container(KotlinTargetPreset::class.java)
|
||||||
addExtension("presets", presets)
|
addExtension("presets", presets)
|
||||||
|
|
||||||
|
defaultJsCompilerType = PropertiesProvider(project).jsCompiler
|
||||||
|
|
||||||
isGradleMetadataAvailable =
|
isGradleMetadataAvailable =
|
||||||
featurePreviews.activeFeatures.find { it.name == "GRADLE_METADATA" }?.let { metadataFeature ->
|
featurePreviews.activeFeatures.find { it.name == "GRADLE_METADATA" }?.let { metadataFeature ->
|
||||||
isGradleMetadataExperimental = true
|
isGradleMetadataExperimental = true
|
||||||
|
|||||||
Reference in New Issue
Block a user