[Gradle, JS] Move producing dsl from subtarget to target in IR

This commit is contained in:
Ilya Goncharov
2020-01-27 14:25:57 +03:00
parent 7a3b6e2d71
commit 8322d7b007
6 changed files with 32 additions and 51 deletions
@@ -35,6 +35,10 @@ interface KotlinJsIrTargetDsl {
}
}
fun produceKotlinLibrary()
fun produceExecutable()
val testRuns: NamedDomainObjectContainer<KotlinJsIrReportAggregatingTestRun>
}
@@ -81,10 +85,6 @@ interface KotlinJsIrSubTargetDsl {
}
}
fun produceKotlinLibrary()
fun produceExecutable()
val testRuns: NamedDomainObjectContainer<KotlinJsIrPlatformTestRun>
}
@@ -33,13 +33,6 @@ 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 configure() {
super.configure()
browserProducingConfiguredHandlers.forEach { handler ->
handler(this)
}
}
override fun configureDefaultTestFramework(it: KotlinJsIrTest) {
it.useKarma {
useChromeHeadless()
@@ -224,14 +217,6 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
}
}
fun whenProducingConfigured(body: KotlinBrowserJsIr.() -> Unit) {
if (producingConfigured) {
this.body()
} else {
browserProducingConfiguredHandlers += body
}
}
companion object {
const val PRODUCTION = "production"
const val DEVELOPMENT = "development"
@@ -34,12 +34,7 @@ abstract class KotlinJsIrSubTarget(
final override lateinit var testRuns: NamedDomainObjectContainer<KotlinJsIrPlatformTestRun>
private set
protected val producingConfigured: Boolean = false
protected val browserProducingConfiguredHandlers: MutableList<KotlinBrowserJsIr.() -> Unit> = mutableListOf()
protected val nodejsProducingConfiguredHandlers: MutableList<KotlinNodeJsIr.() -> Unit> = mutableListOf()
protected open fun configure() {
internal fun configure() {
NpmResolverPlugin.apply(project)
configureBuildVariants()
@@ -56,19 +51,17 @@ abstract class KotlinJsIrSubTarget(
}
}
override fun produceKotlinLibrary() {
internal fun produceKotlinLibrary() {
produceByFlags()
}
override fun produceExecutable() {
internal fun produceExecutable() {
produceByFlags()
configureMain()
}
private fun produceByFlags(vararg flags: String) {
configure()
target.compilations
.matching { it.name == KotlinCompilation.TEST_COMPILATION_NAME }
.all {
@@ -42,10 +42,9 @@ open class KotlinJsIrTarget @Inject constructor(project: Project, platformType:
private val browserLazyDelegate = lazy {
project.objects.newInstance(KotlinBrowserJsIr::class.java, this).also {
it.configure()
browserConfiguredHandlers.forEach { handler ->
it.whenProducingConfigured {
handler(this)
}
handler(it)
}
browserConfiguredHandlers.clear()
}
@@ -63,10 +62,9 @@ open class KotlinJsIrTarget @Inject constructor(project: Project, platformType:
private val nodejsLazyDelegate = lazy {
project.objects.newInstance(KotlinNodeJsIr::class.java, this).also {
it.configure()
nodejsConfiguredHandlers.forEach { handler ->
it.whenProducingConfigured {
handler(this)
}
handler(it)
}
nodejsConfiguredHandlers.clear()
@@ -83,6 +81,26 @@ open class KotlinJsIrTarget @Inject constructor(project: Project, platformType:
body(nodejs)
}
override fun produceKotlinLibrary() {
whenBrowserConfigured {
(this as KotlinJsIrSubTarget).produceKotlinLibrary()
}
whenNodejsConfigured {
(this as KotlinJsIrSubTarget).produceKotlinLibrary()
}
}
override fun produceExecutable() {
whenBrowserConfigured {
(this as KotlinJsIrSubTarget).produceExecutable()
}
whenNodejsConfigured {
(this as KotlinJsIrSubTarget).produceExecutable()
}
}
fun whenBrowserConfigured(body: KotlinJsIrBrowserDsl.() -> Unit) {
if (browserLazyDelegate.isInitialized()) {
browser(body)
@@ -17,13 +17,6 @@ open class KotlinNodeJsIr @Inject constructor(target: KotlinJsIrTarget) :
private val runTaskName = disambiguateCamelCased("run")
override fun configure() {
super.configure()
nodejsProducingConfiguredHandlers.forEach { handler ->
handler(this)
}
}
override fun runTask(body: NodeJsExec.() -> Unit) {
(project.tasks.getByName(runTaskName) as NodeJsExec).body()
}
@@ -47,12 +40,4 @@ open class KotlinNodeJsIr @Inject constructor(target: KotlinJsIrTarget) :
override fun configureBuildVariants() {
}
fun whenProducingConfigured(body: KotlinNodeJsIr.() -> Unit) {
if (producingConfigured) {
this.body()
} else {
nodejsProducingConfiguredHandlers += body
}
}
}
@@ -45,7 +45,7 @@ abstract class KotlinJsSubTarget(
configureMain()
}
internal open fun configure() {
internal fun configure() {
NpmResolverPlugin.apply(project)
configureTests()