[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 baseBuildscript = baseSubproject.buildGradleKts
|
||||||
val libBuildscript = libSubproject.buildGradleKts
|
val libBuildscript = libSubproject.buildGradleKts
|
||||||
baseBuildscript.modify {
|
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 {
|
libBuildscript.modify {
|
||||||
it.replace("implementation(project(\":base\"))", "implementation(files(\"${normalizePath(originalBaseJar.toString())}\"))")
|
it.replace("implementation(project(\":base\"))", "implementation(files(\"${normalizePath(originalBaseJar.toString())}\"))")
|
||||||
|
|||||||
+1
-1
@@ -15,7 +15,7 @@ repositories {
|
|||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|
||||||
kotlin.targets.fromPreset(kotlin.presets.jsLegacy, 'nodeJs') {
|
kotlin.targets.fromPreset(kotlin.presets.js, 'nodeJs') {
|
||||||
nodejs()
|
nodejs()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -15,7 +15,7 @@ repositories {
|
|||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|
||||||
kotlin.targets.fromPreset(kotlin.presets.jsLegacy, 'browser') {
|
kotlin.targets.fromPreset(kotlin.presets.js, 'browser') {
|
||||||
browser()
|
browser()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
apply plugin: 'kotlin-platform-common'
|
apply plugin: 'kotlin-platform-common'
|
||||||
|
|
||||||
dependencies {
|
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) {
|
val target: KotlinJsTargetDsl = when (compilerOrDefault) {
|
||||||
KotlinJsCompilerType.LEGACY -> legacyPreset
|
KotlinJsCompilerType.LEGACY -> legacyPreset
|
||||||
.also {
|
.also {
|
||||||
it.mixedMode = false
|
it.irPreset = null
|
||||||
}
|
}
|
||||||
.createTarget("js")
|
.createTarget("js")
|
||||||
|
|
||||||
KotlinJsCompilerType.IR -> irPreset
|
KotlinJsCompilerType.IR -> irPreset
|
||||||
.also {
|
.also {
|
||||||
it.legacyPreset = null
|
it.mixedMode = false
|
||||||
}
|
}
|
||||||
.createTarget("js")
|
.createTarget("js")
|
||||||
|
|
||||||
KotlinJsCompilerType.BOTH -> irPreset
|
KotlinJsCompilerType.BOTH -> legacyPreset
|
||||||
.also {
|
.also {
|
||||||
legacyPreset.mixedMode = true
|
irPreset.mixedMode = true
|
||||||
it.legacyPreset = legacyPreset
|
it.irPreset = irPreset
|
||||||
}
|
}
|
||||||
.createTarget(
|
.createTarget(
|
||||||
lowerCamelCaseName(
|
lowerCamelCaseName(
|
||||||
"js",
|
"js",
|
||||||
IR.lowerName
|
LEGACY.lowerName
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-6
@@ -106,7 +106,7 @@ private fun KotlinTargetContainerWithJsPresetFunctions.jsInternal(
|
|||||||
presets.getByName(
|
presets.getByName(
|
||||||
lowerCamelCaseName(
|
lowerCamelCaseName(
|
||||||
"js",
|
"js",
|
||||||
if (compilerOrDefault == KotlinJsCompilerType.IR) null else compilerOrDefault.lowerName
|
if (compilerOrDefault == KotlinJsCompilerType.LEGACY) null else compilerOrDefault.lowerName
|
||||||
)
|
)
|
||||||
) as KotlinTargetPreset<KotlinJsTargetDsl>,
|
) as KotlinTargetPreset<KotlinJsTargetDsl>,
|
||||||
configure
|
configure
|
||||||
@@ -116,8 +116,8 @@ private fun KotlinTargetContainerWithJsPresetFunctions.jsInternal(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Try to find existing target with exact name
|
// Try to find existing target with exact name
|
||||||
// and removed suffix IR in case when current compiler is BOTH
|
// and with append suffix Legacy in case when compiler for found target is BOTH,
|
||||||
// and with append suffix IR in case when compiler for found target is not BOTH
|
// and removed suffix Legacy in case when current compiler is BOTH
|
||||||
private fun KotlinTargetContainerWithJsPresetFunctions.getExistingTarget(
|
private fun KotlinTargetContainerWithJsPresetFunctions.getExistingTarget(
|
||||||
name: String,
|
name: String,
|
||||||
compiler: KotlinJsCompilerType?
|
compiler: KotlinJsCompilerType?
|
||||||
@@ -142,13 +142,13 @@ private fun KotlinTargetContainerWithJsPresetFunctions.getExistingTarget(
|
|||||||
val targetNameCandidate = getTargetName(name, compiler)
|
val targetNameCandidate = getTargetName(name, compiler)
|
||||||
|
|
||||||
return targets.findByName(targetNameCandidate) as KotlinJsTargetDsl?
|
return targets.findByName(targetNameCandidate) as KotlinJsTargetDsl?
|
||||||
?: getPreviousTarget(targetNameCandidate.removeJsCompilerSuffix(KotlinJsCompilerType.IR), true)
|
?: getPreviousTarget(targetNameCandidate.removeJsCompilerSuffix(KotlinJsCompilerType.LEGACY), true)
|
||||||
?: getPreviousTarget(lowerCamelCaseName(targetNameCandidate, KotlinJsCompilerType.IR.lowerName), false)
|
?: getPreviousTarget(lowerCamelCaseName(targetNameCandidate, KotlinJsCompilerType.LEGACY.lowerName), false)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getTargetName(name: String, compiler: KotlinJsCompilerType?): String {
|
private fun getTargetName(name: String, compiler: KotlinJsCompilerType?): String {
|
||||||
return lowerCamelCaseName(
|
return lowerCamelCaseName(
|
||||||
name,
|
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) {
|
fun setupDefaultPresets(project: Project) {
|
||||||
with(project.multiplatformExtension.presets) {
|
with(project.multiplatformExtension.presets) {
|
||||||
add(KotlinJvmTargetPreset(project))
|
add(KotlinJvmTargetPreset(project))
|
||||||
add(KotlinJsTargetPreset(project).apply { mixedMode = false })
|
add(KotlinJsTargetPreset(project).apply { irPreset = null })
|
||||||
add(KotlinJsIrTargetPreset(project))
|
add(KotlinJsIrTargetPreset(project).apply { mixedMode = false })
|
||||||
add(
|
add(
|
||||||
KotlinJsIrTargetPreset(project).apply {
|
KotlinJsTargetPreset(project).apply {
|
||||||
legacyPreset = KotlinJsTargetPreset(project).apply { mixedMode = true }
|
irPreset = KotlinJsIrTargetPreset(project).apply { mixedMode = true }
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
add(KotlinWasmTargetPreset(project))
|
add(KotlinWasmTargetPreset(project))
|
||||||
|
|||||||
+4
-3
@@ -136,11 +136,12 @@ internal class DefaultKotlinSourceSetFactory(
|
|||||||
if (sourceSet in notOnlyJsSourceSets) return
|
if (sourceSet in notOnlyJsSourceSets) return
|
||||||
|
|
||||||
fun chooseCompilerAttribute(target: KotlinTarget): KotlinJsCompilerAttribute {
|
fun chooseCompilerAttribute(target: KotlinTarget): KotlinJsCompilerAttribute {
|
||||||
if (target is KotlinJsTarget) {
|
if (target is KotlinJsIrTarget) {
|
||||||
return KotlinJsCompilerAttribute.legacy
|
return KotlinJsCompilerAttribute.ir
|
||||||
}
|
}
|
||||||
|
|
||||||
return KotlinJsCompilerAttribute.ir
|
target as KotlinJsTarget
|
||||||
|
return if (target.irTarget != null) KotlinJsCompilerAttribute.ir else KotlinJsCompilerAttribute.legacy
|
||||||
}
|
}
|
||||||
|
|
||||||
project.kotlinExtension.targets
|
project.kotlinExtension.targets
|
||||||
|
|||||||
+1
-1
@@ -32,7 +32,7 @@ abstract class KotlinJsCompilation @Inject internal constructor(
|
|||||||
final override val compilerOptions: HasCompilerOptions<KotlinJsCompilerOptions>
|
final override val compilerOptions: HasCompilerOptions<KotlinJsCompilerOptions>
|
||||||
get() = super.compilerOptions as HasCompilerOptions<KotlinJsCompilerOptions>
|
get() = super.compilerOptions as HasCompilerOptions<KotlinJsCompilerOptions>
|
||||||
|
|
||||||
val binaries: KotlinJsBinaryContainer =
|
internal val binaries: KotlinJsBinaryContainer =
|
||||||
target.project.objects.newInstance(
|
target.project.objects.newInstance(
|
||||||
KotlinJsBinaryContainer::class.java,
|
KotlinJsBinaryContainer::class.java,
|
||||||
target,
|
target,
|
||||||
|
|||||||
+1
-1
@@ -16,7 +16,7 @@ class KotlinJsCompilationFactory(
|
|||||||
get() = KotlinJsCompilation::class.java
|
get() = KotlinJsCompilation::class.java
|
||||||
|
|
||||||
override fun defaultSourceSetName(compilationName: String): String {
|
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
|
target.disambiguationClassifierInPlatform
|
||||||
else target.disambiguationClassifier
|
else target.disambiguationClassifier
|
||||||
|
|
||||||
|
|||||||
+50
-11
@@ -34,8 +34,7 @@ abstract class KotlinJsTarget
|
|||||||
@Inject
|
@Inject
|
||||||
constructor(
|
constructor(
|
||||||
project: Project,
|
project: Project,
|
||||||
platformType: KotlinPlatformType,
|
platformType: KotlinPlatformType
|
||||||
internal val mixedMode: Boolean
|
|
||||||
) :
|
) :
|
||||||
KotlinTargetWithBinaries<KotlinJsCompilation, KotlinJsBinaryContainer>(project, platformType),
|
KotlinTargetWithBinaries<KotlinJsCompilation, KotlinJsBinaryContainer>(project, platformType),
|
||||||
KotlinTargetWithTests<JsAggregatingExecutionSource, KotlinJsReportAggregatingTestRun>,
|
KotlinTargetWithTests<JsAggregatingExecutionSource, KotlinJsReportAggregatingTestRun>,
|
||||||
@@ -54,24 +53,46 @@ constructor(
|
|||||||
|
|
||||||
internal val commonFakeApiElementsConfigurationName: String
|
internal val commonFakeApiElementsConfigurationName: String
|
||||||
get() = lowerCamelCaseName(
|
get() = lowerCamelCaseName(
|
||||||
if (mixedMode)
|
irTarget?.let {
|
||||||
disambiguationClassifierInPlatform
|
this.disambiguationClassifierInPlatform
|
||||||
else
|
} ?: disambiguationClassifier,
|
||||||
disambiguationClassifier,
|
|
||||||
"commonFakeApiElements"
|
"commonFakeApiElements"
|
||||||
)
|
)
|
||||||
|
|
||||||
val disambiguationClassifierInPlatform: String?
|
val disambiguationClassifierInPlatform: String?
|
||||||
get() = if (mixedMode) {
|
get() = if (irTarget != null) {
|
||||||
disambiguationClassifier?.removeJsCompilerSuffix(KotlinJsCompilerType.LEGACY)
|
disambiguationClassifier?.removeJsCompilerSuffix(LEGACY)
|
||||||
} else {
|
} else {
|
||||||
disambiguationClassifier
|
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> {
|
override fun createUsageContexts(producingCompilation: KotlinCompilation<*>): Set<DefaultKotlinUsageContext> {
|
||||||
val usageContexts = super.createUsageContexts(producingCompilation)
|
val usageContexts = super.createUsageContexts(producingCompilation)
|
||||||
|
|
||||||
if (isMpp!! || mixedMode) return usageContexts
|
if (isMpp!!) return usageContexts
|
||||||
|
|
||||||
return usageContexts +
|
return usageContexts +
|
||||||
DefaultKotlinUsageContext(
|
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
|
override val binaries: KotlinJsBinaryContainer
|
||||||
get() = compilations.withType(KotlinJsCompilation::class.java)
|
get() = compilations.withType(KotlinJsCompilation::class.java)
|
||||||
.named(MAIN_COMPILATION_NAME)
|
.named(MAIN_COMPILATION_NAME)
|
||||||
.map { it.binaries }
|
.map { it.binaries }
|
||||||
.get()
|
.get()
|
||||||
|
|
||||||
|
var irTarget: KotlinJsIrTarget? = null
|
||||||
|
internal set
|
||||||
|
|
||||||
open var isMpp: Boolean? = null
|
open var isMpp: Boolean? = null
|
||||||
internal set
|
internal set
|
||||||
|
|
||||||
@@ -108,7 +144,7 @@ constructor(
|
|||||||
project.objects.newInstance(KotlinBrowserJs::class.java, this).also {
|
project.objects.newInstance(KotlinBrowserJs::class.java, this).also {
|
||||||
it.configure()
|
it.configure()
|
||||||
|
|
||||||
if (propertiesProvider.jsGenerateExecutableDefault && !mixedMode) {
|
if (propertiesProvider.jsGenerateExecutableDefault && irTarget == null) {
|
||||||
binaries.executable()
|
binaries.executable()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,6 +164,7 @@ constructor(
|
|||||||
|
|
||||||
override fun browser(body: KotlinJsBrowserDsl.() -> Unit) {
|
override fun browser(body: KotlinJsBrowserDsl.() -> Unit) {
|
||||||
body(browser)
|
body(browser)
|
||||||
|
irTarget?.browser(body)
|
||||||
}
|
}
|
||||||
|
|
||||||
//node.js
|
//node.js
|
||||||
@@ -135,7 +172,7 @@ constructor(
|
|||||||
project.objects.newInstance(KotlinNodeJs::class.java, this).also {
|
project.objects.newInstance(KotlinNodeJs::class.java, this).also {
|
||||||
it.configure()
|
it.configure()
|
||||||
|
|
||||||
if (propertiesProvider.jsGenerateExecutableDefault && !mixedMode) {
|
if (propertiesProvider.jsGenerateExecutableDefault && irTarget == null) {
|
||||||
binaries.executable()
|
binaries.executable()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,6 +193,7 @@ constructor(
|
|||||||
|
|
||||||
override fun nodejs(body: KotlinJsNodeDsl.() -> Unit) {
|
override fun nodejs(body: KotlinJsNodeDsl.() -> Unit) {
|
||||||
body(nodejs)
|
body(nodejs)
|
||||||
|
irTarget?.nodejs(body)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun whenBrowserConfigured(body: KotlinJsBrowserDsl.() -> Unit) {
|
override fun whenBrowserConfigured(body: KotlinJsBrowserDsl.() -> Unit) {
|
||||||
@@ -182,6 +220,7 @@ constructor(
|
|||||||
sourceMapEmbedSources = null
|
sourceMapEmbedSources = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
irTarget?.useCommonJs()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun useEsModules() {
|
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.plugin.statistics.KotlinBuildStatsService
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget
|
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTargetConfigurator
|
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.targets.js.ir.KotlinJsIrTargetPreset
|
||||||
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
||||||
import org.jetbrains.kotlin.gradle.utils.runProjectConfigurationHealthCheckWhenEvaluated
|
import org.jetbrains.kotlin.gradle.utils.runProjectConfigurationHealthCheckWhenEvaluated
|
||||||
@@ -27,7 +26,8 @@ open class KotlinJsTargetPreset(
|
|||||||
) : KotlinOnlyTargetPreset<KotlinJsTarget, KotlinJsCompilation>(
|
) : KotlinOnlyTargetPreset<KotlinJsTarget, KotlinJsCompilation>(
|
||||||
project
|
project
|
||||||
) {
|
) {
|
||||||
var mixedMode: Boolean? = null
|
var irPreset: KotlinJsIrTargetPreset? = null
|
||||||
|
internal set
|
||||||
|
|
||||||
open val isMpp: Boolean
|
open val isMpp: Boolean
|
||||||
get() = true
|
get() = true
|
||||||
@@ -35,20 +35,33 @@ open class KotlinJsTargetPreset(
|
|||||||
override val platformType: KotlinPlatformType
|
override val platformType: KotlinPlatformType
|
||||||
get() = KotlinPlatformType.js
|
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 {
|
override fun instantiateTarget(name: String): KotlinJsTarget {
|
||||||
return project.objects.newInstance(
|
return project.objects.newInstance(
|
||||||
KotlinJsTarget::class.java,
|
KotlinJsTarget::class.java,
|
||||||
project,
|
project,
|
||||||
platformType,
|
platformType
|
||||||
mixedMode
|
|
||||||
).apply {
|
).apply {
|
||||||
|
this.irTarget = irPreset?.createTarget(
|
||||||
|
lowerCamelCaseName(
|
||||||
|
name.removeJsCompilerSuffix(KotlinJsCompilerType.LEGACY),
|
||||||
|
KotlinJsCompilerType.IR.lowerName
|
||||||
|
)
|
||||||
|
)?.also {
|
||||||
|
it.legacyTarget = this
|
||||||
|
}
|
||||||
this.isMpp = this@KotlinJsTargetPreset.isMpp
|
this.isMpp = this@KotlinJsTargetPreset.isMpp
|
||||||
|
|
||||||
if (!mixedMode) {
|
project.runProjectConfigurationHealthCheckWhenEvaluated {
|
||||||
project.runProjectConfigurationHealthCheckWhenEvaluated {
|
if (!isBrowserConfigured && !isNodejsConfigured) {
|
||||||
if (!isBrowserConfigured && !isNodejsConfigured) {
|
project.logger.warn(
|
||||||
project.logger.warn(
|
"""
|
||||||
"""
|
|
||||||
Please choose a JavaScript environment to build distributions and run tests.
|
Please choose a JavaScript environment to build distributions and run tests.
|
||||||
Not choosing any of them will be an error in the future releases.
|
Not choosing any of them will be an error in the future releases.
|
||||||
kotlin {
|
kotlin {
|
||||||
@@ -59,23 +72,37 @@ open class KotlinJsTargetPreset(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
""".trimIndent()
|
""".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 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 {
|
override fun createTarget(name: String): KotlinJsTarget {
|
||||||
val result = super.createTarget(name)
|
val result = super.createTarget(name)
|
||||||
if (project.hasKpmModel) {
|
if (project.hasKpmModel) {
|
||||||
@@ -83,19 +110,6 @@ open class KotlinJsTargetPreset(
|
|||||||
}
|
}
|
||||||
return result
|
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(
|
class KotlinJsSingleTargetPreset(
|
||||||
@@ -106,14 +120,15 @@ class KotlinJsSingleTargetPreset(
|
|||||||
override val isMpp: Boolean
|
override val isMpp: Boolean
|
||||||
get() = false
|
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:
|
// 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? =
|
override fun provideTargetDisambiguationClassifier(target: KotlinOnlyTarget<KotlinJsCompilation>): String? =
|
||||||
if (mixedMode!!) {
|
irPreset?.let {
|
||||||
super.provideTargetDisambiguationClassifier(target)
|
super.provideTargetDisambiguationClassifier(target)
|
||||||
?.removePrefix(target.name.removeJsCompilerSuffix(KotlinJsCompilerType.LEGACY))
|
?.removePrefix(target.name.removeJsCompilerSuffix(KotlinJsCompilerType.LEGACY))
|
||||||
?.decapitalize()
|
?.decapitalize()
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createKotlinTargetConfigurator() = KotlinJsTargetConfigurator()
|
override fun createKotlinTargetConfigurator() = KotlinJsTargetConfigurator()
|
||||||
|
|||||||
+3
-3
@@ -11,9 +11,9 @@ import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
|
|||||||
|
|
||||||
fun KotlinJsTargetDsl.calculateJsCompilerType(): KotlinJsCompilerType {
|
fun KotlinJsTargetDsl.calculateJsCompilerType(): KotlinJsCompilerType {
|
||||||
return when {
|
return when {
|
||||||
this is KotlinJsTarget && !this.mixedMode -> KotlinJsCompilerType.LEGACY
|
this is KotlinJsTarget && this.irTarget == null -> KotlinJsCompilerType.LEGACY
|
||||||
this is KotlinJsIrTarget && this.legacyTarget == null -> KotlinJsCompilerType.IR
|
this is KotlinJsIrTarget && !this.mixedMode -> KotlinJsCompilerType.IR
|
||||||
this is KotlinJsIrTarget && this.legacyTarget != null -> KotlinJsCompilerType.BOTH
|
this is KotlinJsTarget && this.irTarget != null -> KotlinJsCompilerType.BOTH
|
||||||
else -> throw IllegalStateException("Unable to find previous Kotlin/JS compiler type for $this")
|
else -> throw IllegalStateException("Unable to find previous Kotlin/JS compiler type for $this")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+3
-3
@@ -68,9 +68,6 @@ constructor(
|
|||||||
compilation: KotlinJsCompilation = defaultCompilation
|
compilation: KotlinJsCompilation = defaultCompilation
|
||||||
): List<JsBinary> {
|
): List<JsBinary> {
|
||||||
if (target is KotlinJsIrTarget) {
|
if (target is KotlinJsIrTarget) {
|
||||||
target.legacyTarget
|
|
||||||
?.let { throw IllegalStateException("Can't use `executable()` with 'both' compiler type") }
|
|
||||||
|
|
||||||
target.whenBrowserConfigured {
|
target.whenBrowserConfigured {
|
||||||
(this as KotlinJsIrSubTarget).produceExecutable()
|
(this as KotlinJsIrSubTarget).produceExecutable()
|
||||||
}
|
}
|
||||||
@@ -87,6 +84,9 @@ constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (target is KotlinJsTarget) {
|
if (target is KotlinJsTarget) {
|
||||||
|
target.irTarget
|
||||||
|
?.let { throw IllegalStateException("Can't use `executable()` with 'both' compiler type") }
|
||||||
|
|
||||||
target.whenBrowserConfigured {
|
target.whenBrowserConfigured {
|
||||||
(this as KotlinJsSubTarget).produceExecutable()
|
(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.JsIrCompilationDetails
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinCompilationFactory
|
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.plugin.mpp.getOrCreateDefaultSourceSet
|
||||||
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
||||||
|
|
||||||
@@ -19,7 +18,7 @@ class KotlinJsIrCompilationFactory(
|
|||||||
|
|
||||||
override fun defaultSourceSetName(compilationName: String): String {
|
override fun defaultSourceSetName(compilationName: String): String {
|
||||||
return lowerCamelCaseName(
|
return lowerCamelCaseName(
|
||||||
if (target.legacyTarget != null)
|
if (target.mixedMode)
|
||||||
target.disambiguationClassifierInPlatform
|
target.disambiguationClassifierInPlatform
|
||||||
else
|
else
|
||||||
target.disambiguationClassifier,
|
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.gradle.utils.toHexString
|
||||||
import org.jetbrains.kotlin.statistics.metrics.BooleanMetrics
|
import org.jetbrains.kotlin.statistics.metrics.BooleanMetrics
|
||||||
import org.jetbrains.kotlin.statistics.metrics.StringMetrics
|
import org.jetbrains.kotlin.statistics.metrics.StringMetrics
|
||||||
import org.jetbrains.kotlin.utils.tryConstructClassFromStringArgs
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.nio.charset.StandardCharsets
|
import java.nio.charset.StandardCharsets
|
||||||
import java.security.MessageDigest
|
import java.security.MessageDigest
|
||||||
@@ -95,7 +94,7 @@ abstract class KotlinJsIrLink @Inject constructor(
|
|||||||
@get:IgnoreEmptyDirectories
|
@get:IgnoreEmptyDirectories
|
||||||
@get:NormalizeLineEndings
|
@get:NormalizeLineEndings
|
||||||
@get:InputDirectory
|
@get:InputDirectory
|
||||||
@get:PathSensitive(PathSensitivity.NONE)
|
@get:PathSensitive(PathSensitivity.RELATIVE)
|
||||||
internal abstract val entryModule: DirectoryProperty
|
internal abstract val entryModule: DirectoryProperty
|
||||||
|
|
||||||
@get:Internal
|
@get:Internal
|
||||||
|
|||||||
+7
-48
@@ -11,15 +11,11 @@ import org.gradle.api.Task
|
|||||||
import org.gradle.api.tasks.Copy
|
import org.gradle.api.tasks.Copy
|
||||||
import org.gradle.api.tasks.TaskProvider
|
import org.gradle.api.tasks.TaskProvider
|
||||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJsOptions
|
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.*
|
||||||
import org.jetbrains.kotlin.gradle.plugin.AbstractKotlinTargetConfigurator.Companion.runTaskNameSuffix
|
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.KotlinCompilation.Companion.MAIN_COMPILATION_NAME
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.DefaultKotlinUsageContext
|
import org.jetbrains.kotlin.gradle.plugin.mpp.DefaultKotlinUsageContext
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinTargetWithBinaries
|
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.JsAggregatingExecutionSource
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsReportAggregatingTestRun
|
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsReportAggregatingTestRun
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget
|
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.targets.js.typescript.TypeScriptValidationTask
|
||||||
import org.jetbrains.kotlin.gradle.tasks.locateOrRegisterTask
|
import org.jetbrains.kotlin.gradle.tasks.locateOrRegisterTask
|
||||||
import org.jetbrains.kotlin.gradle.tasks.registerTask
|
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.lowerCamelCaseName
|
||||||
import org.jetbrains.kotlin.gradle.utils.setProperty
|
import org.jetbrains.kotlin.gradle.utils.setProperty
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@@ -40,6 +35,7 @@ abstract class KotlinJsIrTarget
|
|||||||
constructor(
|
constructor(
|
||||||
project: Project,
|
project: Project,
|
||||||
platformType: KotlinPlatformType,
|
platformType: KotlinPlatformType,
|
||||||
|
internal val mixedMode: Boolean
|
||||||
) :
|
) :
|
||||||
KotlinTargetWithBinaries<KotlinJsIrCompilation, KotlinJsBinaryContainer>(project, platformType),
|
KotlinTargetWithBinaries<KotlinJsIrCompilation, KotlinJsBinaryContainer>(project, platformType),
|
||||||
KotlinTargetWithTests<JsAggregatingExecutionSource, KotlinJsReportAggregatingTestRun>,
|
KotlinTargetWithTests<JsAggregatingExecutionSource, KotlinJsReportAggregatingTestRun>,
|
||||||
@@ -65,33 +61,10 @@ constructor(
|
|||||||
field = value
|
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> {
|
override fun createUsageContexts(producingCompilation: KotlinCompilation<*>): Set<DefaultKotlinUsageContext> {
|
||||||
val usageContexts = super.createUsageContexts(producingCompilation)
|
val usageContexts = super.createUsageContexts(producingCompilation)
|
||||||
|
|
||||||
if (isMpp!!) return usageContexts
|
if (isMpp!! || mixedMode) return usageContexts
|
||||||
|
|
||||||
return usageContexts +
|
return usageContexts +
|
||||||
DefaultKotlinUsageContext(
|
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
|
internal val commonFakeApiElementsConfigurationName: String
|
||||||
get() = lowerCamelCaseName(
|
get() = lowerCamelCaseName(
|
||||||
legacyTarget?.let {
|
if (mixedMode)
|
||||||
this.disambiguationClassifierInPlatform
|
disambiguationClassifierInPlatform
|
||||||
} ?: disambiguationClassifier,
|
else
|
||||||
|
disambiguationClassifier,
|
||||||
"commonFakeApiElements"
|
"commonFakeApiElements"
|
||||||
)
|
)
|
||||||
|
|
||||||
val disambiguationClassifierInPlatform: String?
|
val disambiguationClassifierInPlatform: String?
|
||||||
get() = if (legacyTarget != null) {
|
get() = if (mixedMode) {
|
||||||
disambiguationClassifier?.removeJsCompilerSuffix(KotlinJsCompilerType.IR)
|
disambiguationClassifier?.removeJsCompilerSuffix(KotlinJsCompilerType.IR)
|
||||||
} else {
|
} else {
|
||||||
disambiguationClassifier
|
disambiguationClassifier
|
||||||
@@ -256,7 +218,6 @@ constructor(
|
|||||||
|
|
||||||
override fun browser(body: KotlinJsBrowserDsl.() -> Unit) {
|
override fun browser(body: KotlinJsBrowserDsl.() -> Unit) {
|
||||||
body(browser)
|
body(browser)
|
||||||
legacyTarget?.browser(body)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//node.js
|
//node.js
|
||||||
@@ -281,7 +242,6 @@ constructor(
|
|||||||
|
|
||||||
override fun nodejs(body: KotlinJsNodeDsl.() -> Unit) {
|
override fun nodejs(body: KotlinJsNodeDsl.() -> Unit) {
|
||||||
body(nodejs)
|
body(nodejs)
|
||||||
legacyTarget?.nodejs(body)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//d8
|
//d8
|
||||||
@@ -349,7 +309,6 @@ constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
legacyTarget?.useCommonJs()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun useEsModules() {
|
override fun useEsModules() {
|
||||||
|
|||||||
+34
-44
@@ -7,7 +7,9 @@ package org.jetbrains.kotlin.gradle.targets.js.ir
|
|||||||
|
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
import org.jetbrains.kotlin.gradle.plugin.*
|
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.PublicationRegistrationMode
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.hasKpmModel
|
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.hasKpmModel
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.mapTargetCompilationsToKpmVariants
|
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.mapTargetCompilationsToKpmVariants
|
||||||
@@ -21,34 +23,21 @@ open class KotlinJsIrTargetPreset(
|
|||||||
) : KotlinOnlyTargetPreset<KotlinJsIrTarget, KotlinJsIrCompilation>(
|
) : KotlinOnlyTargetPreset<KotlinJsIrTarget, KotlinJsIrCompilation>(
|
||||||
project
|
project
|
||||||
) {
|
) {
|
||||||
internal var legacyPreset: KotlinJsTargetPreset? = null
|
internal var mixedMode: Boolean? = null
|
||||||
internal set
|
|
||||||
|
|
||||||
open val isMpp: Boolean
|
open val isMpp: Boolean
|
||||||
get() = true
|
get() = true
|
||||||
|
|
||||||
override val platformType: KotlinPlatformType = KotlinPlatformType.js
|
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 {
|
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.isMpp = this@KotlinJsIrTargetPreset.isMpp
|
||||||
this.legacyTarget = legacyPreset?.createTarget(
|
if (!mixedMode) {
|
||||||
lowerCamelCaseName(
|
project.runProjectConfigurationHealthCheckWhenEvaluated {
|
||||||
name.removeJsCompilerSuffix(KotlinJsCompilerType.IR),
|
if (!isBrowserConfigured && !isNodejsConfigured) {
|
||||||
KotlinJsCompilerType.LEGACY.lowerName
|
project.logger.warn(
|
||||||
)
|
"""
|
||||||
)
|
|
||||||
project.runProjectConfigurationHealthCheckWhenEvaluated {
|
|
||||||
if (!isBrowserConfigured && !isNodejsConfigured) {
|
|
||||||
project.logger.warn(
|
|
||||||
"""
|
|
||||||
Please choose a JavaScript environment to build distributions and run tests.
|
Please choose a JavaScript environment to build distributions and run tests.
|
||||||
Not choosing any of them will be an error in the future releases.
|
Not choosing any of them will be an error in the future releases.
|
||||||
kotlin {
|
kotlin {
|
||||||
@@ -59,16 +48,17 @@ open class KotlinJsIrTargetPreset(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
""".trimIndent()
|
""".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
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getName(): String = lowerCamelCaseName(
|
override fun getName(): String = JS_PRESET_NAME
|
||||||
PRESET_NAME,
|
|
||||||
legacyPreset?.let { KotlinJsCompilerType.BOTH.lowerName }
|
|
||||||
)
|
|
||||||
|
|
||||||
override fun createCompilationFactory(
|
//TODO[Ilya Goncharov] remove public morozov
|
||||||
|
public override fun createCompilationFactory(
|
||||||
forTarget: KotlinJsIrTarget
|
forTarget: KotlinJsIrTarget
|
||||||
): KotlinCompilationFactory<KotlinJsIrCompilation> {
|
): KotlinCompilationFactory<KotlinJsIrCompilation> =
|
||||||
return KotlinJsIrCompilationFactory(forTarget)
|
KotlinJsIrCompilationFactory(forTarget)
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
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
|
override val isMpp: Boolean
|
||||||
get() = false
|
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:
|
// 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? =
|
override fun provideTargetDisambiguationClassifier(target: KotlinOnlyTarget<KotlinJsIrCompilation>): String? {
|
||||||
legacyPreset?.let {
|
return if (mixedMode!!) {
|
||||||
super.provideTargetDisambiguationClassifier(target)
|
super.provideTargetDisambiguationClassifier(target)
|
||||||
?.removePrefix(target.name.removeJsCompilerSuffix(KotlinJsCompilerType.IR))
|
?.removePrefix(target.name.removeJsCompilerSuffix(KotlinJsCompilerType.IR))
|
||||||
?.decapitalize()
|
?.decapitalize()
|
||||||
|
} else {
|
||||||
|
null
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun createKotlinTargetConfigurator(): KotlinOnlyTargetConfigurator<KotlinJsIrCompilation, KotlinJsIrTarget> =
|
override fun createKotlinTargetConfigurator(): KotlinOnlyTargetConfigurator<KotlinJsIrCompilation, KotlinJsIrTarget> =
|
||||||
KotlinJsIrTargetConfigurator()
|
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.")
|
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
|
irTarget.isMpp = true
|
||||||
|
|
||||||
project.runProjectConfigurationHealthCheckWhenEvaluated {
|
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.mpp.KotlinJsCompilation
|
||||||
import org.jetbrains.kotlin.gradle.plugin.whenEvaluated
|
import org.jetbrains.kotlin.gradle.plugin.whenEvaluated
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget
|
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.RequiresNpmDependencies
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.resolved.KotlinProjectNpmResolution
|
import org.jetbrains.kotlin.gradle.targets.js.npm.resolved.KotlinProjectNpmResolution
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
|
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
|
// Hack for mixed mode, when target is JS and contain JS-IR
|
||||||
if (target is KotlinJsIrTarget) {
|
if (target is KotlinJsTarget) {
|
||||||
target.legacyTarget?.compilations?.all { compilation ->
|
target.irTarget?.compilations?.all { compilation ->
|
||||||
if (compilation is KotlinJsCompilation) {
|
if (compilation is KotlinJsCompilation) {
|
||||||
addCompilation(compilation)
|
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.KotlinJsCompilerAttribute
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget
|
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
|
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.Test
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertNotNull
|
import kotlin.test.assertNotNull
|
||||||
@@ -134,8 +133,8 @@ class ConfigurationsTest : MultiplatformExtensionTest() {
|
|||||||
val project = buildProjectWithMPP {
|
val project = buildProjectWithMPP {
|
||||||
kotlin {
|
kotlin {
|
||||||
js(BOTH)
|
js(BOTH)
|
||||||
targets.withType<KotlinJsIrTarget> {
|
targets.withType<KotlinJsTarget> {
|
||||||
legacyTarget!!.compilations.getByName("main").dependencies {
|
irTarget!!.compilations.getByName("main").dependencies {
|
||||||
api("test:compilation-dependency")
|
api("test:compilation-dependency")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user