Fix logging in workers
Setting `forkMode` to `ForkMode.NEVER` switches
`isolationMode` to `IsolationMode.CLASSLOADER`.
Classloader isolation mode prevented passing task's
logger to the unit of work.
Also it might resulted in multiple daemon instances starting
in parallel.
This change removes setting `forMode` (it was unnecessary).
Also a logger is used for the fallback message instead of printing it
to stderr. An assertion is added to tests, ensuring that
the fallback does not happen.
#KT-29394 Fixed
This commit is contained in:
-29
@@ -328,35 +328,6 @@ 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
|
@Test
|
||||||
fun testLibWithTests() = doTestLibWithTests(Project("new-mpp-lib-with-tests", gradleVersion))
|
fun testLibWithTests() = doTestLibWithTests(Project("new-mpp-lib-with-tests", gradleVersion))
|
||||||
|
|
||||||
|
|||||||
+44
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 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 org.jetbrains.kotlin.gradle
|
||||||
|
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
class WorkersIT : BaseGradleIT() {
|
||||||
|
@Test
|
||||||
|
fun testParallelTasks() {
|
||||||
|
parallelTasksImpl(isParallel = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testNoParallelTasks() {
|
||||||
|
parallelTasksImpl(isParallel = false)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun parallelTasksImpl(isParallel: Boolean) =
|
||||||
|
with(Project("new-mpp-parallel", GradleVersionRequired.AtLeast("4.7"))) {
|
||||||
|
val options = defaultBuildOptions().copy(parallelTasksInProject = isParallel, withDaemon = false)
|
||||||
|
val traceLoading = "-Dorg.jetbrains.kotlin.compilerRunner.GradleKotlinCompilerWork.trace.loading=true"
|
||||||
|
build("assemble", traceLoading, 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) }
|
||||||
|
assertSubstringCount("Loaded GradleKotlinCompilerWork", 1)
|
||||||
|
assertCompiledKotlinSources(project.relativize(project.allKotlinFiles))
|
||||||
|
assertNotContains("Falling back to sl4j logger")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
-1
@@ -20,7 +20,6 @@ internal class GradleCompilerRunnerWithWorkers(
|
|||||||
// todo: write tests with Workers enabled;
|
// todo: write tests with Workers enabled;
|
||||||
workersExecutor.submit(GradleKotlinCompilerWork::class.java) { config ->
|
workersExecutor.submit(GradleKotlinCompilerWork::class.java) { config ->
|
||||||
config.isolationMode = IsolationMode.NONE
|
config.isolationMode = IsolationMode.NONE
|
||||||
config.forkMode = ForkMode.NEVER
|
|
||||||
config.params(workArgs)
|
config.params(workArgs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-3
@@ -66,6 +66,15 @@ internal class GradleKotlinCompilerWork @Inject constructor(
|
|||||||
*/
|
*/
|
||||||
config: GradleKotlinCompilerWorkArguments
|
config: GradleKotlinCompilerWorkArguments
|
||||||
) : Runnable {
|
) : Runnable {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
init {
|
||||||
|
if (System.getProperty("org.jetbrains.kotlin.compilerRunner.GradleKotlinCompilerWork.trace.loading") == "true") {
|
||||||
|
System.out.println("Loaded GradleKotlinCompilerWork")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private val projectRootFile = config.projectFiles.projectRootFile
|
private val projectRootFile = config.projectFiles.projectRootFile
|
||||||
private val clientIsAliveFlagFile = config.projectFiles.clientIsAliveFlagFile
|
private val clientIsAliveFlagFile = config.projectFiles.clientIsAliveFlagFile
|
||||||
private val sessionFlagFile = config.projectFiles.sessionFlagFile
|
private val sessionFlagFile = config.projectFiles.sessionFlagFile
|
||||||
@@ -80,10 +89,16 @@ internal class GradleKotlinCompilerWork @Inject constructor(
|
|||||||
private val taskPath = config.taskPath
|
private val taskPath = config.taskPath
|
||||||
|
|
||||||
private val log: KotlinLogger =
|
private val log: KotlinLogger =
|
||||||
TaskLoggers.get(taskPath)?.let { GradleKotlinLogger(it) }
|
TaskLoggers.get(taskPath)?.let { GradleKotlinLogger(it).apply { debug("Using '$taskPath' logger") } }
|
||||||
?: run {
|
?: run {
|
||||||
System.err.println("Could not get logger for '$taskPath'. Falling back to sl4j logger")
|
val logger = LoggerFactory.getLogger("GradleKotlinCompilerWork")
|
||||||
SL4JKotlinLogger(LoggerFactory.getLogger("GradleKotlinCompilerWork"))
|
val kotlinLogger = if (logger is org.gradle.api.logging.Logger) {
|
||||||
|
GradleKotlinLogger(logger)
|
||||||
|
} else SL4JKotlinLogger(logger)
|
||||||
|
|
||||||
|
kotlinLogger.apply {
|
||||||
|
debug("Could not get logger for '$taskPath'. Falling back to sl4j logger")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val isIncremental: Boolean
|
private val isIncremental: Boolean
|
||||||
|
|||||||
Reference in New Issue
Block a user