Make closing artifact difference registry more robust
KT-16298
This commit is contained in:
+35
-8
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile
|
|||||||
import org.jetbrains.kotlin.incremental.BuildCacheStorage
|
import org.jetbrains.kotlin.incremental.BuildCacheStorage
|
||||||
import org.jetbrains.kotlin.incremental.multiproject.ArtifactDifferenceRegistryProvider
|
import org.jetbrains.kotlin.incremental.multiproject.ArtifactDifferenceRegistryProvider
|
||||||
import org.jetbrains.kotlin.incremental.relativeToRoot
|
import org.jetbrains.kotlin.incremental.relativeToRoot
|
||||||
|
import org.jetbrains.kotlin.incremental.stackTraceStr
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
internal class KotlinGradleBuildServices private constructor(gradle: Gradle): BuildAdapter() {
|
internal class KotlinGradleBuildServices private constructor(gradle: Gradle): BuildAdapter() {
|
||||||
@@ -120,19 +121,45 @@ internal class KotlinGradleBuildServices private constructor(gradle: Gradle): Bu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
closeArtifactDifferenceRegistry()
|
||||||
if (workingDir.exists()) {
|
|
||||||
// The working directory may have been removed by the clean task.
|
|
||||||
// https://youtrack.jetbrains.com/issue/KT-16298
|
|
||||||
buildCacheStorage.flush(memoryCachesOnly = false)
|
|
||||||
}
|
|
||||||
buildCacheStorage.close()
|
|
||||||
|
|
||||||
gradle.removeListener(this)
|
gradle.removeListener(this)
|
||||||
instance = null
|
instance = null
|
||||||
log.kotlinDebug(DISPOSE_MESSAGE)
|
log.kotlinDebug(DISPOSE_MESSAGE)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun closeArtifactDifferenceRegistry() {
|
||||||
|
var caughtError = false
|
||||||
|
try {
|
||||||
|
if (workingDir.exists()) {
|
||||||
|
// The working directory may have been removed by the clean task.
|
||||||
|
// https://youtrack.jetbrains.com/issue/KT-16298
|
||||||
|
buildCacheStorage.flush(memoryCachesOnly = false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (e: Throwable) {
|
||||||
|
log.kotlinDebug { "Error trying to flush artifact difference registry: ${e.stackTraceStr}" }
|
||||||
|
caughtError = true
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
try {
|
||||||
|
buildCacheStorage.close()
|
||||||
|
}
|
||||||
|
catch (e: Throwable) {
|
||||||
|
log.kotlinDebug { "Error trying to close artifact difference registry: ${e.stackTraceStr}" }
|
||||||
|
caughtError = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (caughtError && workingDir.exists()) {
|
||||||
|
try {
|
||||||
|
workingDir.deleteRecursively()
|
||||||
|
}
|
||||||
|
catch (e: Throwable) {
|
||||||
|
log.kotlinDebug { "Error trying to delete kotlin-build $workingDir: ${e.stackTraceStr}" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun getUsedMemoryKb(): Long? {
|
private fun getUsedMemoryKb(): Long? {
|
||||||
if (!log.isDebugEnabled) return null
|
if (!log.isDebugEnabled) return null
|
||||||
|
|
||||||
|
|||||||
+7
-2
@@ -100,8 +100,13 @@ internal class BuildCacheStorage(workingDir: File) : BasicMapsOwner(), ArtifactD
|
|||||||
versionFile.delete()
|
versionFile.delete()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun close() {
|
override fun flush(memoryCachesOnly: Boolean) {
|
||||||
super.close()
|
super.flush(memoryCachesOnly)
|
||||||
version.saveIfNeeded()
|
version.saveIfNeeded()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun close() {
|
||||||
|
super.close()
|
||||||
|
artifactDifferenceRegistry = null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user