[Gradle, JS] Both mode will leave as it was with legacy base
Because of both mode will be removed too (because it is redundant when legacy is deprecated), so it is no sense to change it
This commit is contained in:
+1
-1
@@ -469,7 +469,7 @@ class Kotlin2JsGradlePluginIT : AbstractKotlin2JsGradlePluginIT(false) {
|
||||
val baseBuildscript = baseSubproject.buildGradleKts
|
||||
val libBuildscript = libSubproject.buildGradleKts
|
||||
baseBuildscript.modify {
|
||||
it.replace("js(\"both\")", "js(\"both\") { (this as org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget).legacyTarget?.moduleName = \"base2\" }")
|
||||
it.replace("js(\"both\")", "js(\"both\") { moduleName = \"base2\" }")
|
||||
}
|
||||
libBuildscript.modify {
|
||||
it.replace("implementation(project(\":base\"))", "implementation(files(\"${normalizePath(originalBaseJar.toString())}\"))")
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
kotlin.targets.fromPreset(kotlin.presets.jsLegacy, 'nodeJs') {
|
||||
kotlin.targets.fromPreset(kotlin.presets.js, 'nodeJs') {
|
||||
nodejs()
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
kotlin.targets.fromPreset(kotlin.presets.jsLegacy, 'browser') {
|
||||
kotlin.targets.fromPreset(kotlin.presets.js, 'browser') {
|
||||
browser()
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
apply plugin: 'kotlin-platform-common'
|
||||
|
||||
dependencies {
|
||||
implementation 'com.example:sample-lib:1.0'
|
||||
implementation 'com.example:sample-lib:1.0'
|
||||
}
|
||||
+6
-6
@@ -299,25 +299,25 @@ abstract class KotlinJsProjectExtension(project: Project) :
|
||||
val target: KotlinJsTargetDsl = when (compilerOrDefault) {
|
||||
KotlinJsCompilerType.LEGACY -> legacyPreset
|
||||
.also {
|
||||
it.mixedMode = false
|
||||
it.irPreset = null
|
||||
}
|
||||
.createTarget("js")
|
||||
|
||||
KotlinJsCompilerType.IR -> irPreset
|
||||
.also {
|
||||
it.legacyPreset = null
|
||||
it.mixedMode = false
|
||||
}
|
||||
.createTarget("js")
|
||||
|
||||
KotlinJsCompilerType.BOTH -> irPreset
|
||||
KotlinJsCompilerType.BOTH -> legacyPreset
|
||||
.also {
|
||||
legacyPreset.mixedMode = true
|
||||
it.legacyPreset = legacyPreset
|
||||
irPreset.mixedMode = true
|
||||
it.irPreset = irPreset
|
||||
}
|
||||
.createTarget(
|
||||
lowerCamelCaseName(
|
||||
"js",
|
||||
IR.lowerName
|
||||
LEGACY.lowerName
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
+6
-6
@@ -106,7 +106,7 @@ private fun KotlinTargetContainerWithJsPresetFunctions.jsInternal(
|
||||
presets.getByName(
|
||||
lowerCamelCaseName(
|
||||
"js",
|
||||
if (compilerOrDefault == KotlinJsCompilerType.IR) null else compilerOrDefault.lowerName
|
||||
if (compilerOrDefault == KotlinJsCompilerType.LEGACY) null else compilerOrDefault.lowerName
|
||||
)
|
||||
) as KotlinTargetPreset<KotlinJsTargetDsl>,
|
||||
configure
|
||||
@@ -116,8 +116,8 @@ private fun KotlinTargetContainerWithJsPresetFunctions.jsInternal(
|
||||
}
|
||||
|
||||
// Try to find existing target with exact name
|
||||
// and removed suffix IR in case when current compiler is BOTH
|
||||
// and with append suffix IR in case when compiler for found target is not BOTH
|
||||
// and with append suffix Legacy in case when compiler for found target is BOTH,
|
||||
// and removed suffix Legacy in case when current compiler is BOTH
|
||||
private fun KotlinTargetContainerWithJsPresetFunctions.getExistingTarget(
|
||||
name: String,
|
||||
compiler: KotlinJsCompilerType?
|
||||
@@ -142,13 +142,13 @@ private fun KotlinTargetContainerWithJsPresetFunctions.getExistingTarget(
|
||||
val targetNameCandidate = getTargetName(name, compiler)
|
||||
|
||||
return targets.findByName(targetNameCandidate) as KotlinJsTargetDsl?
|
||||
?: getPreviousTarget(targetNameCandidate.removeJsCompilerSuffix(KotlinJsCompilerType.IR), true)
|
||||
?: getPreviousTarget(lowerCamelCaseName(targetNameCandidate, KotlinJsCompilerType.IR.lowerName), false)
|
||||
?: getPreviousTarget(targetNameCandidate.removeJsCompilerSuffix(KotlinJsCompilerType.LEGACY), true)
|
||||
?: getPreviousTarget(lowerCamelCaseName(targetNameCandidate, KotlinJsCompilerType.LEGACY.lowerName), false)
|
||||
}
|
||||
|
||||
private fun getTargetName(name: String, compiler: KotlinJsCompilerType?): String {
|
||||
return lowerCamelCaseName(
|
||||
name,
|
||||
if (compiler == KotlinJsCompilerType.BOTH) KotlinJsCompilerType.IR.lowerName else null
|
||||
if (compiler == KotlinJsCompilerType.BOTH) KotlinJsCompilerType.LEGACY.lowerName else null
|
||||
)
|
||||
}
|
||||
|
||||
+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 { mixedMode = false })
|
||||
add(KotlinJsIrTargetPreset(project))
|
||||
add(KotlinJsTargetPreset(project).apply { irPreset = null })
|
||||
add(KotlinJsIrTargetPreset(project).apply { mixedMode = false })
|
||||
add(
|
||||
KotlinJsIrTargetPreset(project).apply {
|
||||
legacyPreset = KotlinJsTargetPreset(project).apply { mixedMode = true }
|
||||
KotlinJsTargetPreset(project).apply {
|
||||
irPreset = KotlinJsIrTargetPreset(project).apply { mixedMode = true }
|
||||
}
|
||||
)
|
||||
add(KotlinWasmTargetPreset(project))
|
||||
|
||||
+4
-3
@@ -136,11 +136,12 @@ internal class DefaultKotlinSourceSetFactory(
|
||||
if (sourceSet in notOnlyJsSourceSets) return
|
||||
|
||||
fun chooseCompilerAttribute(target: KotlinTarget): KotlinJsCompilerAttribute {
|
||||
if (target is KotlinJsTarget) {
|
||||
return KotlinJsCompilerAttribute.legacy
|
||||
if (target is KotlinJsIrTarget) {
|
||||
return KotlinJsCompilerAttribute.ir
|
||||
}
|
||||
|
||||
return KotlinJsCompilerAttribute.ir
|
||||
target as KotlinJsTarget
|
||||
return if (target.irTarget != null) KotlinJsCompilerAttribute.ir else KotlinJsCompilerAttribute.legacy
|
||||
}
|
||||
|
||||
project.kotlinExtension.targets
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ abstract class KotlinJsCompilation @Inject internal constructor(
|
||||
final override val compilerOptions: HasCompilerOptions<KotlinJsCompilerOptions>
|
||||
get() = super.compilerOptions as HasCompilerOptions<KotlinJsCompilerOptions>
|
||||
|
||||
val binaries: KotlinJsBinaryContainer =
|
||||
internal 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.mixedMode)
|
||||
val classifier = if (target is KotlinJsTarget && target.irTarget != null)
|
||||
target.disambiguationClassifierInPlatform
|
||||
else target.disambiguationClassifier
|
||||
|
||||
|
||||
+50
-11
@@ -34,8 +34,7 @@ abstract class KotlinJsTarget
|
||||
@Inject
|
||||
constructor(
|
||||
project: Project,
|
||||
platformType: KotlinPlatformType,
|
||||
internal val mixedMode: Boolean
|
||||
platformType: KotlinPlatformType
|
||||
) :
|
||||
KotlinTargetWithBinaries<KotlinJsCompilation, KotlinJsBinaryContainer>(project, platformType),
|
||||
KotlinTargetWithTests<JsAggregatingExecutionSource, KotlinJsReportAggregatingTestRun>,
|
||||
@@ -54,24 +53,46 @@ constructor(
|
||||
|
||||
internal val commonFakeApiElementsConfigurationName: String
|
||||
get() = lowerCamelCaseName(
|
||||
if (mixedMode)
|
||||
disambiguationClassifierInPlatform
|
||||
else
|
||||
disambiguationClassifier,
|
||||
irTarget?.let {
|
||||
this.disambiguationClassifierInPlatform
|
||||
} ?: disambiguationClassifier,
|
||||
"commonFakeApiElements"
|
||||
)
|
||||
|
||||
val disambiguationClassifierInPlatform: String?
|
||||
get() = if (mixedMode) {
|
||||
disambiguationClassifier?.removeJsCompilerSuffix(KotlinJsCompilerType.LEGACY)
|
||||
get() = if (irTarget != null) {
|
||||
disambiguationClassifier?.removeJsCompilerSuffix(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!! || mixedMode) return usageContexts
|
||||
if (isMpp!!) return usageContexts
|
||||
|
||||
return usageContexts +
|
||||
DefaultKotlinUsageContext(
|
||||
@@ -82,12 +103,27 @@ 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
|
||||
|
||||
@@ -108,7 +144,7 @@ constructor(
|
||||
project.objects.newInstance(KotlinBrowserJs::class.java, this).also {
|
||||
it.configure()
|
||||
|
||||
if (propertiesProvider.jsGenerateExecutableDefault && !mixedMode) {
|
||||
if (propertiesProvider.jsGenerateExecutableDefault && irTarget == null) {
|
||||
binaries.executable()
|
||||
}
|
||||
|
||||
@@ -128,6 +164,7 @@ constructor(
|
||||
|
||||
override fun browser(body: KotlinJsBrowserDsl.() -> Unit) {
|
||||
body(browser)
|
||||
irTarget?.browser(body)
|
||||
}
|
||||
|
||||
//node.js
|
||||
@@ -135,7 +172,7 @@ constructor(
|
||||
project.objects.newInstance(KotlinNodeJs::class.java, this).also {
|
||||
it.configure()
|
||||
|
||||
if (propertiesProvider.jsGenerateExecutableDefault && !mixedMode) {
|
||||
if (propertiesProvider.jsGenerateExecutableDefault && irTarget == null) {
|
||||
binaries.executable()
|
||||
}
|
||||
|
||||
@@ -156,6 +193,7 @@ constructor(
|
||||
|
||||
override fun nodejs(body: KotlinJsNodeDsl.() -> Unit) {
|
||||
body(nodejs)
|
||||
irTarget?.nodejs(body)
|
||||
}
|
||||
|
||||
override fun whenBrowserConfigured(body: KotlinJsBrowserDsl.() -> Unit) {
|
||||
@@ -182,6 +220,7 @@ constructor(
|
||||
sourceMapEmbedSources = null
|
||||
}
|
||||
}
|
||||
irTarget?.useCommonJs()
|
||||
}
|
||||
|
||||
override fun useEsModules() {
|
||||
|
||||
+50
-35
@@ -16,7 +16,6 @@ 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
|
||||
@@ -27,7 +26,8 @@ open class KotlinJsTargetPreset(
|
||||
) : KotlinOnlyTargetPreset<KotlinJsTarget, KotlinJsCompilation>(
|
||||
project
|
||||
) {
|
||||
var mixedMode: Boolean? = null
|
||||
var irPreset: KotlinJsIrTargetPreset? = null
|
||||
internal set
|
||||
|
||||
open val isMpp: Boolean
|
||||
get() = true
|
||||
@@ -35,20 +35,33 @@ 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,
|
||||
mixedMode
|
||||
platformType
|
||||
).apply {
|
||||
this.irTarget = irPreset?.createTarget(
|
||||
lowerCamelCaseName(
|
||||
name.removeJsCompilerSuffix(KotlinJsCompilerType.LEGACY),
|
||||
KotlinJsCompilerType.IR.lowerName
|
||||
)
|
||||
)?.also {
|
||||
it.legacyTarget = this
|
||||
}
|
||||
this.isMpp = this@KotlinJsTargetPreset.isMpp
|
||||
|
||||
if (!mixedMode) {
|
||||
project.runProjectConfigurationHealthCheckWhenEvaluated {
|
||||
if (!isBrowserConfigured && !isNodejsConfigured) {
|
||||
project.logger.warn(
|
||||
"""
|
||||
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 {
|
||||
@@ -59,23 +72,37 @@ 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) {
|
||||
@@ -83,19 +110,6 @@ open class KotlinJsTargetPreset(
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
override fun getName(): String = JS_PRESET_NAME
|
||||
|
||||
public override fun createCompilationFactory(forTarget: KotlinJsTarget): KotlinJsCompilationFactory {
|
||||
return KotlinJsCompilationFactory(forTarget)
|
||||
}
|
||||
|
||||
companion object {
|
||||
val JS_PRESET_NAME = lowerCamelCaseName(
|
||||
"js",
|
||||
KotlinJsCompilerType.LEGACY.lowerName
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
class KotlinJsSingleTargetPreset(
|
||||
@@ -106,14 +120,15 @@ 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? =
|
||||
if (mixedMode!!) {
|
||||
irPreset?.let {
|
||||
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.mixedMode -> KotlinJsCompilerType.LEGACY
|
||||
this is KotlinJsIrTarget && this.legacyTarget == null -> KotlinJsCompilerType.IR
|
||||
this is KotlinJsIrTarget && this.legacyTarget != null -> KotlinJsCompilerType.BOTH
|
||||
this is KotlinJsTarget && this.irTarget == null -> KotlinJsCompilerType.LEGACY
|
||||
this is KotlinJsIrTarget && !this.mixedMode -> KotlinJsCompilerType.IR
|
||||
this is KotlinJsTarget && this.irTarget != null -> KotlinJsCompilerType.BOTH
|
||||
else -> throw IllegalStateException("Unable to find previous Kotlin/JS compiler type for $this")
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -68,9 +68,6 @@ 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()
|
||||
}
|
||||
@@ -87,6 +84,9 @@ constructor(
|
||||
}
|
||||
|
||||
if (target is KotlinJsTarget) {
|
||||
target.irTarget
|
||||
?.let { throw IllegalStateException("Can't use `executable()` with 'both' compiler type") }
|
||||
|
||||
target.whenBrowserConfigured {
|
||||
(this as KotlinJsSubTarget).produceExecutable()
|
||||
}
|
||||
|
||||
+1
-2
@@ -7,7 +7,6 @@ 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
|
||||
|
||||
@@ -19,7 +18,7 @@ class KotlinJsIrCompilationFactory(
|
||||
|
||||
override fun defaultSourceSetName(compilationName: String): String {
|
||||
return lowerCamelCaseName(
|
||||
if (target.legacyTarget != null)
|
||||
if (target.mixedMode)
|
||||
target.disambiguationClassifierInPlatform
|
||||
else
|
||||
target.disambiguationClassifier,
|
||||
|
||||
+1
-2
@@ -26,7 +26,6 @@ import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile
|
||||
import org.jetbrains.kotlin.gradle.utils.toHexString
|
||||
import org.jetbrains.kotlin.statistics.metrics.BooleanMetrics
|
||||
import org.jetbrains.kotlin.statistics.metrics.StringMetrics
|
||||
import org.jetbrains.kotlin.utils.tryConstructClassFromStringArgs
|
||||
import java.io.File
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.security.MessageDigest
|
||||
@@ -95,7 +94,7 @@ abstract class KotlinJsIrLink @Inject constructor(
|
||||
@get:IgnoreEmptyDirectories
|
||||
@get:NormalizeLineEndings
|
||||
@get:InputDirectory
|
||||
@get:PathSensitive(PathSensitivity.NONE)
|
||||
@get:PathSensitive(PathSensitivity.RELATIVE)
|
||||
internal abstract val entryModule: DirectoryProperty
|
||||
|
||||
@get:Internal
|
||||
|
||||
+7
-48
@@ -11,15 +11,11 @@ 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
|
||||
@@ -30,7 +26,6 @@ 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
|
||||
@@ -40,6 +35,7 @@ abstract class KotlinJsIrTarget
|
||||
constructor(
|
||||
project: Project,
|
||||
platformType: KotlinPlatformType,
|
||||
internal val mixedMode: Boolean
|
||||
) :
|
||||
KotlinTargetWithBinaries<KotlinJsIrCompilation, KotlinJsBinaryContainer>(project, platformType),
|
||||
KotlinTargetWithTests<JsAggregatingExecutionSource, KotlinJsReportAggregatingTestRun>,
|
||||
@@ -65,33 +61,10 @@ 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!!) return usageContexts
|
||||
if (isMpp!! || mixedMode) return usageContexts
|
||||
|
||||
return usageContexts +
|
||||
DefaultKotlinUsageContext(
|
||||
@@ -102,28 +75,17 @@ 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(
|
||||
legacyTarget?.let {
|
||||
this.disambiguationClassifierInPlatform
|
||||
} ?: disambiguationClassifier,
|
||||
if (mixedMode)
|
||||
disambiguationClassifierInPlatform
|
||||
else
|
||||
disambiguationClassifier,
|
||||
"commonFakeApiElements"
|
||||
)
|
||||
|
||||
val disambiguationClassifierInPlatform: String?
|
||||
get() = if (legacyTarget != null) {
|
||||
get() = if (mixedMode) {
|
||||
disambiguationClassifier?.removeJsCompilerSuffix(KotlinJsCompilerType.IR)
|
||||
} else {
|
||||
disambiguationClassifier
|
||||
@@ -256,7 +218,6 @@ constructor(
|
||||
|
||||
override fun browser(body: KotlinJsBrowserDsl.() -> Unit) {
|
||||
body(browser)
|
||||
legacyTarget?.browser(body)
|
||||
}
|
||||
|
||||
//node.js
|
||||
@@ -281,7 +242,6 @@ constructor(
|
||||
|
||||
override fun nodejs(body: KotlinJsNodeDsl.() -> Unit) {
|
||||
body(nodejs)
|
||||
legacyTarget?.nodejs(body)
|
||||
}
|
||||
|
||||
//d8
|
||||
@@ -349,7 +309,6 @@ constructor(
|
||||
}
|
||||
}
|
||||
}
|
||||
legacyTarget?.useCommonJs()
|
||||
}
|
||||
|
||||
override fun useEsModules() {
|
||||
|
||||
+34
-44
@@ -7,7 +7,9 @@ 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.*
|
||||
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.pm20.PublicationRegistrationMode
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.hasKpmModel
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.mapTargetCompilationsToKpmVariants
|
||||
@@ -21,34 +23,21 @@ open class KotlinJsIrTargetPreset(
|
||||
) : KotlinOnlyTargetPreset<KotlinJsIrTarget, KotlinJsIrCompilation>(
|
||||
project
|
||||
) {
|
||||
internal var legacyPreset: KotlinJsTargetPreset? = null
|
||||
internal set
|
||||
internal var mixedMode: Boolean? = null
|
||||
|
||||
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).apply {
|
||||
return project.objects.newInstance(KotlinJsIrTarget::class.java, project, platformType, mixedMode).apply {
|
||||
this.isMpp = this@KotlinJsIrTargetPreset.isMpp
|
||||
this.legacyTarget = legacyPreset?.createTarget(
|
||||
lowerCamelCaseName(
|
||||
name.removeJsCompilerSuffix(KotlinJsCompilerType.IR),
|
||||
KotlinJsCompilerType.LEGACY.lowerName
|
||||
)
|
||||
)
|
||||
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 {
|
||||
@@ -59,16 +48,17 @@ 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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -84,19 +74,19 @@ open class KotlinJsIrTargetPreset(
|
||||
return result
|
||||
}
|
||||
|
||||
override fun getName(): String = lowerCamelCaseName(
|
||||
PRESET_NAME,
|
||||
legacyPreset?.let { KotlinJsCompilerType.BOTH.lowerName }
|
||||
)
|
||||
override fun getName(): String = JS_PRESET_NAME
|
||||
|
||||
override fun createCompilationFactory(
|
||||
//TODO[Ilya Goncharov] remove public morozov
|
||||
public override fun createCompilationFactory(
|
||||
forTarget: KotlinJsIrTarget
|
||||
): KotlinCompilationFactory<KotlinJsIrCompilation> {
|
||||
return KotlinJsIrCompilationFactory(forTarget)
|
||||
}
|
||||
): KotlinCompilationFactory<KotlinJsIrCompilation> =
|
||||
KotlinJsIrCompilationFactory(forTarget)
|
||||
|
||||
companion object {
|
||||
const val PRESET_NAME = "js"
|
||||
val JS_PRESET_NAME = lowerCamelCaseName(
|
||||
"js",
|
||||
KotlinJsCompilerType.IR.lowerName
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,16 +98,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? =
|
||||
legacyPreset?.let {
|
||||
override fun provideTargetDisambiguationClassifier(target: KotlinOnlyTarget<KotlinJsIrCompilation>): String? {
|
||||
return if (mixedMode!!) {
|
||||
super.provideTargetDisambiguationClassifier(target)
|
||||
?.removePrefix(target.name.removeJsCompilerSuffix(KotlinJsCompilerType.IR))
|
||||
?.decapitalize()
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
override fun createKotlinTargetConfigurator(): KotlinOnlyTargetConfigurator<KotlinJsIrCompilation, KotlinJsIrTarget> =
|
||||
KotlinJsIrTargetConfigurator()
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ class KotlinWasmTargetPreset(
|
||||
project.logger.warn("New 'wasm' target is Work-in-Progress and is subject to change without notice.")
|
||||
}
|
||||
|
||||
val irTarget = project.objects.newInstance(KotlinJsIrTarget::class.java, project, KotlinPlatformType.wasm)
|
||||
val irTarget = project.objects.newInstance(KotlinJsIrTarget::class.java, project, KotlinPlatformType.wasm, false)
|
||||
irTarget.isMpp = true
|
||||
|
||||
project.runProjectConfigurationHealthCheckWhenEvaluated {
|
||||
|
||||
+2
-3
@@ -16,7 +16,6 @@ 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
|
||||
@@ -104,8 +103,8 @@ internal class KotlinProjectNpmResolver(
|
||||
}
|
||||
|
||||
// Hack for mixed mode, when target is JS and contain JS-IR
|
||||
if (target is KotlinJsIrTarget) {
|
||||
target.legacyTarget?.compilations?.all { compilation ->
|
||||
if (target is KotlinJsTarget) {
|
||||
target.irTarget?.compilations?.all { compilation ->
|
||||
if (compilation is KotlinJsCompilation) {
|
||||
addCompilation(compilation)
|
||||
}
|
||||
|
||||
+2
-3
@@ -20,7 +20,6 @@ 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
|
||||
@@ -134,8 +133,8 @@ class ConfigurationsTest : MultiplatformExtensionTest() {
|
||||
val project = buildProjectWithMPP {
|
||||
kotlin {
|
||||
js(BOTH)
|
||||
targets.withType<KotlinJsIrTarget> {
|
||||
legacyTarget!!.compilations.getByName("main").dependencies {
|
||||
targets.withType<KotlinJsTarget> {
|
||||
irTarget!!.compilations.getByName("main").dependencies {
|
||||
api("test:compilation-dependency")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user