[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> val testRuns: NamedDomainObjectContainer<KotlinJsIrReportAggregatingTestRun>
} }
@@ -81,10 +85,6 @@ interface KotlinJsIrSubTargetDsl {
} }
} }
fun produceKotlinLibrary()
fun produceExecutable()
val testRuns: NamedDomainObjectContainer<KotlinJsIrPlatformTestRun> val testRuns: NamedDomainObjectContainer<KotlinJsIrPlatformTestRun>
} }
@@ -33,13 +33,6 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
override val testTaskDescription: String override val testTaskDescription: String
get() = "Run all ${target.name} tests inside browser using karma and webpack" 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) { override fun configureDefaultTestFramework(it: KotlinJsIrTest) {
it.useKarma { it.useKarma {
useChromeHeadless() 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 { companion object {
const val PRODUCTION = "production" const val PRODUCTION = "production"
const val DEVELOPMENT = "development" const val DEVELOPMENT = "development"
@@ -34,12 +34,7 @@ abstract class KotlinJsIrSubTarget(
final override lateinit var testRuns: NamedDomainObjectContainer<KotlinJsIrPlatformTestRun> final override lateinit var testRuns: NamedDomainObjectContainer<KotlinJsIrPlatformTestRun>
private set private set
protected val producingConfigured: Boolean = false internal fun configure() {
protected val browserProducingConfiguredHandlers: MutableList<KotlinBrowserJsIr.() -> Unit> = mutableListOf()
protected val nodejsProducingConfiguredHandlers: MutableList<KotlinNodeJsIr.() -> Unit> = mutableListOf()
protected open fun configure() {
NpmResolverPlugin.apply(project) NpmResolverPlugin.apply(project)
configureBuildVariants() configureBuildVariants()
@@ -56,19 +51,17 @@ abstract class KotlinJsIrSubTarget(
} }
} }
override fun produceKotlinLibrary() { internal fun produceKotlinLibrary() {
produceByFlags() produceByFlags()
} }
override fun produceExecutable() { internal fun produceExecutable() {
produceByFlags() produceByFlags()
configureMain() configureMain()
} }
private fun produceByFlags(vararg flags: String) { private fun produceByFlags(vararg flags: String) {
configure()
target.compilations target.compilations
.matching { it.name == KotlinCompilation.TEST_COMPILATION_NAME } .matching { it.name == KotlinCompilation.TEST_COMPILATION_NAME }
.all { .all {
@@ -42,10 +42,9 @@ open class KotlinJsIrTarget @Inject constructor(project: Project, platformType:
private val browserLazyDelegate = lazy { private val browserLazyDelegate = lazy {
project.objects.newInstance(KotlinBrowserJsIr::class.java, this).also { project.objects.newInstance(KotlinBrowserJsIr::class.java, this).also {
it.configure()
browserConfiguredHandlers.forEach { handler -> browserConfiguredHandlers.forEach { handler ->
it.whenProducingConfigured { handler(it)
handler(this)
}
} }
browserConfiguredHandlers.clear() browserConfiguredHandlers.clear()
} }
@@ -63,10 +62,9 @@ open class KotlinJsIrTarget @Inject constructor(project: Project, platformType:
private val nodejsLazyDelegate = lazy { private val nodejsLazyDelegate = lazy {
project.objects.newInstance(KotlinNodeJsIr::class.java, this).also { project.objects.newInstance(KotlinNodeJsIr::class.java, this).also {
it.configure()
nodejsConfiguredHandlers.forEach { handler -> nodejsConfiguredHandlers.forEach { handler ->
it.whenProducingConfigured { handler(it)
handler(this)
}
} }
nodejsConfiguredHandlers.clear() nodejsConfiguredHandlers.clear()
@@ -83,6 +81,26 @@ open class KotlinJsIrTarget @Inject constructor(project: Project, platformType:
body(nodejs) 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) { fun whenBrowserConfigured(body: KotlinJsIrBrowserDsl.() -> Unit) {
if (browserLazyDelegate.isInitialized()) { if (browserLazyDelegate.isInitialized()) {
browser(body) browser(body)
@@ -17,13 +17,6 @@ open class KotlinNodeJsIr @Inject constructor(target: KotlinJsIrTarget) :
private val runTaskName = disambiguateCamelCased("run") private val runTaskName = disambiguateCamelCased("run")
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()
} }
@@ -47,12 +40,4 @@ open class KotlinNodeJsIr @Inject constructor(target: KotlinJsIrTarget) :
override fun configureBuildVariants() { override fun configureBuildVariants() {
} }
fun whenProducingConfigured(body: KotlinNodeJsIr.() -> Unit) {
if (producingConfigured) {
this.body()
} else {
nodejsProducingConfiguredHandlers += body
}
}
} }
@@ -45,7 +45,7 @@ abstract class KotlinJsSubTarget(
configureMain() configureMain()
} }
internal open fun configure() { internal fun configure() {
NpmResolverPlugin.apply(project) NpmResolverPlugin.apply(project)
configureTests() configureTests()