[Gradle, JS] Move producing dsl from subtarget to target
This commit is contained in:
+26
-6
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsNodeDsl
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsTargetDsl
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
|
||||
import org.jetbrains.kotlin.gradle.targets.js.subtargets.KotlinBrowserJs
|
||||
import org.jetbrains.kotlin.gradle.targets.js.subtargets.KotlinJsSubTarget
|
||||
import org.jetbrains.kotlin.gradle.targets.js.subtargets.KotlinNodeJs
|
||||
import org.jetbrains.kotlin.gradle.tasks.locateTask
|
||||
import org.jetbrains.kotlin.gradle.testing.internal.KotlinTestReport
|
||||
@@ -82,10 +83,10 @@ constructor(
|
||||
|
||||
private val browserLazyDelegate = lazy {
|
||||
project.objects.newInstance(KotlinBrowserJs::class.java, this).also {
|
||||
it.configure()
|
||||
|
||||
browserConfiguredHandlers.forEach { handler ->
|
||||
it.whenProducingConfigured {
|
||||
handler(this)
|
||||
}
|
||||
handler(it)
|
||||
}
|
||||
browserConfiguredHandlers.clear()
|
||||
}
|
||||
@@ -103,10 +104,9 @@ constructor(
|
||||
|
||||
private val nodejsLazyDelegate = lazy {
|
||||
project.objects.newInstance(KotlinNodeJs::class.java, this).also {
|
||||
it.configure()
|
||||
nodejsConfiguredHandlers.forEach { handler ->
|
||||
it.whenProducingConfigured {
|
||||
handler(this)
|
||||
}
|
||||
handler(it)
|
||||
}
|
||||
|
||||
nodejsConfiguredHandlers.clear()
|
||||
@@ -123,6 +123,26 @@ constructor(
|
||||
body(nodejs)
|
||||
}
|
||||
|
||||
override fun produceKotlinLibrary() {
|
||||
whenBrowserConfigured {
|
||||
(this as KotlinJsSubTarget).produceKotlinLibrary()
|
||||
}
|
||||
|
||||
whenNodejsConfigured {
|
||||
(this as KotlinJsSubTarget).produceKotlinLibrary()
|
||||
}
|
||||
}
|
||||
|
||||
override fun produceExecutable() {
|
||||
whenBrowserConfigured {
|
||||
(this as KotlinJsSubTarget).produceExecutable()
|
||||
}
|
||||
|
||||
whenNodejsConfigured {
|
||||
(this as KotlinJsSubTarget).produceExecutable()
|
||||
}
|
||||
}
|
||||
|
||||
fun whenBrowserConfigured(body: KotlinJsBrowserDsl.() -> Unit) {
|
||||
if (browserLazyDelegate.isInitialized()) {
|
||||
browser(body)
|
||||
|
||||
+4
-4
@@ -55,6 +55,10 @@ interface KotlinJsTargetDsl {
|
||||
}
|
||||
}
|
||||
|
||||
fun produceKotlinLibrary()
|
||||
|
||||
fun produceExecutable()
|
||||
|
||||
val testRuns: NamedDomainObjectContainer<KotlinJsReportAggregatingTestRun>
|
||||
}
|
||||
|
||||
@@ -66,10 +70,6 @@ interface KotlinJsSubTargetDsl {
|
||||
}
|
||||
}
|
||||
|
||||
fun produceKotlinLibrary()
|
||||
|
||||
fun produceExecutable()
|
||||
|
||||
val testRuns: NamedDomainObjectContainer<KotlinJsPlatformTestRun>
|
||||
}
|
||||
|
||||
|
||||
-15
@@ -53,13 +53,6 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
||||
target.irTarget?.browser?.produceExecutable()
|
||||
}
|
||||
|
||||
override fun configure() {
|
||||
super.configure()
|
||||
browserProducingConfiguredHandlers.forEach { handler ->
|
||||
handler(this)
|
||||
}
|
||||
}
|
||||
|
||||
override fun configureDefaultTestFramework(testTask: KotlinJsTest) {
|
||||
testTask.useKarma {
|
||||
useChromeHeadless()
|
||||
@@ -304,14 +297,6 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
||||
}
|
||||
}
|
||||
|
||||
fun whenProducingConfigured(body: KotlinBrowserJs.() -> Unit) {
|
||||
if (producingConfigured) {
|
||||
this.body()
|
||||
} else {
|
||||
browserProducingConfiguredHandlers += body
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val DCE_TASK_PREFIX = "processDce"
|
||||
const val DCE_TASK_SUFFIX = "kotlinJs"
|
||||
|
||||
+3
-11
@@ -37,23 +37,15 @@ abstract class KotlinJsSubTarget(
|
||||
final override lateinit var testRuns: NamedDomainObjectContainer<KotlinJsPlatformTestRun>
|
||||
private set
|
||||
|
||||
protected val producingConfigured: Boolean = false
|
||||
|
||||
protected val browserProducingConfiguredHandlers: MutableList<KotlinBrowserJs.() -> Unit> = mutableListOf()
|
||||
protected val nodejsProducingConfiguredHandlers: MutableList<KotlinNodeJs.() -> Unit> = mutableListOf()
|
||||
|
||||
override fun produceKotlinLibrary() {
|
||||
configure()
|
||||
internal open fun produceKotlinLibrary() {
|
||||
}
|
||||
|
||||
override fun produceExecutable() {
|
||||
configure()
|
||||
|
||||
internal open fun produceExecutable() {
|
||||
configureBuildVariants()
|
||||
configureMain()
|
||||
}
|
||||
|
||||
protected open fun configure() {
|
||||
internal open fun configure() {
|
||||
NpmResolverPlugin.apply(project)
|
||||
|
||||
configureTests()
|
||||
|
||||
-15
@@ -30,13 +30,6 @@ open class KotlinNodeJs @Inject constructor(target: KotlinJsTarget) :
|
||||
target.irTarget?.nodejs?.produceExecutable()
|
||||
}
|
||||
|
||||
override fun configure() {
|
||||
super.configure()
|
||||
nodejsProducingConfiguredHandlers.forEach { handler ->
|
||||
handler(this)
|
||||
}
|
||||
}
|
||||
|
||||
override fun runTask(body: NodeJsExec.() -> Unit) {
|
||||
(project.tasks.getByName(runTaskName) as NodeJsExec).body()
|
||||
}
|
||||
@@ -60,12 +53,4 @@ open class KotlinNodeJs @Inject constructor(target: KotlinJsTarget) :
|
||||
|
||||
override fun configureBuildVariants() {
|
||||
}
|
||||
|
||||
fun whenProducingConfigured(body: KotlinNodeJs.() -> Unit) {
|
||||
if (producingConfigured) {
|
||||
this.body()
|
||||
} else {
|
||||
nodejsProducingConfiguredHandlers += body
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user