[JS, IR] Make IR default for both mode
This commit is contained in:
committed by
Space Team
parent
9342356c38
commit
a3be2c893b
+6
-6
@@ -299,25 +299,25 @@ abstract class KotlinJsProjectExtension(project: Project) :
|
||||
val target: KotlinJsTargetDsl = when (compilerOrDefault) {
|
||||
KotlinJsCompilerType.LEGACY -> legacyPreset
|
||||
.also {
|
||||
it.irPreset = null
|
||||
it.mixedMode = false
|
||||
}
|
||||
.createTarget("js")
|
||||
|
||||
KotlinJsCompilerType.IR -> irPreset
|
||||
.also {
|
||||
it.mixedMode = false
|
||||
it.legacyPreset = null
|
||||
}
|
||||
.createTarget("js")
|
||||
|
||||
KotlinJsCompilerType.BOTH -> legacyPreset
|
||||
KotlinJsCompilerType.BOTH -> irPreset
|
||||
.also {
|
||||
irPreset.mixedMode = true
|
||||
it.irPreset = irPreset
|
||||
legacyPreset.mixedMode = true
|
||||
it.legacyPreset = legacyPreset
|
||||
}
|
||||
.createTarget(
|
||||
lowerCamelCaseName(
|
||||
"js",
|
||||
LEGACY.lowerName
|
||||
IR.lowerName
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
+4
-4
@@ -141,11 +141,11 @@ class KotlinMultiplatformPlugin : Plugin<Project> {
|
||||
fun setupDefaultPresets(project: Project) {
|
||||
with(project.multiplatformExtension.presets) {
|
||||
add(KotlinJvmTargetPreset(project))
|
||||
add(KotlinJsTargetPreset(project).apply { irPreset = null })
|
||||
add(KotlinJsIrTargetPreset(project).apply { mixedMode = false })
|
||||
add(KotlinJsTargetPreset(project).apply { mixedMode = false })
|
||||
add(KotlinJsIrTargetPreset(project))
|
||||
add(
|
||||
KotlinJsTargetPreset(project).apply {
|
||||
irPreset = KotlinJsIrTargetPreset(project).apply { mixedMode = true }
|
||||
KotlinJsIrTargetPreset(project).apply {
|
||||
legacyPreset = KotlinJsTargetPreset(project).apply { mixedMode = true }
|
||||
}
|
||||
)
|
||||
add(KotlinWasmTargetPreset(project))
|
||||
|
||||
+3
-4
@@ -136,12 +136,11 @@ internal class DefaultKotlinSourceSetFactory(
|
||||
if (sourceSet in notOnlyJsSourceSets) return
|
||||
|
||||
fun chooseCompilerAttribute(target: KotlinTarget): KotlinJsCompilerAttribute {
|
||||
if (target is KotlinJsIrTarget) {
|
||||
return KotlinJsCompilerAttribute.ir
|
||||
if (target is KotlinJsTarget) {
|
||||
return KotlinJsCompilerAttribute.legacy
|
||||
}
|
||||
|
||||
target as KotlinJsTarget
|
||||
return if (target.irTarget != null) KotlinJsCompilerAttribute.ir else KotlinJsCompilerAttribute.legacy
|
||||
return KotlinJsCompilerAttribute.ir
|
||||
}
|
||||
|
||||
project.kotlinExtension.targets
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@ abstract class KotlinJsCompilation @Inject internal constructor(
|
||||
|
||||
internal open val defaultExternalsOutputFormat: ExternalsOutputFormat = ExternalsOutputFormat.SOURCE
|
||||
|
||||
internal val binaries: KotlinJsBinaryContainer =
|
||||
val binaries: KotlinJsBinaryContainer =
|
||||
target.project.objects.newInstance(
|
||||
KotlinJsBinaryContainer::class.java,
|
||||
target,
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ class KotlinJsCompilationFactory(
|
||||
get() = KotlinJsCompilation::class.java
|
||||
|
||||
override fun defaultSourceSetName(compilationName: String): String {
|
||||
val classifier = if (target is KotlinJsTarget && target.irTarget != null)
|
||||
val classifier = if (target is KotlinJsTarget && target.mixedMode)
|
||||
target.disambiguationClassifierInPlatform
|
||||
else target.disambiguationClassifier
|
||||
|
||||
|
||||
+11
-50
@@ -34,7 +34,8 @@ abstract class KotlinJsTarget
|
||||
@Inject
|
||||
constructor(
|
||||
project: Project,
|
||||
platformType: KotlinPlatformType
|
||||
platformType: KotlinPlatformType,
|
||||
internal val mixedMode: Boolean
|
||||
) :
|
||||
KotlinTargetWithBinaries<KotlinJsCompilation, KotlinJsBinaryContainer>(project, platformType),
|
||||
KotlinTargetWithTests<JsAggregatingExecutionSource, KotlinJsReportAggregatingTestRun>,
|
||||
@@ -53,46 +54,24 @@ constructor(
|
||||
|
||||
internal val commonFakeApiElementsConfigurationName: String
|
||||
get() = lowerCamelCaseName(
|
||||
irTarget?.let {
|
||||
this.disambiguationClassifierInPlatform
|
||||
} ?: disambiguationClassifier,
|
||||
if (mixedMode)
|
||||
disambiguationClassifierInPlatform
|
||||
else
|
||||
disambiguationClassifier,
|
||||
"commonFakeApiElements"
|
||||
)
|
||||
|
||||
val disambiguationClassifierInPlatform: String?
|
||||
get() = if (irTarget != null) {
|
||||
disambiguationClassifier?.removeJsCompilerSuffix(LEGACY)
|
||||
get() = if (mixedMode) {
|
||||
disambiguationClassifier?.removeJsCompilerSuffix(KotlinJsCompilerType.LEGACY)
|
||||
} else {
|
||||
disambiguationClassifier
|
||||
}
|
||||
|
||||
override val kotlinComponents: Set<KotlinTargetComponent> by lazy {
|
||||
if (irTarget == null)
|
||||
super.kotlinComponents
|
||||
else {
|
||||
val mainCompilation = compilations.getByName(MAIN_COMPILATION_NAME)
|
||||
val usageContexts = createUsageContexts(mainCompilation) +
|
||||
irTarget!!.createUsageContexts(irTarget!!.compilations.getByName(MAIN_COMPILATION_NAME))
|
||||
|
||||
val componentName =
|
||||
if (project.kotlinExtension is KotlinMultiplatformExtension)
|
||||
irTarget?.let { targetName.removeJsCompilerSuffix(LEGACY) } ?: targetName
|
||||
else PRIMARY_SINGLE_COMPONENT_NAME
|
||||
|
||||
val result = createKotlinVariant(componentName, mainCompilation, usageContexts)
|
||||
|
||||
result.sourcesArtifacts = setOf(
|
||||
sourcesJarArtifact(mainCompilation, componentName, dashSeparatedName(targetName.toLowerCase()))
|
||||
)
|
||||
|
||||
setOf(result)
|
||||
}
|
||||
}
|
||||
|
||||
override fun createUsageContexts(producingCompilation: KotlinCompilation<*>): Set<DefaultKotlinUsageContext> {
|
||||
val usageContexts = super.createUsageContexts(producingCompilation)
|
||||
|
||||
if (isMpp!!) return usageContexts
|
||||
if (isMpp!! || mixedMode) return usageContexts
|
||||
|
||||
return usageContexts +
|
||||
DefaultKotlinUsageContext(
|
||||
@@ -103,27 +82,12 @@ constructor(
|
||||
)
|
||||
}
|
||||
|
||||
override fun createKotlinVariant(
|
||||
componentName: String,
|
||||
compilation: KotlinCompilation<*>,
|
||||
usageContexts: Set<DefaultKotlinUsageContext>
|
||||
): KotlinVariant {
|
||||
return super.createKotlinVariant(componentName, compilation, usageContexts).apply {
|
||||
irTarget?.let {
|
||||
artifactTargetName = targetName.removeJsCompilerSuffix(LEGACY)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override val binaries: KotlinJsBinaryContainer
|
||||
get() = compilations.withType(KotlinJsCompilation::class.java)
|
||||
.named(MAIN_COMPILATION_NAME)
|
||||
.map { it.binaries }
|
||||
.get()
|
||||
|
||||
var irTarget: KotlinJsIrTarget? = null
|
||||
internal set
|
||||
|
||||
open var isMpp: Boolean? = null
|
||||
internal set
|
||||
|
||||
@@ -144,7 +108,7 @@ constructor(
|
||||
project.objects.newInstance(KotlinBrowserJs::class.java, this).also {
|
||||
it.configure()
|
||||
|
||||
if (propertiesProvider.jsGenerateExecutableDefault && irTarget == null) {
|
||||
if (propertiesProvider.jsGenerateExecutableDefault && !mixedMode) {
|
||||
binaries.executable()
|
||||
}
|
||||
|
||||
@@ -164,7 +128,6 @@ constructor(
|
||||
|
||||
override fun browser(body: KotlinJsBrowserDsl.() -> Unit) {
|
||||
body(browser)
|
||||
irTarget?.browser(body)
|
||||
}
|
||||
|
||||
//node.js
|
||||
@@ -172,7 +135,7 @@ constructor(
|
||||
project.objects.newInstance(KotlinNodeJs::class.java, this).also {
|
||||
it.configure()
|
||||
|
||||
if (propertiesProvider.jsGenerateExecutableDefault && irTarget == null) {
|
||||
if (propertiesProvider.jsGenerateExecutableDefault && !mixedMode) {
|
||||
binaries.executable()
|
||||
}
|
||||
|
||||
@@ -193,7 +156,6 @@ constructor(
|
||||
|
||||
override fun nodejs(body: KotlinJsNodeDsl.() -> Unit) {
|
||||
body(nodejs)
|
||||
irTarget?.nodejs(body)
|
||||
}
|
||||
|
||||
override fun whenBrowserConfigured(body: KotlinJsBrowserDsl.() -> Unit) {
|
||||
@@ -220,6 +182,5 @@ constructor(
|
||||
sourceMapEmbedSources = null
|
||||
}
|
||||
}
|
||||
irTarget?.useCommonJs()
|
||||
}
|
||||
}
|
||||
+35
-50
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.mapTargetCompilationsToKpmVar
|
||||
import org.jetbrains.kotlin.gradle.plugin.statistics.KotlinBuildStatsService
|
||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget
|
||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTargetConfigurator
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTargetPreset
|
||||
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
||||
import org.jetbrains.kotlin.gradle.utils.runProjectConfigurationHealthCheckWhenEvaluated
|
||||
@@ -26,8 +27,7 @@ open class KotlinJsTargetPreset(
|
||||
) : KotlinOnlyTargetPreset<KotlinJsTarget, KotlinJsCompilation>(
|
||||
project
|
||||
) {
|
||||
var irPreset: KotlinJsIrTargetPreset? = null
|
||||
internal set
|
||||
var mixedMode: Boolean? = null
|
||||
|
||||
open val isMpp: Boolean
|
||||
get() = true
|
||||
@@ -35,33 +35,20 @@ open class KotlinJsTargetPreset(
|
||||
override val platformType: KotlinPlatformType
|
||||
get() = KotlinPlatformType.js
|
||||
|
||||
override fun useDisambiguationClassifierAsSourceSetNamePrefix() = irPreset == null
|
||||
|
||||
override fun overrideDisambiguationClassifierOnIdeImport(name: String): String? =
|
||||
irPreset?.let {
|
||||
name.removeJsCompilerSuffix(KotlinJsCompilerType.LEGACY)
|
||||
}
|
||||
|
||||
override fun instantiateTarget(name: String): KotlinJsTarget {
|
||||
return project.objects.newInstance(
|
||||
KotlinJsTarget::class.java,
|
||||
project,
|
||||
platformType
|
||||
platformType,
|
||||
mixedMode
|
||||
).apply {
|
||||
this.irTarget = irPreset?.createTarget(
|
||||
lowerCamelCaseName(
|
||||
name.removeJsCompilerSuffix(KotlinJsCompilerType.LEGACY),
|
||||
KotlinJsCompilerType.IR.lowerName
|
||||
)
|
||||
)?.also {
|
||||
it.legacyTarget = this
|
||||
}
|
||||
this.isMpp = this@KotlinJsTargetPreset.isMpp
|
||||
|
||||
project.runProjectConfigurationHealthCheckWhenEvaluated {
|
||||
if (!isBrowserConfigured && !isNodejsConfigured) {
|
||||
project.logger.warn(
|
||||
"""
|
||||
if (!mixedMode) {
|
||||
project.runProjectConfigurationHealthCheckWhenEvaluated {
|
||||
if (!isBrowserConfigured && !isNodejsConfigured) {
|
||||
project.logger.warn(
|
||||
"""
|
||||
Please choose a JavaScript environment to build distributions and run tests.
|
||||
Not choosing any of them will be an error in the future releases.
|
||||
kotlin {
|
||||
@@ -72,37 +59,23 @@ open class KotlinJsTargetPreset(
|
||||
}
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
)
|
||||
}
|
||||
val buildStatsService = KotlinBuildStatsService.getInstance()
|
||||
when {
|
||||
isBrowserConfigured && isNodejsConfigured -> buildStatsService?.report(StringMetrics.JS_TARGET_MODE, "both")
|
||||
isBrowserConfigured -> buildStatsService?.report(StringMetrics.JS_TARGET_MODE, "browser")
|
||||
isNodejsConfigured -> buildStatsService?.report(StringMetrics.JS_TARGET_MODE, "nodejs")
|
||||
!isBrowserConfigured && !isNodejsConfigured -> buildStatsService?.report(StringMetrics.JS_TARGET_MODE, "none")
|
||||
}
|
||||
Unit
|
||||
}
|
||||
val buildStatsService = KotlinBuildStatsService.getInstance()
|
||||
when {
|
||||
isBrowserConfigured && isNodejsConfigured -> buildStatsService?.report(StringMetrics.JS_TARGET_MODE, "both")
|
||||
isBrowserConfigured -> buildStatsService?.report(StringMetrics.JS_TARGET_MODE, "browser")
|
||||
isNodejsConfigured -> buildStatsService?.report(StringMetrics.JS_TARGET_MODE, "nodejs")
|
||||
!isBrowserConfigured && !isNodejsConfigured -> buildStatsService?.report(StringMetrics.JS_TARGET_MODE, "none")
|
||||
}
|
||||
Unit
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun createKotlinTargetConfigurator() = KotlinJsTargetConfigurator()
|
||||
|
||||
override fun getName(): String {
|
||||
return lowerCamelCaseName(
|
||||
PRESET_NAME,
|
||||
irPreset?.let { KotlinJsCompilerType.BOTH.lowerName }
|
||||
)
|
||||
}
|
||||
|
||||
override fun createCompilationFactory(forTarget: KotlinJsTarget): KotlinJsCompilationFactory {
|
||||
return KotlinJsCompilationFactory(forTarget)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val PRESET_NAME = "js"
|
||||
}
|
||||
|
||||
override fun createTarget(name: String): KotlinJsTarget {
|
||||
val result = super.createTarget(name)
|
||||
if (project.hasKpmModel) {
|
||||
@@ -110,6 +83,19 @@ open class KotlinJsTargetPreset(
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
override fun getName(): String = JS_PRESET_NAME
|
||||
|
||||
public override fun createCompilationFactory(forTarget: KotlinJsTarget): KotlinJsCompilationFactory {
|
||||
return KotlinJsCompilationFactory(project, forTarget)
|
||||
}
|
||||
|
||||
companion object {
|
||||
val JS_PRESET_NAME = lowerCamelCaseName(
|
||||
"js",
|
||||
KotlinJsCompilerType.LEGACY.lowerName
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
class KotlinJsSingleTargetPreset(
|
||||
@@ -120,15 +106,14 @@ class KotlinJsSingleTargetPreset(
|
||||
override val isMpp: Boolean
|
||||
get() = false
|
||||
|
||||
override fun overrideDisambiguationClassifierOnIdeImport(name: String): String? =
|
||||
null
|
||||
|
||||
// In a Kotlin/JS single-platform project, we don't need any disambiguation suffixes or prefixes in the names:
|
||||
override fun provideTargetDisambiguationClassifier(target: KotlinOnlyTarget<KotlinJsCompilation>): String? =
|
||||
irPreset?.let {
|
||||
if (mixedMode!!) {
|
||||
super.provideTargetDisambiguationClassifier(target)
|
||||
?.removePrefix(target.name.removeJsCompilerSuffix(KotlinJsCompilerType.LEGACY))
|
||||
?.decapitalize()
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
override fun createKotlinTargetConfigurator() = KotlinJsTargetConfigurator()
|
||||
|
||||
+3
-3
@@ -11,9 +11,9 @@ import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
|
||||
|
||||
fun KotlinJsTargetDsl.calculateJsCompilerType(): KotlinJsCompilerType {
|
||||
return when {
|
||||
this is KotlinJsTarget && this.irTarget == null -> KotlinJsCompilerType.LEGACY
|
||||
this is KotlinJsIrTarget && !this.mixedMode -> KotlinJsCompilerType.IR
|
||||
this is KotlinJsTarget && this.irTarget != null -> KotlinJsCompilerType.BOTH
|
||||
this is KotlinJsTarget && !this.mixedMode -> KotlinJsCompilerType.LEGACY
|
||||
this is KotlinJsIrTarget && this.legacyTarget == null -> KotlinJsCompilerType.IR
|
||||
this is KotlinJsIrTarget && this.legacyTarget != null -> KotlinJsCompilerType.BOTH
|
||||
else -> throw IllegalStateException("Unable to find previous Kotlin/JS compiler type for $this")
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -36,7 +36,7 @@ internal class DukatCompilationResolverPlugin(
|
||||
}
|
||||
val legacyTargetReuseIrTask by lazy {
|
||||
val target = compilation.target
|
||||
target is KotlinJsTarget && (target.irTarget != null && externalsOutputFormat == ExternalsOutputFormat.SOURCE)
|
||||
target is KotlinJsTarget && (target.mixedMode && externalsOutputFormat == ExternalsOutputFormat.SOURCE)
|
||||
}
|
||||
val externalsOutputFormat by lazy {
|
||||
compilation.externalsOutputFormat
|
||||
@@ -137,7 +137,7 @@ internal class DukatCompilationResolverPlugin(
|
||||
internal fun KotlinJsCompilation.shouldDependOnDukatIntegrationTask(): Boolean = with(target) {
|
||||
this is KotlinJsIrTarget ||
|
||||
(this is KotlinJsTarget &&
|
||||
(irTarget == null || externalsOutputFormat != ExternalsOutputFormat.SOURCE)
|
||||
(!mixedMode || externalsOutputFormat != ExternalsOutputFormat.SOURCE)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -68,6 +68,9 @@ constructor(
|
||||
compilation: KotlinJsCompilation = defaultCompilation
|
||||
): List<JsBinary> {
|
||||
if (target is KotlinJsIrTarget) {
|
||||
target.legacyTarget
|
||||
?.let { throw IllegalStateException("Can't use `executable()` with 'both' compiler type") }
|
||||
|
||||
target.whenBrowserConfigured {
|
||||
(this as KotlinJsIrSubTarget).produceExecutable()
|
||||
}
|
||||
@@ -84,9 +87,6 @@ constructor(
|
||||
}
|
||||
|
||||
if (target is KotlinJsTarget) {
|
||||
target.irTarget
|
||||
?.let { throw IllegalStateException("Can't use `executable()` with 'both' compiler type") }
|
||||
|
||||
target.whenBrowserConfigured {
|
||||
(this as KotlinJsSubTarget).produceExecutable()
|
||||
}
|
||||
|
||||
+2
-1
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.gradle.targets.js.ir
|
||||
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.JsIrCompilationDetails
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinCompilationFactory
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.getOrCreateDefaultSourceSet
|
||||
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
||||
|
||||
@@ -18,7 +19,7 @@ class KotlinJsIrCompilationFactory(
|
||||
|
||||
override fun defaultSourceSetName(compilationName: String): String {
|
||||
return lowerCamelCaseName(
|
||||
if (target.mixedMode)
|
||||
if (target.legacyTarget != null)
|
||||
target.disambiguationClassifierInPlatform
|
||||
else
|
||||
target.disambiguationClassifier,
|
||||
|
||||
+48
-7
@@ -11,11 +11,15 @@ import org.gradle.api.Task
|
||||
import org.gradle.api.tasks.Copy
|
||||
import org.gradle.api.tasks.TaskProvider
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJsOptions
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
|
||||
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
|
||||
import org.jetbrains.kotlin.gradle.plugin.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.AbstractKotlinTargetConfigurator.Companion.runTaskNameSuffix
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation.Companion.MAIN_COMPILATION_NAME
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.DefaultKotlinUsageContext
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinTargetWithBinaries
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinVariant
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.PRIMARY_SINGLE_COMPONENT_NAME
|
||||
import org.jetbrains.kotlin.gradle.targets.js.JsAggregatingExecutionSource
|
||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsReportAggregatingTestRun
|
||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget
|
||||
@@ -27,6 +31,7 @@ import org.jetbrains.kotlin.gradle.targets.js.npm.npmProject
|
||||
import org.jetbrains.kotlin.gradle.targets.js.typescript.TypeScriptValidationTask
|
||||
import org.jetbrains.kotlin.gradle.tasks.locateOrRegisterTask
|
||||
import org.jetbrains.kotlin.gradle.tasks.registerTask
|
||||
import org.jetbrains.kotlin.gradle.utils.dashSeparatedName
|
||||
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
||||
import org.jetbrains.kotlin.gradle.utils.setProperty
|
||||
import javax.inject.Inject
|
||||
@@ -36,7 +41,6 @@ abstract class KotlinJsIrTarget
|
||||
constructor(
|
||||
project: Project,
|
||||
platformType: KotlinPlatformType,
|
||||
internal val mixedMode: Boolean
|
||||
) :
|
||||
KotlinTargetWithBinaries<KotlinJsIrCompilation, KotlinJsBinaryContainer>(project, platformType),
|
||||
KotlinTargetWithTests<JsAggregatingExecutionSource, KotlinJsReportAggregatingTestRun>,
|
||||
@@ -62,10 +66,33 @@ constructor(
|
||||
field = value
|
||||
}
|
||||
|
||||
override val kotlinComponents: Set<KotlinTargetComponent> by lazy {
|
||||
if (legacyTarget == null)
|
||||
super.kotlinComponents
|
||||
else {
|
||||
val mainCompilation = compilations.getByName(MAIN_COMPILATION_NAME)
|
||||
val usageContexts = createUsageContexts(mainCompilation) +
|
||||
legacyTarget!!.createUsageContexts(legacyTarget!!.compilations.getByName(MAIN_COMPILATION_NAME))
|
||||
|
||||
val componentName =
|
||||
if (project.kotlinExtension is KotlinMultiplatformExtension)
|
||||
legacyTarget?.let { targetName.removeJsCompilerSuffix(KotlinJsCompilerType.IR) } ?: targetName
|
||||
else PRIMARY_SINGLE_COMPONENT_NAME
|
||||
|
||||
val result = createKotlinVariant(componentName, mainCompilation, usageContexts)
|
||||
|
||||
result.sourcesArtifacts = setOf(
|
||||
sourcesJarArtifact(mainCompilation, componentName, dashSeparatedName(targetName.toLowerCase()))
|
||||
)
|
||||
|
||||
setOf(result)
|
||||
}
|
||||
}
|
||||
|
||||
override fun createUsageContexts(producingCompilation: KotlinCompilation<*>): Set<DefaultKotlinUsageContext> {
|
||||
val usageContexts = super.createUsageContexts(producingCompilation)
|
||||
|
||||
if (isMpp!! || mixedMode) return usageContexts
|
||||
if (isMpp!!) return usageContexts
|
||||
|
||||
return usageContexts +
|
||||
DefaultKotlinUsageContext(
|
||||
@@ -76,17 +103,28 @@ constructor(
|
||||
)
|
||||
}
|
||||
|
||||
override fun createKotlinVariant(
|
||||
componentName: String,
|
||||
compilation: KotlinCompilation<*>,
|
||||
usageContexts: Set<DefaultKotlinUsageContext>
|
||||
): KotlinVariant {
|
||||
return super.createKotlinVariant(componentName, compilation, usageContexts).apply {
|
||||
legacyTarget?.let {
|
||||
artifactTargetName = targetName.removeJsCompilerSuffix(KotlinJsCompilerType.IR)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal val commonFakeApiElementsConfigurationName: String
|
||||
get() = lowerCamelCaseName(
|
||||
if (mixedMode)
|
||||
disambiguationClassifierInPlatform
|
||||
else
|
||||
disambiguationClassifier,
|
||||
legacyTarget?.let {
|
||||
this.disambiguationClassifierInPlatform
|
||||
} ?: disambiguationClassifier,
|
||||
"commonFakeApiElements"
|
||||
)
|
||||
|
||||
val disambiguationClassifierInPlatform: String?
|
||||
get() = if (mixedMode) {
|
||||
get() = if (legacyTarget != null) {
|
||||
disambiguationClassifier?.removeJsCompilerSuffix(KotlinJsCompilerType.IR)
|
||||
} else {
|
||||
disambiguationClassifier
|
||||
@@ -224,6 +262,7 @@ constructor(
|
||||
|
||||
override fun browser(body: KotlinJsBrowserDsl.() -> Unit) {
|
||||
body(browser)
|
||||
legacyTarget?.browser(body)
|
||||
}
|
||||
|
||||
//node.js
|
||||
@@ -248,6 +287,7 @@ constructor(
|
||||
|
||||
override fun nodejs(body: KotlinJsNodeDsl.() -> Unit) {
|
||||
body(nodejs)
|
||||
legacyTarget?.nodejs(body)
|
||||
}
|
||||
|
||||
//d8
|
||||
@@ -315,6 +355,7 @@ constructor(
|
||||
}
|
||||
}
|
||||
}
|
||||
legacyTarget?.useCommonJs()
|
||||
}
|
||||
|
||||
private fun KotlinJsOptions.configureCommonJsOptions() {
|
||||
|
||||
+44
-34
@@ -7,9 +7,7 @@ package org.jetbrains.kotlin.gradle.targets.js.ir
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.jetbrains.kotlin.gradle.plugin.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinCompilationFactory
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinOnlyTarget
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinOnlyTargetPreset
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.PublicationRegistrationMode
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.hasKpmModel
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.mapTargetCompilationsToKpmVariants
|
||||
@@ -23,21 +21,34 @@ open class KotlinJsIrTargetPreset(
|
||||
) : KotlinOnlyTargetPreset<KotlinJsIrTarget, KotlinJsIrCompilation>(
|
||||
project
|
||||
) {
|
||||
internal var mixedMode: Boolean? = null
|
||||
internal var legacyPreset: KotlinJsTargetPreset? = null
|
||||
internal set
|
||||
|
||||
open val isMpp: Boolean
|
||||
get() = true
|
||||
|
||||
override val platformType: KotlinPlatformType = KotlinPlatformType.js
|
||||
|
||||
override fun useDisambiguationClassifierAsSourceSetNamePrefix() = legacyPreset == null
|
||||
|
||||
override fun overrideDisambiguationClassifierOnIdeImport(name: String): String? =
|
||||
legacyPreset?.let {
|
||||
name.removeJsCompilerSuffix(KotlinJsCompilerType.IR)
|
||||
}
|
||||
|
||||
override fun instantiateTarget(name: String): KotlinJsIrTarget {
|
||||
return project.objects.newInstance(KotlinJsIrTarget::class.java, project, platformType, mixedMode).apply {
|
||||
return project.objects.newInstance(KotlinJsIrTarget::class.java, project, platformType).apply {
|
||||
this.isMpp = this@KotlinJsIrTargetPreset.isMpp
|
||||
if (!mixedMode) {
|
||||
project.runProjectConfigurationHealthCheckWhenEvaluated {
|
||||
if (!isBrowserConfigured && !isNodejsConfigured) {
|
||||
project.logger.warn(
|
||||
"""
|
||||
this.legacyTarget = legacyPreset?.createTarget(
|
||||
lowerCamelCaseName(
|
||||
name.removeJsCompilerSuffix(KotlinJsCompilerType.IR),
|
||||
KotlinJsCompilerType.LEGACY.lowerName
|
||||
)
|
||||
)
|
||||
project.runProjectConfigurationHealthCheckWhenEvaluated {
|
||||
if (!isBrowserConfigured && !isNodejsConfigured) {
|
||||
project.logger.warn(
|
||||
"""
|
||||
Please choose a JavaScript environment to build distributions and run tests.
|
||||
Not choosing any of them will be an error in the future releases.
|
||||
kotlin {
|
||||
@@ -48,17 +59,16 @@ open class KotlinJsIrTargetPreset(
|
||||
}
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
val buildStatsService = KotlinBuildStatsService.getInstance()
|
||||
when {
|
||||
isBrowserConfigured && isNodejsConfigured -> buildStatsService?.report(StringMetrics.JS_TARGET_MODE, "both")
|
||||
isBrowserConfigured -> buildStatsService?.report(StringMetrics.JS_TARGET_MODE, "browser")
|
||||
isNodejsConfigured -> buildStatsService?.report(StringMetrics.JS_TARGET_MODE, "nodejs")
|
||||
!isBrowserConfigured && !isNodejsConfigured -> buildStatsService?.report(StringMetrics.JS_TARGET_MODE, "none")
|
||||
}
|
||||
Unit
|
||||
)
|
||||
}
|
||||
val buildStatsService = KotlinBuildStatsService.getInstance()
|
||||
when {
|
||||
isBrowserConfigured && isNodejsConfigured -> buildStatsService?.report(StringMetrics.JS_TARGET_MODE, "both")
|
||||
isBrowserConfigured -> buildStatsService?.report(StringMetrics.JS_TARGET_MODE, "browser")
|
||||
isNodejsConfigured -> buildStatsService?.report(StringMetrics.JS_TARGET_MODE, "nodejs")
|
||||
!isBrowserConfigured && !isNodejsConfigured -> buildStatsService?.report(StringMetrics.JS_TARGET_MODE, "none")
|
||||
}
|
||||
Unit
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -74,19 +84,19 @@ open class KotlinJsIrTargetPreset(
|
||||
return result
|
||||
}
|
||||
|
||||
override fun getName(): String = JS_PRESET_NAME
|
||||
override fun getName(): String = lowerCamelCaseName(
|
||||
PRESET_NAME,
|
||||
legacyPreset?.let { KotlinJsCompilerType.BOTH.lowerName }
|
||||
)
|
||||
|
||||
//TODO[Ilya Goncharov] remove public morozov
|
||||
public override fun createCompilationFactory(
|
||||
override fun createCompilationFactory(
|
||||
forTarget: KotlinJsIrTarget
|
||||
): KotlinCompilationFactory<KotlinJsIrCompilation> =
|
||||
KotlinJsIrCompilationFactory(forTarget)
|
||||
): KotlinCompilationFactory<KotlinJsIrCompilation> {
|
||||
return KotlinJsIrCompilationFactory(forTarget)
|
||||
}
|
||||
|
||||
companion object {
|
||||
val JS_PRESET_NAME = lowerCamelCaseName(
|
||||
"js",
|
||||
KotlinJsCompilerType.IR.lowerName
|
||||
)
|
||||
const val PRESET_NAME = "js"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,16 +108,16 @@ class KotlinJsIrSingleTargetPreset(
|
||||
override val isMpp: Boolean
|
||||
get() = false
|
||||
|
||||
override fun overrideDisambiguationClassifierOnIdeImport(name: String): String? =
|
||||
null
|
||||
|
||||
// In a Kotlin/JS single-platform project, we don't need any disambiguation suffixes or prefixes in the names:
|
||||
override fun provideTargetDisambiguationClassifier(target: KotlinOnlyTarget<KotlinJsIrCompilation>): String? {
|
||||
return if (mixedMode!!) {
|
||||
override fun provideTargetDisambiguationClassifier(target: KotlinOnlyTarget<KotlinJsIrCompilation>): String? =
|
||||
legacyPreset?.let {
|
||||
super.provideTargetDisambiguationClassifier(target)
|
||||
?.removePrefix(target.name.removeJsCompilerSuffix(KotlinJsCompilerType.IR))
|
||||
?.decapitalize()
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
override fun createKotlinTargetConfigurator(): KotlinOnlyTargetConfigurator<KotlinJsIrCompilation, KotlinJsIrTarget> =
|
||||
KotlinJsIrTargetConfigurator()
|
||||
|
||||
+3
-2
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
||||
import org.jetbrains.kotlin.gradle.plugin.whenEvaluated
|
||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
|
||||
import org.jetbrains.kotlin.gradle.targets.js.npm.RequiresNpmDependencies
|
||||
import org.jetbrains.kotlin.gradle.targets.js.npm.resolved.KotlinProjectNpmResolution
|
||||
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
|
||||
@@ -103,8 +104,8 @@ internal class KotlinProjectNpmResolver(
|
||||
}
|
||||
|
||||
// Hack for mixed mode, when target is JS and contain JS-IR
|
||||
if (target is KotlinJsTarget) {
|
||||
target.irTarget?.compilations?.all { compilation ->
|
||||
if (target is KotlinJsIrTarget) {
|
||||
target.legacyTarget?.compilations?.all { compilation ->
|
||||
if (compilation is KotlinJsCompilation) {
|
||||
addCompilation(compilation)
|
||||
}
|
||||
|
||||
+3
-2
@@ -20,6 +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.KotlinJsTarget
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertNotNull
|
||||
@@ -133,8 +134,8 @@ class ConfigurationsTest : MultiplatformExtensionTest() {
|
||||
val project = buildProjectWithMPP {
|
||||
kotlin {
|
||||
js(BOTH)
|
||||
targets.withType<KotlinJsTarget> {
|
||||
irTarget!!.compilations.getByName("main").dependencies {
|
||||
targets.withType<KotlinJsIrTarget> {
|
||||
legacyTarget!!.compilations.getByName("main").dependencies {
|
||||
api("test:compilation-dependency")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user