[Gradle, JS] Commonize targets with interfaces
This commit is contained in:
+19
-20
@@ -2,11 +2,10 @@ package org.jetbrains.kotlin.gradle.dsl
|
||||
|
||||
import groovy.lang.Closure
|
||||
import org.gradle.util.ConfigureUtil
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetPreset
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetsContainerWithPresets
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.*
|
||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTargetPreset
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsTargetDsl
|
||||
import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget
|
||||
|
||||
// DO NOT EDIT MANUALLY! Generated by org.jetbrains.kotlin.generators.gradle.dsl.MppPresetFunctionsCodegenKt
|
||||
@@ -30,11 +29,11 @@ interface KotlinTargetContainerWithPresetFunctions : KotlinTargetsContainerWithP
|
||||
|
||||
fun js(
|
||||
name: String = "js",
|
||||
configure: KotlinJsTarget.() -> Unit = { }
|
||||
): KotlinJsTarget =
|
||||
configure: KotlinJsTargetDsl.() -> Unit = { }
|
||||
): KotlinJsTargetDsl =
|
||||
configureOrCreate(
|
||||
name,
|
||||
presets.getByName("js") as KotlinJsTargetPreset,
|
||||
presets.getByName("js") as KotlinTargetPreset<KotlinJsTargetDsl>,
|
||||
configure
|
||||
)
|
||||
|
||||
@@ -43,20 +42,20 @@ interface KotlinTargetContainerWithPresetFunctions : KotlinTargetsContainerWithP
|
||||
fun js(name: String, configure: Closure<*>) = js(name) { ConfigureUtil.configure(configure, this) }
|
||||
fun js(configure: Closure<*>) = js { ConfigureUtil.configure(configure, this) }
|
||||
|
||||
fun jsIr(
|
||||
name: String = "jsIr",
|
||||
configure: KotlinJsIrTarget.() -> Unit = { }
|
||||
): KotlinJsIrTarget =
|
||||
configureOrCreate(
|
||||
name,
|
||||
presets.getByName("jsIr") as KotlinJsIrTargetPreset,
|
||||
configure
|
||||
)
|
||||
|
||||
fun jsIr() = jsIr("jsIr") { }
|
||||
fun jsIr(name: String) = jsIr(name) { }
|
||||
fun jsIr(name: String, configure: Closure<*>) = jsIr(name) { ConfigureUtil.configure(configure, this) }
|
||||
fun jsIr(configure: Closure<*>) = jsIr { ConfigureUtil.configure(configure, this) }
|
||||
// fun jsIr(
|
||||
// name: String = "jsIr",
|
||||
// configure: KotlinJsIrTarget.() -> Unit = { }
|
||||
// ): KotlinJsIrTarget =
|
||||
// configureOrCreate(
|
||||
// name,
|
||||
// presets.getByName("jsIr") as KotlinJsIrTargetPreset,
|
||||
// configure
|
||||
// )
|
||||
//
|
||||
// fun jsIr() = jsIr("jsIr") { }
|
||||
// fun jsIr(name: String) = jsIr(name) { }
|
||||
// fun jsIr(name: String, configure: Closure<*>) = jsIr(name) { ConfigureUtil.configure(configure, this) }
|
||||
// fun jsIr(configure: Closure<*>) = jsIr { ConfigureUtil.configure(configure, this) }
|
||||
|
||||
fun android(
|
||||
name: String = "android",
|
||||
|
||||
+10
-77
@@ -8,13 +8,11 @@ package org.jetbrains.kotlin.gradle.targets.js
|
||||
import org.jetbrains.kotlin.gradle.execution.KotlinAggregateExecutionSource
|
||||
import org.jetbrains.kotlin.gradle.plugin.CompilationExecutionSource
|
||||
import org.jetbrains.kotlin.gradle.plugin.CompilationExecutionSourceSupport
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetTestRun
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrCompilation
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrSubTarget
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTest
|
||||
import org.jetbrains.kotlin.gradle.targets.js.subtargets.KotlinJsSubTarget
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsSubTargetDsl
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsSubtargetContainerDsl
|
||||
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
|
||||
import org.jetbrains.kotlin.gradle.testing.KotlinReportAggregatingTestRun
|
||||
import org.jetbrains.kotlin.gradle.testing.KotlinTaskTestRun
|
||||
@@ -24,11 +22,8 @@ import kotlin.properties.Delegates
|
||||
class JsCompilationExecutionSource(override val compilation: KotlinJsCompilation) :
|
||||
CompilationExecutionSource<KotlinJsCompilation>
|
||||
|
||||
class JsIrCompilationExecutionSource(override val compilation: KotlinJsIrCompilation) :
|
||||
CompilationExecutionSource<KotlinJsIrCompilation>
|
||||
|
||||
open class KotlinJsPlatformTestRun(testRunName: String, subtarget: KotlinJsSubTarget) :
|
||||
KotlinTaskTestRun<JsCompilationExecutionSource, KotlinJsTest>(testRunName, subtarget.target),
|
||||
open class KotlinJsPlatformTestRun(testRunName: String, target: KotlinTarget) :
|
||||
KotlinTaskTestRun<JsCompilationExecutionSource, KotlinJsTest>(testRunName, target),
|
||||
CompilationExecutionSourceSupport<KotlinJsCompilation> {
|
||||
|
||||
private var _executionSource: JsCompilationExecutionSource by Delegates.notNull()
|
||||
@@ -47,26 +42,6 @@ open class KotlinJsPlatformTestRun(testRunName: String, subtarget: KotlinJsSubTa
|
||||
}
|
||||
}
|
||||
|
||||
open class KotlinJsIrPlatformTestRun(testRunName: String, subtarget: KotlinJsIrSubTarget) :
|
||||
KotlinTaskTestRun<JsIrCompilationExecutionSource, KotlinJsIrTest>(testRunName, subtarget.target),
|
||||
CompilationExecutionSourceSupport<KotlinJsIrCompilation> {
|
||||
|
||||
private var _executionSource: JsIrCompilationExecutionSource by Delegates.notNull()
|
||||
|
||||
final override var executionSource: JsIrCompilationExecutionSource
|
||||
get() = _executionSource
|
||||
set(value) {
|
||||
executionTask.configure { it.compilation = value.compilation }
|
||||
_executionSource = value
|
||||
}
|
||||
|
||||
override fun setExecutionSourceFrom(compilation: KotlinJsIrCompilation) {
|
||||
requireCompilationOfTarget(compilation, target)
|
||||
|
||||
executionSource = JsIrCompilationExecutionSource(compilation)
|
||||
}
|
||||
}
|
||||
|
||||
class JsAggregatingExecutionSource(private val aggregatingTestRun: KotlinJsReportAggregatingTestRun) :
|
||||
KotlinAggregateExecutionSource<JsCompilationExecutionSource> {
|
||||
|
||||
@@ -74,16 +49,9 @@ class JsAggregatingExecutionSource(private val aggregatingTestRun: KotlinJsRepor
|
||||
get() = aggregatingTestRun.getConfiguredExecutions().map { it.executionSource }
|
||||
}
|
||||
|
||||
class JsIrAggregatingExecutionSource(private val aggregatingTestRun: KotlinJsIrReportAggregatingTestRun) :
|
||||
KotlinAggregateExecutionSource<JsIrCompilationExecutionSource> {
|
||||
|
||||
override val executionSources: Iterable<JsIrCompilationExecutionSource>
|
||||
get() = aggregatingTestRun.getConfiguredExecutions().map { it.executionSource }
|
||||
}
|
||||
|
||||
open class KotlinJsReportAggregatingTestRun(
|
||||
testRunName: String,
|
||||
override val target: KotlinJsTarget
|
||||
override val target: KotlinJsSubtargetContainerDsl
|
||||
) : KotlinReportAggregatingTestRun<JsCompilationExecutionSource, JsAggregatingExecutionSource, KotlinJsPlatformTestRun>(testRunName),
|
||||
KotlinTargetTestRun<JsAggregatingExecutionSource>,
|
||||
CompilationExecutionSourceSupport<KotlinJsCompilation> {
|
||||
@@ -95,7 +63,7 @@ open class KotlinJsReportAggregatingTestRun(
|
||||
override val executionSource: JsAggregatingExecutionSource
|
||||
get() = JsAggregatingExecutionSource(this)
|
||||
|
||||
private fun KotlinJsSubTarget.getChildTestExecution() = testRuns.maybeCreate(testRunName)
|
||||
private fun KotlinJsSubTargetDsl.getChildTestExecution() = testRuns.maybeCreate(testRunName)
|
||||
|
||||
override fun getConfiguredExecutions(): Iterable<KotlinJsPlatformTestRun> = mutableListOf<KotlinJsPlatformTestRun>().apply {
|
||||
if (target.isNodejsConfigured) {
|
||||
@@ -107,46 +75,11 @@ open class KotlinJsReportAggregatingTestRun(
|
||||
}
|
||||
|
||||
override fun configureAllExecutions(configure: KotlinJsPlatformTestRun.() -> Unit) {
|
||||
val doConfigureInChildren: KotlinJsSubTarget.() -> Unit = {
|
||||
val doConfigureInChildren: KotlinJsSubTargetDsl.() -> Unit = {
|
||||
configure(getChildTestExecution())
|
||||
}
|
||||
|
||||
target.whenBrowserConfigured { doConfigureInChildren(this as KotlinJsSubTarget) }
|
||||
target.whenNodejsConfigured { doConfigureInChildren(this as KotlinJsSubTarget) }
|
||||
}
|
||||
}
|
||||
|
||||
open class KotlinJsIrReportAggregatingTestRun(
|
||||
testRunName: String,
|
||||
override val target: KotlinJsIrTarget
|
||||
) : KotlinReportAggregatingTestRun<JsIrCompilationExecutionSource, JsIrAggregatingExecutionSource, KotlinJsIrPlatformTestRun>(testRunName),
|
||||
KotlinTargetTestRun<JsIrAggregatingExecutionSource>,
|
||||
CompilationExecutionSourceSupport<KotlinJsIrCompilation> {
|
||||
|
||||
override fun setExecutionSourceFrom(compilation: KotlinJsIrCompilation) = configureAllExecutions {
|
||||
setExecutionSourceFrom(compilation)
|
||||
}
|
||||
|
||||
override val executionSource: JsIrAggregatingExecutionSource
|
||||
get() = JsIrAggregatingExecutionSource(this)
|
||||
|
||||
private fun KotlinJsIrSubTarget.getChildTestExecution() = testRuns.maybeCreate(testRunName)
|
||||
|
||||
override fun getConfiguredExecutions(): Iterable<KotlinJsIrPlatformTestRun> = mutableListOf<KotlinJsIrPlatformTestRun>().apply {
|
||||
if (target.isNodejsConfigured) {
|
||||
add(target.nodejs.getChildTestExecution())
|
||||
}
|
||||
if (target.isBrowserConfigured) {
|
||||
add(target.browser.getChildTestExecution())
|
||||
}
|
||||
}
|
||||
|
||||
override fun configureAllExecutions(configure: KotlinJsIrPlatformTestRun.() -> Unit) {
|
||||
val doConfigureInChildren: KotlinJsIrSubTarget.() -> Unit = {
|
||||
configure(getChildTestExecution())
|
||||
}
|
||||
|
||||
target.whenBrowserConfigured { doConfigureInChildren(this as KotlinJsIrSubTarget) }
|
||||
target.whenNodejsConfigured { doConfigureInChildren(this as KotlinJsIrSubTarget) }
|
||||
target.whenBrowserConfigured { doConfigureInChildren(this) }
|
||||
target.whenNodejsConfigured { doConfigureInChildren(this) }
|
||||
}
|
||||
}
|
||||
+8
-7
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinOnlyTarget
|
||||
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.KotlinJsIrTarget
|
||||
import org.jetbrains.kotlin.gradle.targets.js.subtargets.KotlinBrowserJs
|
||||
@@ -42,7 +43,7 @@ constructor(
|
||||
) :
|
||||
KotlinOnlyTarget<KotlinJsCompilation>(project, platformType),
|
||||
KotlinTargetWithTests<JsAggregatingExecutionSource, KotlinJsReportAggregatingTestRun>,
|
||||
KotlinJsTargetDsl {
|
||||
KotlinJsTargetDsl, KotlinJsSubtargetContainerDsl {
|
||||
override lateinit var testRuns: NamedDomainObjectContainer<KotlinJsReportAggregatingTestRun>
|
||||
internal set
|
||||
|
||||
@@ -96,9 +97,9 @@ constructor(
|
||||
|
||||
private val browserConfiguredHandlers = mutableListOf<KotlinJsBrowserDsl.() -> Unit>()
|
||||
|
||||
val browser by browserLazyDelegate
|
||||
override val browser by browserLazyDelegate
|
||||
|
||||
internal val isBrowserConfigured: Boolean = browserLazyDelegate.isInitialized()
|
||||
override val isBrowserConfigured: Boolean = browserLazyDelegate.isInitialized()
|
||||
|
||||
override fun browser(body: KotlinJsBrowserDsl.() -> Unit) {
|
||||
body(browser)
|
||||
@@ -117,9 +118,9 @@ constructor(
|
||||
|
||||
private val nodejsConfiguredHandlers = mutableListOf<KotlinJsNodeDsl.() -> Unit>()
|
||||
|
||||
val nodejs by nodejsLazyDelegate
|
||||
override val nodejs by nodejsLazyDelegate
|
||||
|
||||
internal val isNodejsConfigured: Boolean = nodejsLazyDelegate.isInitialized()
|
||||
override val isNodejsConfigured: Boolean = nodejsLazyDelegate.isInitialized()
|
||||
|
||||
override fun nodejs(body: KotlinJsNodeDsl.() -> Unit) {
|
||||
body(nodejs)
|
||||
@@ -156,7 +157,7 @@ constructor(
|
||||
}
|
||||
}
|
||||
|
||||
fun whenBrowserConfigured(body: KotlinJsBrowserDsl.() -> Unit) {
|
||||
override fun whenBrowserConfigured(body: KotlinJsBrowserDsl.() -> Unit) {
|
||||
if (browserLazyDelegate.isInitialized()) {
|
||||
browser(body)
|
||||
} else {
|
||||
@@ -164,7 +165,7 @@ constructor(
|
||||
}
|
||||
}
|
||||
|
||||
fun whenNodejsConfigured(body: KotlinJsNodeDsl.() -> Unit) {
|
||||
override fun whenNodejsConfigured(body: KotlinJsNodeDsl.() -> Unit) {
|
||||
if (nodejsLazyDelegate.isInitialized()) {
|
||||
nodejs(body)
|
||||
} else {
|
||||
|
||||
+19
-7
@@ -9,15 +9,27 @@ import groovy.lang.Closure
|
||||
import org.gradle.api.NamedDomainObjectContainer
|
||||
import org.gradle.util.ConfigureUtil
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJsDce
|
||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsIrPlatformTestRun
|
||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsIrReportAggregatingTestRun
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
|
||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsPlatformTestRun
|
||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsReportAggregatingTestRun
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTest
|
||||
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsExec
|
||||
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
|
||||
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack
|
||||
|
||||
interface KotlinJsSubtargetContainerDsl : KotlinTarget {
|
||||
val nodejs: KotlinJsNodeDsl
|
||||
|
||||
val browser: KotlinJsBrowserDsl
|
||||
|
||||
val isNodejsConfigured: Boolean
|
||||
|
||||
val isBrowserConfigured: Boolean
|
||||
|
||||
fun whenNodejsConfigured(body: KotlinJsNodeDsl.() -> Unit)
|
||||
|
||||
fun whenBrowserConfigured(body: KotlinJsBrowserDsl.() -> Unit)
|
||||
}
|
||||
|
||||
interface KotlinJsIrTargetDsl {
|
||||
fun browser() = browser { }
|
||||
fun browser(body: KotlinJsIrBrowserDsl.() -> Unit)
|
||||
@@ -39,10 +51,10 @@ interface KotlinJsIrTargetDsl {
|
||||
|
||||
fun produceExecutable()
|
||||
|
||||
val testRuns: NamedDomainObjectContainer<KotlinJsIrReportAggregatingTestRun>
|
||||
val testRuns: NamedDomainObjectContainer<KotlinJsReportAggregatingTestRun>
|
||||
}
|
||||
|
||||
interface KotlinJsTargetDsl {
|
||||
interface KotlinJsTargetDsl : KotlinTarget {
|
||||
fun browser() = browser { }
|
||||
fun browser(body: KotlinJsBrowserDsl.() -> Unit)
|
||||
fun browser(fn: Closure<*>) {
|
||||
@@ -78,14 +90,14 @@ interface KotlinJsSubTargetDsl {
|
||||
}
|
||||
|
||||
interface KotlinJsIrSubTargetDsl {
|
||||
fun testTask(body: KotlinJsIrTest.() -> Unit)
|
||||
fun testTask(body: KotlinJsTest.() -> Unit)
|
||||
fun testTask(fn: Closure<*>) {
|
||||
testTask {
|
||||
ConfigureUtil.configure(fn, this)
|
||||
}
|
||||
}
|
||||
|
||||
val testRuns: NamedDomainObjectContainer<KotlinJsIrPlatformTestRun>
|
||||
val testRuns: NamedDomainObjectContainer<KotlinJsPlatformTestRun>
|
||||
}
|
||||
|
||||
interface KotlinJsBrowserDsl : KotlinJsSubTargetDsl {
|
||||
|
||||
+9
-2
@@ -10,9 +10,11 @@ import org.gradle.api.Task
|
||||
import org.gradle.api.plugins.BasePluginConvention
|
||||
import org.gradle.api.tasks.Copy
|
||||
import org.gradle.language.base.plugins.LifecycleBasePlugin
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJsDce
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.*
|
||||
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
|
||||
import org.jetbrains.kotlin.gradle.targets.js.subtargets.BrowserDistribution
|
||||
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
|
||||
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack
|
||||
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig
|
||||
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig.Devtool
|
||||
@@ -22,7 +24,7 @@ import javax.inject.Inject
|
||||
|
||||
open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
||||
KotlinJsIrSubTarget(target, "browser"),
|
||||
KotlinJsIrBrowserDsl {
|
||||
KotlinJsBrowserDsl {
|
||||
|
||||
private val commonWebpackConfigurations: MutableList<KotlinWebpack.() -> Unit> = mutableListOf()
|
||||
private val commonRunConfigurations: MutableList<KotlinWebpack.() -> Unit> = mutableListOf()
|
||||
@@ -33,7 +35,7 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
||||
override val testTaskDescription: String
|
||||
get() = "Run all ${target.name} tests inside browser using karma and webpack"
|
||||
|
||||
override fun configureDefaultTestFramework(it: KotlinJsIrTest) {
|
||||
override fun configureDefaultTestFramework(it: KotlinJsTest) {
|
||||
it.useKarma {
|
||||
useChromeHeadless()
|
||||
}
|
||||
@@ -52,6 +54,11 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
||||
commonWebpackConfigurations.add(body)
|
||||
}
|
||||
|
||||
@ExperimentalDceDsl
|
||||
override fun dceTask(body: KotlinJsDce.() -> Unit) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun configureMain(compilation: KotlinJsIrCompilation) {
|
||||
configureRun(compilation)
|
||||
configureBuild(compilation)
|
||||
|
||||
+12
-11
@@ -12,11 +12,12 @@ import org.jetbrains.kotlin.gradle.plugin.AbstractKotlinTargetConfigurator
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetWithTests
|
||||
import org.jetbrains.kotlin.gradle.plugin.whenEvaluated
|
||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsIrPlatformTestRun
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsIrSubTargetDsl
|
||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsPlatformTestRun
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsSubTargetDsl
|
||||
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
|
||||
import org.jetbrains.kotlin.gradle.targets.js.npm.NpmResolverPlugin
|
||||
import org.jetbrains.kotlin.gradle.targets.js.npm.npmProject
|
||||
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
|
||||
import org.jetbrains.kotlin.gradle.tasks.registerTask
|
||||
import org.jetbrains.kotlin.gradle.testing.internal.configureConventions
|
||||
import org.jetbrains.kotlin.gradle.testing.internal.kotlinTestRegistry
|
||||
@@ -25,13 +26,13 @@ import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
||||
abstract class KotlinJsIrSubTarget(
|
||||
val target: KotlinJsIrTarget,
|
||||
private val disambiguationClassifier: String
|
||||
) : KotlinJsIrSubTargetDsl {
|
||||
) : KotlinJsSubTargetDsl {
|
||||
val project get() = target.project
|
||||
private val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
||||
|
||||
abstract val testTaskDescription: String
|
||||
|
||||
final override lateinit var testRuns: NamedDomainObjectContainer<KotlinJsIrPlatformTestRun>
|
||||
final override lateinit var testRuns: NamedDomainObjectContainer<KotlinJsPlatformTestRun>
|
||||
private set
|
||||
|
||||
internal fun configure() {
|
||||
@@ -79,7 +80,7 @@ abstract class KotlinJsIrSubTarget(
|
||||
}
|
||||
}
|
||||
|
||||
override fun testTask(body: KotlinJsIrTest.() -> Unit) {
|
||||
override fun testTask(body: KotlinJsTest.() -> Unit) {
|
||||
testRuns.getByName(KotlinTargetWithTests.DEFAULT_TEST_RUN_NAME).executionTask.configure(body)
|
||||
}
|
||||
|
||||
@@ -89,7 +90,7 @@ abstract class KotlinJsIrSubTarget(
|
||||
abstract fun configureBuildVariants()
|
||||
|
||||
private fun configureTests() {
|
||||
testRuns = project.container(KotlinJsIrPlatformTestRun::class.java) { name -> KotlinJsIrPlatformTestRun(name, this) }.also {
|
||||
testRuns = project.container(KotlinJsPlatformTestRun::class.java) { name -> KotlinJsPlatformTestRun(name, target) }.also {
|
||||
(this as ExtensionAware).extensions.add(this::testRuns.name, it)
|
||||
}
|
||||
|
||||
@@ -97,21 +98,21 @@ abstract class KotlinJsIrSubTarget(
|
||||
testRuns.create(KotlinTargetWithTests.DEFAULT_TEST_RUN_NAME)
|
||||
}
|
||||
|
||||
protected open fun configureTestRunDefaults(testRun: KotlinJsIrPlatformTestRun) {
|
||||
protected open fun configureTestRunDefaults(testRun: KotlinJsPlatformTestRun) {
|
||||
target.compilations.matching { it.name == KotlinCompilation.TEST_COMPILATION_NAME }.all { compilation ->
|
||||
configureTestsRun(testRun, compilation)
|
||||
}
|
||||
}
|
||||
|
||||
private fun configureTestsRun(testRun: KotlinJsIrPlatformTestRun, compilation: KotlinJsIrCompilation) {
|
||||
fun KotlinJsIrPlatformTestRun.subtargetTestTaskName(): String = disambiguateCamelCased(
|
||||
private fun configureTestsRun(testRun: KotlinJsPlatformTestRun, compilation: KotlinJsIrCompilation) {
|
||||
fun KotlinJsPlatformTestRun.subtargetTestTaskName(): String = disambiguateCamelCased(
|
||||
lowerCamelCaseName(
|
||||
name.takeIf { it != KotlinTargetWithTests.DEFAULT_TEST_RUN_NAME },
|
||||
AbstractKotlinTargetConfigurator.testTaskNameSuffix
|
||||
)
|
||||
)
|
||||
|
||||
val testJs = project.registerTask<KotlinJsIrTest>(testRun.subtargetTestTaskName()) { testJs ->
|
||||
val testJs = project.registerTask<KotlinJsTest>(testRun.subtargetTestTaskName()) { testJs ->
|
||||
val compileTask = compilation.compileKotlinTask
|
||||
|
||||
testJs.group = LifecycleBasePlugin.VERIFICATION_GROUP
|
||||
@@ -151,7 +152,7 @@ abstract class KotlinJsIrSubTarget(
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract fun configureDefaultTestFramework(it: KotlinJsIrTest)
|
||||
protected abstract fun configureDefaultTestFramework(it: KotlinJsTest)
|
||||
|
||||
private fun configureMain() {
|
||||
target.compilations.all { compilation ->
|
||||
|
||||
+19
-18
@@ -12,12 +12,13 @@ import org.jetbrains.kotlin.gradle.plugin.AbstractKotlinTargetConfigurator.Compa
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
||||
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.JsAggregatingExecutionSource
|
||||
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
|
||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsReportAggregatingTestRun
|
||||
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.tasks.locateTask
|
||||
import org.jetbrains.kotlin.gradle.testing.internal.KotlinTestReport
|
||||
import org.jetbrains.kotlin.gradle.testing.testTaskName
|
||||
@@ -26,9 +27,9 @@ import javax.inject.Inject
|
||||
|
||||
open class KotlinJsIrTarget @Inject constructor(project: Project, platformType: KotlinPlatformType) :
|
||||
KotlinOnlyTarget<KotlinJsIrCompilation>(project, platformType),
|
||||
KotlinTargetWithTests<JsIrAggregatingExecutionSource, KotlinJsIrReportAggregatingTestRun>,
|
||||
KotlinJsIrTargetDsl {
|
||||
override lateinit var testRuns: NamedDomainObjectContainer<KotlinJsIrReportAggregatingTestRun>
|
||||
KotlinTargetWithTests<JsAggregatingExecutionSource, KotlinJsReportAggregatingTestRun>,
|
||||
KotlinJsTargetDsl, KotlinJsSubtargetContainerDsl {
|
||||
override lateinit var testRuns: NamedDomainObjectContainer<KotlinJsReportAggregatingTestRun>
|
||||
internal set
|
||||
|
||||
var producingType: KotlinJsProducingType? = null
|
||||
@@ -53,13 +54,13 @@ open class KotlinJsIrTarget @Inject constructor(project: Project, platformType:
|
||||
}
|
||||
}
|
||||
|
||||
private val browserConfiguredHandlers = mutableListOf<KotlinJsIrBrowserDsl.() -> Unit>()
|
||||
private val browserConfiguredHandlers = mutableListOf<KotlinJsBrowserDsl.() -> Unit>()
|
||||
|
||||
val browser by browserLazyDelegate
|
||||
override val browser by browserLazyDelegate
|
||||
|
||||
internal val isBrowserConfigured: Boolean = browserLazyDelegate.isInitialized()
|
||||
override val isBrowserConfigured: Boolean = browserLazyDelegate.isInitialized()
|
||||
|
||||
override fun browser(body: KotlinJsIrBrowserDsl.() -> Unit) {
|
||||
override fun browser(body: KotlinJsBrowserDsl.() -> Unit) {
|
||||
body(browser)
|
||||
}
|
||||
|
||||
@@ -74,13 +75,13 @@ open class KotlinJsIrTarget @Inject constructor(project: Project, platformType:
|
||||
}
|
||||
}
|
||||
|
||||
private val nodejsConfiguredHandlers = mutableListOf<KotlinJsIrNodeDsl.() -> Unit>()
|
||||
private val nodejsConfiguredHandlers = mutableListOf<KotlinJsNodeDsl.() -> Unit>()
|
||||
|
||||
val nodejs by nodejsLazyDelegate
|
||||
override val nodejs by nodejsLazyDelegate
|
||||
|
||||
internal val isNodejsConfigured: Boolean = nodejsLazyDelegate.isInitialized()
|
||||
override val isNodejsConfigured: Boolean = nodejsLazyDelegate.isInitialized()
|
||||
|
||||
override fun nodejs(body: KotlinJsIrNodeDsl.() -> Unit) {
|
||||
override fun nodejs(body: KotlinJsNodeDsl.() -> Unit) {
|
||||
body(nodejs)
|
||||
}
|
||||
|
||||
@@ -115,7 +116,7 @@ open class KotlinJsIrTarget @Inject constructor(project: Project, platformType:
|
||||
}
|
||||
}
|
||||
|
||||
fun whenBrowserConfigured(body: KotlinJsIrBrowserDsl.() -> Unit) {
|
||||
override fun whenBrowserConfigured(body: KotlinJsBrowserDsl.() -> Unit) {
|
||||
if (browserLazyDelegate.isInitialized()) {
|
||||
browser(body)
|
||||
} else {
|
||||
@@ -123,7 +124,7 @@ open class KotlinJsIrTarget @Inject constructor(project: Project, platformType:
|
||||
}
|
||||
}
|
||||
|
||||
fun whenNodejsConfigured(body: KotlinJsIrNodeDsl.() -> Unit) {
|
||||
override fun whenNodejsConfigured(body: KotlinJsNodeDsl.() -> Unit) {
|
||||
if (nodejsLazyDelegate.isInitialized()) {
|
||||
nodejs(body)
|
||||
} else {
|
||||
|
||||
+5
-6
@@ -11,23 +11,22 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinJsIrSourceSetProcessor
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinOnlyTargetConfigurator
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSetProcessor
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetWithTestsConfigurator
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinOnlyTarget
|
||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsIrReportAggregatingTestRun
|
||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsReportAggregatingTestRun
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinTasksProvider
|
||||
import org.jetbrains.kotlin.gradle.testing.internal.kotlinTestRegistry
|
||||
import org.jetbrains.kotlin.gradle.testing.testTaskName
|
||||
|
||||
open class KotlinJsIrTargetConfigurator(kotlinPluginVersion: String) :
|
||||
KotlinOnlyTargetConfigurator<KotlinJsIrCompilation, KotlinJsIrTarget>(true, true, kotlinPluginVersion),
|
||||
KotlinTargetWithTestsConfigurator<KotlinJsIrReportAggregatingTestRun, KotlinJsIrTarget> {
|
||||
KotlinTargetWithTestsConfigurator<KotlinJsReportAggregatingTestRun, KotlinJsIrTarget> {
|
||||
|
||||
override val testRunClass: Class<KotlinJsIrReportAggregatingTestRun> get() = KotlinJsIrReportAggregatingTestRun::class.java
|
||||
override val testRunClass: Class<KotlinJsReportAggregatingTestRun> get() = KotlinJsReportAggregatingTestRun::class.java
|
||||
|
||||
override fun createTestRun(
|
||||
name: String,
|
||||
target: KotlinJsIrTarget
|
||||
): KotlinJsIrReportAggregatingTestRun {
|
||||
val result = KotlinJsIrReportAggregatingTestRun(name, target)
|
||||
): KotlinJsReportAggregatingTestRun {
|
||||
val result = KotlinJsReportAggregatingTestRun(name, target)
|
||||
|
||||
val testTask = target.project.kotlinTestRegistry.getOrCreateAggregatedTestTask(
|
||||
name = result.testTaskName,
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ open class KotlinJsIrTargetPreset(
|
||||
KotlinJsIrCompilationFactory(project, forTarget)
|
||||
|
||||
companion object {
|
||||
const val PRESET_NAME = "jsIr"
|
||||
const val PRESET_NAME = "js"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-3
@@ -5,13 +5,14 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.targets.js.ir
|
||||
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsIrNodeDsl
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsNodeDsl
|
||||
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsExec
|
||||
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
|
||||
import javax.inject.Inject
|
||||
|
||||
open class KotlinNodeJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
||||
KotlinJsIrSubTarget(target, "node"),
|
||||
KotlinJsIrNodeDsl {
|
||||
KotlinJsNodeDsl {
|
||||
override val testTaskDescription: String
|
||||
get() = "Run all ${target.name} tests inside nodejs using the builtin test framework"
|
||||
|
||||
@@ -21,7 +22,7 @@ open class KotlinNodeJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
||||
(project.tasks.getByName(runTaskName) as NodeJsExec).body()
|
||||
}
|
||||
|
||||
override fun configureDefaultTestFramework(it: KotlinJsIrTest) {
|
||||
override fun configureDefaultTestFramework(it: KotlinJsTest) {
|
||||
it.useMocha { }
|
||||
}
|
||||
|
||||
|
||||
+6
-1
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.gradle.tasks.registerTask
|
||||
import org.jetbrains.kotlin.gradle.testing.internal.configureConventions
|
||||
import org.jetbrains.kotlin.gradle.testing.internal.kotlinTestRegistry
|
||||
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
||||
import org.jetbrains.kotlin.gradle.utils.newFileProperty
|
||||
|
||||
abstract class KotlinJsSubTarget(
|
||||
val target: KotlinJsTarget,
|
||||
@@ -66,7 +67,7 @@ abstract class KotlinJsSubTarget(
|
||||
abstract fun configureBuildVariants()
|
||||
|
||||
private fun configureTests() {
|
||||
testRuns = project.container(KotlinJsPlatformTestRun::class.java) { name -> KotlinJsPlatformTestRun(name, this) }.also {
|
||||
testRuns = project.container(KotlinJsPlatformTestRun::class.java) { name -> KotlinJsPlatformTestRun(name, target) }.also {
|
||||
(this as ExtensionAware).extensions.add(this::testRuns.name, it)
|
||||
}
|
||||
|
||||
@@ -94,6 +95,10 @@ abstract class KotlinJsSubTarget(
|
||||
testJs.group = LifecycleBasePlugin.VERIFICATION_GROUP
|
||||
testJs.description = testTaskDescription
|
||||
|
||||
testJs.inputFileProperty.set(project.newFileProperty {
|
||||
compileTask.outputFile
|
||||
})
|
||||
|
||||
testJs.dependsOn(nodeJs.npmInstallTask, compileTask, nodeJs.nodeJsSetupTask)
|
||||
|
||||
testJs.onlyIf {
|
||||
|
||||
+6
@@ -7,7 +7,9 @@ package org.jetbrains.kotlin.gradle.targets.js.testing
|
||||
|
||||
import groovy.lang.Closure
|
||||
import org.gradle.api.file.FileCollection
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.InputFile
|
||||
import org.gradle.api.tasks.InputFiles
|
||||
import org.gradle.api.tasks.Internal
|
||||
import org.gradle.process.internal.DefaultProcessForkOptions
|
||||
@@ -22,6 +24,7 @@ import org.jetbrains.kotlin.gradle.targets.js.npm.npmProject
|
||||
import org.jetbrains.kotlin.gradle.targets.js.testing.karma.KotlinKarma
|
||||
import org.jetbrains.kotlin.gradle.targets.js.testing.mocha.KotlinMocha
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinTest
|
||||
import org.jetbrains.kotlin.gradle.utils.newFileProperty
|
||||
|
||||
open class KotlinJsTest :
|
||||
KotlinTest(),
|
||||
@@ -36,6 +39,9 @@ open class KotlinJsTest :
|
||||
val testFrameworkSettings: String
|
||||
@Input get() = testFramework!!.settingsState
|
||||
|
||||
@InputFile
|
||||
val inputFileProperty: RegularFileProperty = project.newFileProperty()
|
||||
|
||||
@Input
|
||||
var debug: Boolean = false
|
||||
|
||||
|
||||
Reference in New Issue
Block a user