Revert "[Gradle, JS] binaries API instead of produce*"
This reverts commit 055e98e9
This commit is contained in:
+36
-19
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.gradle.targets.js
|
||||
import org.gradle.api.NamedDomainObjectContainer
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.tasks.TaskProvider
|
||||
import org.gradle.util.WrapUtil
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
|
||||
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
|
||||
import org.jetbrains.kotlin.gradle.plugin.*
|
||||
@@ -17,8 +16,8 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetComponent
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetWithTests
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinBinaryContainer
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinOnlyTarget
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.PRIMARY_SINGLE_COMPONENT_NAME
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsBrowserDsl
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsNodeDsl
|
||||
@@ -27,6 +26,7 @@ import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsTargetDsl
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.JsBinary
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.*
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.*
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.*
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsBinaryContainer
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
|
||||
import org.jetbrains.kotlin.gradle.targets.js.subtargets.KotlinBrowserJs
|
||||
@@ -45,7 +45,7 @@ constructor(
|
||||
project: Project,
|
||||
platformType: KotlinPlatformType
|
||||
) :
|
||||
KotlinBinaryContainer<KotlinJsCompilation, KotlinJsBinaryContainer>(project, platformType),
|
||||
KotlinOnlyTarget<KotlinJsCompilation>(project, platformType),
|
||||
KotlinTargetWithTests<JsAggregatingExecutionSource, KotlinJsReportAggregatingTestRun>,
|
||||
KotlinJsTargetDsl,
|
||||
KotlinJsSubTargetContainerDsl {
|
||||
@@ -90,23 +90,11 @@ constructor(
|
||||
}
|
||||
}
|
||||
|
||||
override val binaries: KotlinJsBinaryContainer =
|
||||
// Use newInstance to allow accessing binaries by their names in Groovy using the extension mechanism.
|
||||
project.objects.newInstance(
|
||||
KotlinJsBinaryContainer::class.java,
|
||||
this,
|
||||
WrapUtil.toDomainObjectSet(JsBinary::class.java).apply {
|
||||
all {
|
||||
whenBrowserConfigured {
|
||||
(this as KotlinJsSubTarget).produceExecutable()
|
||||
}
|
||||
var producingType: KotlinJsProducingType? = null
|
||||
|
||||
whenNodejsConfigured {
|
||||
(this as KotlinJsSubTarget).produceExecutable()
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
@Deprecated("Use produceExecutable instead", ReplaceWith("produceExecutable()"))
|
||||
override val binaries: KotlinJsBinaryContainer =
|
||||
throw IllegalStateException("binaries is useless for legacy compiler. Use produceExecutable instead")
|
||||
|
||||
var irTarget: KotlinJsIrTarget? = null
|
||||
|
||||
@@ -166,6 +154,35 @@ constructor(
|
||||
irTarget?.nodejs(body)
|
||||
}
|
||||
|
||||
override fun produceExecutable() {
|
||||
produce(KotlinJsProducingType.EXECUTABLE) {
|
||||
(this as KotlinJsSubTarget).produceExecutable()
|
||||
}
|
||||
}
|
||||
|
||||
private fun produce(
|
||||
producingType: KotlinJsProducingType,
|
||||
producer: KotlinJsSubTargetDsl.() -> Unit = {}
|
||||
) {
|
||||
check(this.producingType == null || this.producingType == producingType) {
|
||||
"Only one producing type supported. Try to set $producingType but previously ${this.producingType} found"
|
||||
}
|
||||
|
||||
this.producingType = producingType
|
||||
|
||||
whenBrowserConfigured {
|
||||
if (this is KotlinBrowserJs) {
|
||||
producer()
|
||||
}
|
||||
}
|
||||
|
||||
whenNodejsConfigured {
|
||||
if (this is KotlinNodeJs) {
|
||||
producer()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun whenBrowserConfigured(body: KotlinJsBrowserDsl.() -> Unit) {
|
||||
if (browserLazyDelegate.isInitialized()) {
|
||||
browser(body)
|
||||
|
||||
+2
@@ -49,6 +49,8 @@ interface KotlinJsTargetDsl : KotlinTarget {
|
||||
}
|
||||
}
|
||||
|
||||
fun produceExecutable()
|
||||
|
||||
fun useCommonJs()
|
||||
|
||||
val binaries: KotlinJsBinaryContainer
|
||||
|
||||
+5
@@ -115,6 +115,11 @@ constructor(
|
||||
body(nodejs)
|
||||
}
|
||||
|
||||
@Deprecated("Use binaries.executable instead", ReplaceWith("binaries.executable()"))
|
||||
override fun produceExecutable() {
|
||||
project.logger.warn("produceExecutable configuration is useless with IR compiler")
|
||||
}
|
||||
|
||||
override fun whenBrowserConfigured(body: KotlinJsBrowserDsl.() -> Unit) {
|
||||
if (browserLazyDelegate.isInitialized()) {
|
||||
browser(body)
|
||||
|
||||
Reference in New Issue
Block a user