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