mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-04-01 15:51:52 +00:00
[Gradle, JS] Check only once set producing type
This commit is contained in:
@@ -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
|
||||
}
|
||||
@@ -69,6 +69,8 @@ constructor(
|
||||
}
|
||||
}
|
||||
|
||||
var producingType: KotlinJsProducingType? = null
|
||||
|
||||
var irTarget: KotlinJsIrTarget? = null
|
||||
|
||||
val testTaskName get() = testRuns.getByName(KotlinTargetWithTests.DEFAULT_TEST_RUN_NAME).testTaskName
|
||||
@@ -124,18 +126,27 @@ constructor(
|
||||
}
|
||||
|
||||
override fun produceKotlinLibrary() {
|
||||
produce {
|
||||
produce(KotlinJsProducingType.KOTLIN_LIBRARY) {
|
||||
produceKotlinLibrary()
|
||||
}
|
||||
}
|
||||
|
||||
override fun produceExecutable() {
|
||||
produce {
|
||||
produce(KotlinJsProducingType.EXECUTABLE) {
|
||||
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 {
|
||||
(this as KotlinJsSubTarget).producer()
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinTargetWithTests
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinOnlyTarget
|
||||
import org.jetbrains.kotlin.gradle.targets.js.JsIrAggregatingExecutionSource
|
||||
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.KotlinJsIrNodeDsl
|
||||
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>
|
||||
internal set
|
||||
|
||||
var producingType: KotlinJsProducingType? = null
|
||||
|
||||
val testTaskName get() = testRuns.getByName(KotlinTargetWithTests.DEFAULT_TEST_RUN_NAME).testTaskName
|
||||
val testTask: TaskProvider<KotlinTestReport>
|
||||
get() = checkNotNull(project.locateTask(testTaskName))
|
||||
@@ -83,18 +86,27 @@ open class KotlinJsIrTarget @Inject constructor(project: Project, platformType:
|
||||
}
|
||||
|
||||
override fun produceKotlinLibrary() {
|
||||
produce {
|
||||
produce(KotlinJsProducingType.KOTLIN_LIBRARY) {
|
||||
produceKotlinLibrary()
|
||||
}
|
||||
}
|
||||
|
||||
override fun produceExecutable() {
|
||||
produce {
|
||||
produce(KotlinJsProducingType.EXECUTABLE) {
|
||||
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 {
|
||||
(this as KotlinJsSubTarget).producer()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user