Add flag to enable intra-project parallel tasks

To enable parallel tasks execution within a project,
add 'kotlin.parallel.tasks.in.project=true'
to gradle.properties or local.properties file .

    #KT-28155 fixed
This commit is contained in:
Alexey Tsvetkov
2018-11-06 23:08:39 +03:00
parent 4678a00324
commit 5fa627c501
12 changed files with 156 additions and 46 deletions
@@ -178,7 +178,8 @@ abstract class BaseGradleIT {
val kotlinDaemonDebugPort: Int? = null,
val usePreciseJavaTracking: Boolean? = null,
val withBuildCache: Boolean = false,
val kaptOptions: KaptOptions? = null
val kaptOptions: KaptOptions? = null,
val parallelTasksInProject: Boolean? = null
)
data class KaptOptions(val verbose: Boolean, val useWorkers: Boolean)
@@ -446,6 +447,18 @@ abstract class BaseGradleIT {
assertTasksUpToDate(tasks.toList())
}
fun CompiledProject.assertTasksSubmittedWork(vararg tasks: String) {
for (task in tasks) {
assertContains("Starting Kotlin compiler work from task '$task'")
}
}
fun CompiledProject.assertTasksDidNotSubmitWork(vararg tasks: String) {
for (task in tasks) {
assertNotContains("Starting Kotlin compiler work from task '$task'")
}
}
fun CompiledProject.getOutputForTask(taskName: String): String {
val taskOutputRegex = ("\\[LIFECYCLE] \\[class org\\.gradle(?:\\.internal\\.buildevents)?\\.TaskExecutionLogger] :$taskName" +
"([\\s\\S]+?)" +
@@ -567,6 +580,10 @@ abstract class BaseGradleIT {
add("-Pkapt.use.worker.api=${kaptOptions.useWorkers}")
}
options.parallelTasksInProject?.let {
add("-Pkotlin.parallel.tasks.in.project=$it")
}
// Workaround: override a console type set in the user machine gradle.properties (since Gradle 4.3):
add("--console=plain")
@@ -249,6 +249,35 @@ class NewMultiplatformIT : BaseGradleIT() {
}
}
@Test
fun testParallelTasks() {
parallelTasksImpl(isParallel = true)
}
@Test
fun testNoParallelTasks() {
parallelTasksImpl(isParallel = false)
}
private fun parallelTasksImpl(isParallel: Boolean) = with(Project("new-mpp-parallel", gradleVersion)) {
val options = defaultBuildOptions().copy(parallelTasksInProject = isParallel)
build("assemble", options = options) {
assertSuccessful()
val tasks = arrayOf(":compileKotlinMetadata", ":compileKotlinJvm", ":compileKotlinJs")
if (isParallel) {
assertTasksSubmittedWork(*tasks)
} else {
assertTasksDidNotSubmitWork(*tasks)
}
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"
)
expectedKotlinOutputFiles.forEach { assertFileExists(it) }
}
}
@Test
fun testLibWithTests() = with(Project("new-mpp-lib-with-tests", gradleVersion)) {
build("check") {
@@ -0,0 +1,37 @@
buildscript {
repositories {
mavenLocal()
jcenter()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'kotlin-multiplatform'
repositories {
mavenLocal()
jcenter()
}
kotlin {
sourceSets {
commonMain {}
jvmMain {
dependencies {
implementation 'org.jetbrains.kotlin:kotlin-stdlib'
}
}
jsMain {
dependencies {
implementation 'org.jetbrains.kotlin:kotlin-stdlib-js'
}
}
}
targets {
fromPreset(presets.jvm, 'jvm')
fromPreset(presets.js, 'js')
}
}
@@ -0,0 +1,9 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package common
class A(val x: Int)