[Gradle, JS] Make ir binaries as live data

#KT-38058 fixed
This commit is contained in:
Ilya Goncharov
2020-04-06 19:23:49 +03:00
parent 6eb2875690
commit 6a02e257a0
3 changed files with 17 additions and 15 deletions
@@ -85,12 +85,11 @@ constructor(
} }
) )
internal fun getIrBinary( internal fun getIrBinaries(
type: KotlinJsBinaryType type: KotlinJsBinaryType
): JsIrBinary = ): DomainObjectSet<JsIrBinary> =
matching { it.type == type } matching { it.type == type }
.withType(JsIrBinary::class.java) .withType(JsIrBinary::class.java)
.single()
private fun <T : JsBinary> createBinaries( private fun <T : JsBinary> createBinaries(
compilation: KotlinJsCompilation, compilation: KotlinJsCompilation,
@@ -96,9 +96,9 @@ abstract class KotlinJsIrSubTarget(
testJs.group = LifecycleBasePlugin.VERIFICATION_GROUP testJs.group = LifecycleBasePlugin.VERIFICATION_GROUP
testJs.description = testTaskDescription testJs.description = testTaskDescription
val testExecutableTask = compilation.binaries.getIrBinary( val testExecutableTask = compilation.binaries.getIrBinaries(
KotlinJsBinaryType.DEVELOPMENT KotlinJsBinaryType.DEVELOPMENT
).linkTask ).single().linkTask
testJs.inputFileProperty.set( testJs.inputFileProperty.set(
testExecutableTask.map { it.outputFileProperty.get() } testExecutableTask.map { it.outputFileProperty.get() }
@@ -31,21 +31,24 @@ open class KotlinNodeJsIr @Inject constructor(target: KotlinJsIrTarget) :
override fun configureRun( override fun configureRun(
compilation: KotlinJsIrCompilation compilation: KotlinJsIrCompilation
) { ) {
val developmentExecutable = compilation.binaries.getIrBinary(KotlinJsBinaryType.DEVELOPMENT) compilation.binaries.getIrBinaries(KotlinJsBinaryType.DEVELOPMENT)
.all { developmentExecutable ->
val runTaskHolder = NodeJsExec.create(compilation, disambiguateCamelCased(RUN_TASK_NAME)) { val runTaskHolder = NodeJsExec.create(compilation, disambiguateCamelCased(RUN_TASK_NAME)) {
group = taskGroupName group = taskGroupName
inputFileProperty.set(developmentExecutable.linkTask.map { it.outputFileProperty.get() }) inputFileProperty.set(developmentExecutable.linkTask.map { it.outputFileProperty.get() })
} }
target.runTask.dependsOn(runTaskHolder) target.runTask.dependsOn(runTaskHolder)
} }
}
override fun configureBuild( override fun configureBuild(
compilation: KotlinJsIrCompilation compilation: KotlinJsIrCompilation
) { ) {
val productionExecutable = compilation.binaries.getIrBinary(KotlinJsBinaryType.PRODUCTION) compilation.binaries.getIrBinaries(KotlinJsBinaryType.PRODUCTION)
.all { productionExecutable ->
val assembleTask = project.tasks.getByName(LifecycleBasePlugin.ASSEMBLE_TASK_NAME) val assembleTask = project.tasks.getByName(LifecycleBasePlugin.ASSEMBLE_TASK_NAME)
assembleTask.dependsOn(productionExecutable.linkTask) assembleTask.dependsOn(productionExecutable.linkTask)
} }
}
} }