[Gradle, JS] Check only once set producing type
This commit is contained in:
+11
@@ -0,0 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.gradle.targets.js
|
||||||
|
|
||||||
|
enum class KotlinJsProducingType {
|
||||||
|
KOTLIN_LIBRARY,
|
||||||
|
EXECUTABLE
|
||||||
|
}
|
||||||
+14
-3
@@ -69,6 +69,8 @@ constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var producingType: KotlinJsProducingType? = null
|
||||||
|
|
||||||
var irTarget: KotlinJsIrTarget? = null
|
var irTarget: KotlinJsIrTarget? = null
|
||||||
|
|
||||||
val testTaskName get() = testRuns.getByName(KotlinTargetWithTests.DEFAULT_TEST_RUN_NAME).testTaskName
|
val testTaskName get() = testRuns.getByName(KotlinTargetWithTests.DEFAULT_TEST_RUN_NAME).testTaskName
|
||||||
@@ -124,18 +126,27 @@ constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun produceKotlinLibrary() {
|
override fun produceKotlinLibrary() {
|
||||||
produce {
|
produce(KotlinJsProducingType.KOTLIN_LIBRARY) {
|
||||||
produceKotlinLibrary()
|
produceKotlinLibrary()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun produceExecutable() {
|
override fun produceExecutable() {
|
||||||
produce {
|
produce(KotlinJsProducingType.EXECUTABLE) {
|
||||||
produceExecutable()
|
produceExecutable()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun produce(producer: KotlinJsSubTarget.() -> Unit) {
|
private fun produce(
|
||||||
|
producingType: KotlinJsProducingType,
|
||||||
|
producer: KotlinJsSubTarget.() -> 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 {
|
whenBrowserConfigured {
|
||||||
(this as KotlinJsSubTarget).producer()
|
(this as KotlinJsSubTarget).producer()
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-3
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinTargetWithTests
|
|||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinOnlyTarget
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinOnlyTarget
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.JsIrAggregatingExecutionSource
|
import org.jetbrains.kotlin.gradle.targets.js.JsIrAggregatingExecutionSource
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsIrReportAggregatingTestRun
|
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsIrReportAggregatingTestRun
|
||||||
|
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsProducingType
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsIrBrowserDsl
|
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsIrBrowserDsl
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsIrNodeDsl
|
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsIrNodeDsl
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsIrTargetDsl
|
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsIrTargetDsl
|
||||||
@@ -31,6 +32,8 @@ open class KotlinJsIrTarget @Inject constructor(project: Project, platformType:
|
|||||||
override lateinit var testRuns: NamedDomainObjectContainer<KotlinJsIrReportAggregatingTestRun>
|
override lateinit var testRuns: NamedDomainObjectContainer<KotlinJsIrReportAggregatingTestRun>
|
||||||
internal set
|
internal set
|
||||||
|
|
||||||
|
var producingType: KotlinJsProducingType? = null
|
||||||
|
|
||||||
val testTaskName get() = testRuns.getByName(KotlinTargetWithTests.DEFAULT_TEST_RUN_NAME).testTaskName
|
val testTaskName get() = testRuns.getByName(KotlinTargetWithTests.DEFAULT_TEST_RUN_NAME).testTaskName
|
||||||
val testTask: TaskProvider<KotlinTestReport>
|
val testTask: TaskProvider<KotlinTestReport>
|
||||||
get() = checkNotNull(project.locateTask(testTaskName))
|
get() = checkNotNull(project.locateTask(testTaskName))
|
||||||
@@ -83,18 +86,27 @@ open class KotlinJsIrTarget @Inject constructor(project: Project, platformType:
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun produceKotlinLibrary() {
|
override fun produceKotlinLibrary() {
|
||||||
produce {
|
produce(KotlinJsProducingType.KOTLIN_LIBRARY) {
|
||||||
produceKotlinLibrary()
|
produceKotlinLibrary()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun produceExecutable() {
|
override fun produceExecutable() {
|
||||||
produce {
|
produce(KotlinJsProducingType.EXECUTABLE) {
|
||||||
produceExecutable()
|
produceExecutable()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun produce(producer: KotlinJsSubTarget.() -> Unit) {
|
private fun produce(
|
||||||
|
producingType: KotlinJsProducingType,
|
||||||
|
producer: KotlinJsSubTarget.() -> 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 {
|
whenBrowserConfigured {
|
||||||
(this as KotlinJsSubTarget).producer()
|
(this as KotlinJsSubTarget).producer()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user