Delete daemon client file when Gradle process stops
#KT-17177 fixed
This commit is contained in:
+17
-4
@@ -16,12 +16,10 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.gradle
|
package org.jetbrains.kotlin.gradle
|
||||||
|
|
||||||
import org.jetbrains.kotlin.compilerRunner.COULD_NOT_CONNECT_TO_DAEMON_MESSAGE
|
import org.jetbrains.kotlin.compilerRunner.*
|
||||||
import org.jetbrains.kotlin.compilerRunner.CREATED_SESSION_FILE_PREFIX
|
|
||||||
import org.jetbrains.kotlin.compilerRunner.DELETED_SESSION_FILE_PREFIX
|
|
||||||
import org.jetbrains.kotlin.compilerRunner.EXISTING_SESSION_FILE_PREFIX
|
|
||||||
import org.junit.Assert
|
import org.junit.Assert
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
// todo: test client file creation/deletion
|
// todo: test client file creation/deletion
|
||||||
// todo: test daemon start (does not start every build)
|
// todo: test daemon start (does not start every build)
|
||||||
@@ -77,4 +75,19 @@ class KotlinDaemonIT : BaseGradleIT() {
|
|||||||
Assert.assertArrayEquals("Sessions should not be deleted (incremental build)", deletedSessions, emptyArray())
|
Assert.assertArrayEquals("Sessions should not be deleted (incremental build)", deletedSessions, emptyArray())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testClientFileIsDeletedOnExit() {
|
||||||
|
val project = Project("kotlinProject", GRADLE_VERSION)
|
||||||
|
val options = defaultBuildOptions().copy(withDaemon = false)
|
||||||
|
|
||||||
|
project.build("assemble", options = options) {
|
||||||
|
val regex = Regex("(?m)($CREATED_CLIENT_FILE_PREFIX|$EXISTING_CLIENT_FILE_PREFIX)(.+)$")
|
||||||
|
val clientFiles = regex.findAll(output).toList().map { File(it.groupValues[2]) }
|
||||||
|
assert(clientFiles.isNotEmpty()) { "No client files in log" }
|
||||||
|
clientFiles.forEach { clientFile ->
|
||||||
|
assert(!clientFile.exists()) { "Client file $clientFile is expected to be deleted!" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+4
-4
@@ -304,11 +304,11 @@ internal class GradleCompilerRunner(private val project: Project) : KotlinCompil
|
|||||||
val log = project.logger
|
val log = project.logger
|
||||||
if (clientIsAliveFlagFile == null || !clientIsAliveFlagFile!!.exists()) {
|
if (clientIsAliveFlagFile == null || !clientIsAliveFlagFile!!.exists()) {
|
||||||
val projectName = project.rootProject.name.normalizeForFlagFile()
|
val projectName = project.rootProject.name.normalizeForFlagFile()
|
||||||
clientIsAliveFlagFile = FileUtil.createTempFile("kotlin-compiler-in-$projectName-", ".alive")
|
clientIsAliveFlagFile = FileUtil.createTempFile("kotlin-compiler-in-$projectName-", ".alive", /*deleteOnExit =*/ true)
|
||||||
log.kotlinDebug { CREATED_CLIENT_FILE_PREFIX + clientIsAliveFlagFile!!.relativeToRoot(project) }
|
log.kotlinDebug { CREATED_CLIENT_FILE_PREFIX + clientIsAliveFlagFile!!.canonicalPath }
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
log.kotlinDebug { EXISTING_CLIENT_FILE_PREFIX + clientIsAliveFlagFile!!.relativeToRoot(project) }
|
log.kotlinDebug { EXISTING_CLIENT_FILE_PREFIX + clientIsAliveFlagFile!!.canonicalPath }
|
||||||
}
|
}
|
||||||
|
|
||||||
return clientIsAliveFlagFile!!
|
return clientIsAliveFlagFile!!
|
||||||
@@ -329,7 +329,7 @@ internal class GradleCompilerRunner(private val project: Project) : KotlinCompil
|
|||||||
val log = project.logger
|
val log = project.logger
|
||||||
if (sessionFlagFile == null || !sessionFlagFile!!.exists()) {
|
if (sessionFlagFile == null || !sessionFlagFile!!.exists()) {
|
||||||
val sessionFilesDir = sessionsDir(project).apply { mkdirs() }
|
val sessionFilesDir = sessionsDir(project).apply { mkdirs() }
|
||||||
sessionFlagFile = FileUtil.createTempFile(sessionFilesDir, "kotlin-compiler-", ".salive")
|
sessionFlagFile = FileUtil.createTempFile(sessionFilesDir, "kotlin-compiler-", ".salive", /*deleteOnExit =*/ true)
|
||||||
log.kotlinDebug { CREATED_SESSION_FILE_PREFIX + sessionFlagFile!!.relativeToRoot(project) }
|
log.kotlinDebug { CREATED_SESSION_FILE_PREFIX + sessionFlagFile!!.relativeToRoot(project) }
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
Reference in New Issue
Block a user