[Gradle, JS] binaries API instead of produce*
This commit is contained in:
+1
-1
@@ -12,7 +12,7 @@ import org.gradle.util.ConfigureUtil
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
||||
|
||||
abstract class KotlinBinaryContainer<T : KotlinCompilation<*>, R : DomainObjectSet<*>>(
|
||||
abstract class KotlinBinaryContainer<T : KotlinCompilation<*>, out R : DomainObjectSet<*>>(
|
||||
project: Project,
|
||||
platformType: KotlinPlatformType
|
||||
) : KotlinOnlyTarget<T>(project, platformType) {
|
||||
|
||||
+31
-42
@@ -8,10 +8,23 @@ 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.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.AbstractKotlinTargetConfigurator.Companion.runTaskNameSuffix
|
||||
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.PRIMARY_SINGLE_COMPONENT_NAME
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsBrowserDsl
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsNodeDsl
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsSubTargetContainerDsl
|
||||
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.ir.KotlinJsBinaryContainer
|
||||
@@ -32,7 +45,7 @@ constructor(
|
||||
project: Project,
|
||||
platformType: KotlinPlatformType
|
||||
) :
|
||||
KotlinOnlyTarget<KotlinJsCompilation>(project, platformType),
|
||||
KotlinBinaryContainer<KotlinJsCompilation, KotlinJsBinaryContainer>(project, platformType),
|
||||
KotlinTargetWithTests<JsAggregatingExecutionSource, KotlinJsReportAggregatingTestRun>,
|
||||
KotlinJsTargetDsl,
|
||||
KotlinJsSubTargetContainerDsl {
|
||||
@@ -77,7 +90,23 @@ constructor(
|
||||
}
|
||||
}
|
||||
|
||||
var producingType: KotlinJsProducingType? = null
|
||||
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()
|
||||
}
|
||||
|
||||
whenNodejsConfigured {
|
||||
(this as KotlinJsSubTarget).produceExecutable()
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
var irTarget: KotlinJsIrTarget? = null
|
||||
|
||||
@@ -137,46 +166,6 @@ constructor(
|
||||
irTarget?.nodejs(body)
|
||||
}
|
||||
|
||||
override fun produceKotlinLibrary() {
|
||||
produce(KotlinJsProducingType.KOTLIN_LIBRARY)
|
||||
}
|
||||
|
||||
override fun produceExecutable() {
|
||||
produce(KotlinJsProducingType.EXECUTABLE) {
|
||||
(this as KotlinJsSubTarget).produceExecutable()
|
||||
}
|
||||
}
|
||||
|
||||
override val binaries: KotlinJsBinaryContainer
|
||||
get() = TODO("Not yet implemented")
|
||||
|
||||
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"
|
||||
}
|
||||
|
||||
if (this.producingType != null) {
|
||||
return
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
-4
@@ -49,10 +49,6 @@ interface KotlinJsTargetDsl : KotlinTarget {
|
||||
}
|
||||
}
|
||||
|
||||
fun produceKotlinLibrary()
|
||||
|
||||
fun produceExecutable()
|
||||
|
||||
fun useCommonJs()
|
||||
|
||||
val binaries: KotlinJsBinaryContainer
|
||||
|
||||
+3
-1
@@ -8,6 +8,8 @@ package org.jetbrains.kotlin.gradle.targets.js.ir
|
||||
import org.gradle.api.DomainObjectSet
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.plugins.ExtensionAware
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinBinaryContainer
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
||||
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -15,7 +17,7 @@ import javax.inject.Inject
|
||||
open class KotlinJsBinaryContainer
|
||||
@Inject
|
||||
constructor(
|
||||
val target: KotlinJsIrTarget,
|
||||
val target: KotlinBinaryContainer<KotlinJsCompilation, KotlinJsBinaryContainer>,
|
||||
backingContainer: DomainObjectSet<JsBinary>
|
||||
) : DomainObjectSet<JsBinary> by backingContainer {
|
||||
val project: Project
|
||||
|
||||
-8
@@ -115,14 +115,6 @@ constructor(
|
||||
body(nodejs)
|
||||
}
|
||||
|
||||
override fun produceKotlinLibrary() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
override fun produceExecutable() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
override fun whenBrowserConfigured(body: KotlinJsBrowserDsl.() -> Unit) {
|
||||
if (browserLazyDelegate.isInitialized()) {
|
||||
browser(body)
|
||||
|
||||
Reference in New Issue
Block a user