[Gradle, JS] Fix WorkersIT tests

This commit is contained in:
Ilya Goncharov
2020-01-30 13:13:12 +03:00
parent 8646f6a098
commit d50f520639
5 changed files with 55 additions and 9 deletions
@@ -5,23 +5,45 @@
package org.jetbrains.kotlin.gradle
import org.jetbrains.kotlin.gradle.plugin.JsMode
import org.jetbrains.kotlin.gradle.util.jsMode
import org.junit.Test
class WorkersIT : BaseGradleIT() {
@Test
fun testParallelTasks() {
parallelTasksImpl(isParallel = true)
parallelTasksImpl(
isParallel = true,
jsIr = true
)
parallelTasksImpl(
isParallel = true,
jsIr = false
)
}
@Test
fun testNoParallelTasks() {
parallelTasksImpl(isParallel = false)
parallelTasksImpl(
isParallel = false,
jsIr = true
)
parallelTasksImpl(
isParallel = false,
jsIr = false
)
}
private fun parallelTasksImpl(isParallel: Boolean) =
private fun parallelTasksImpl(
isParallel: Boolean,
jsIr: Boolean
) =
with(Project("new-mpp-parallel")) {
val options = defaultBuildOptions().copy(parallelTasksInProject = isParallel, withDaemon = false)
val traceLoading = "-Dorg.jetbrains.kotlin.compilerRunner.GradleKotlinCompilerWork.trace.loading=true"
if (!jsIr) {
gradleProperties().appendText(jsMode(JsMode.LEGACY))
}
build("assemble", traceLoading, options = options) {
assertSuccessful()
val tasks = arrayOf(":compileKotlinMetadata", ":compileKotlinJvm", ":compileKotlinJs")
@@ -33,7 +55,8 @@ class WorkersIT : BaseGradleIT() {
val expectedKotlinOutputFiles = listOf(
kotlinClassesDir(sourceSet = "metadata/main") + "common/A.kotlin_metadata",
kotlinClassesDir(sourceSet = "jvm/main") + "common/A.class",
kotlinClassesDir(sourceSet = "js/main") + "new-mpp-parallel.js"
kotlinClassesDir(sourceSet = "js/main") +
if (jsIr) "manifest" else "new-mpp-parallel.js"
)
expectedKotlinOutputFiles.forEach { assertFileExists(it) }
assertSubstringCount("Loaded GradleKotlinCompilerWork", 1)
@@ -355,7 +355,6 @@ internal class KotlinJsIrSourceSetProcessor(
return tasksProvider.registerKotlinJsIrTask(
project,
taskName,
KotlinJsIrLink::class.java,
kotlinCompilation
) { task ->
task.type = type
@@ -0,0 +1,20 @@
/*
* 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.ir
import org.gradle.api.tasks.CacheableTask
import org.gradle.workers.WorkerExecutor
import org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers
import javax.inject.Inject
@CacheableTask
internal open class KotlinJsIrLinkWithWorkers
@Inject
constructor(
private val workerExecutor: WorkerExecutor
) : KotlinJsIrLink() {
override fun compilerRunner() = GradleCompilerRunnerWithWorkers(this, workerExecutor)
}
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile
import org.jetbrains.kotlin.gradle.utils.newFileProperty
import java.io.File
@CacheableTask
open class KotlinJsIrLink : Kotlin2JsCompile() {
@Input
lateinit var type: KotlinJsIrType
@@ -25,6 +26,7 @@ open class KotlinJsIrLink : Kotlin2JsCompile() {
@get:SkipWhenEmpty
@get:InputDirectory
@get:PathSensitive(PathSensitivity.RELATIVE)
val entryModule: File
get() = File(
(taskData.compilation as KotlinJsIrCompilation)
@@ -25,6 +25,8 @@ import org.jetbrains.kotlin.gradle.plugin.mapKotlinTaskProperties
import org.jetbrains.kotlin.gradle.plugin.mpp.AbstractKotlinCompilation
import org.jetbrains.kotlin.gradle.plugin.runOnceAfterEvaluated
import org.jetbrains.kotlin.gradle.plugin.sources.applyLanguageSettingsToKotlinOptions
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrLink
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrLinkWithWorkers
/**
* Registers the task with [name] and [type] and initialization script [body]
@@ -100,14 +102,14 @@ internal open class KotlinTasksProvider(val targetName: String) {
return result
}
fun <T : Kotlin2JsCompile> registerKotlinJsIrTask(
fun registerKotlinJsIrTask(
project: Project,
name: String,
taskClass: Class<out T>,
compilation: AbstractKotlinCompilation<*>,
configureAction: (T) -> Unit
): TaskProvider<out T> {
configureAction: (KotlinJsIrLink) -> Unit
): TaskProvider<out KotlinJsIrLink> {
val properties = PropertiesProvider(project)
val taskClass = taskOrWorkersTask<KotlinJsIrLink, KotlinJsIrLinkWithWorkers>(properties)
val result = project.registerTask(name, taskClass) {
configureAction(it)
}