KT-49780 Do not clean outputs after cache corruption

This commit is contained in:
nataliya.valtman
2022-05-13 13:18:17 +03:00
committed by Space
parent 6c994787b3
commit dcdd1cd14e
2 changed files with 77 additions and 2 deletions
@@ -189,8 +189,10 @@ abstract class IncrementalCompilerRunner<
return exitCode
} catch (e: Exception) { // todo: catch only cache corruption
// todo: warn?
reporter.report { "Rebuilding because of possible caches corruption: $e" }
rebuild(BuildAttribute.CACHE_CORRUPTION)
reporter.report { "Possible caches corruption: $e" }
rebuild(BuildAttribute.CACHE_CORRUPTION).also {
cachesMayBeCorrupted = false
}
} finally {
if (cachesMayBeCorrupted) {
cleanOutputsAndLocalStateOnRebuild(args)
@@ -4,6 +4,7 @@ import org.gradle.testkit.runner.BuildResult
import org.gradle.util.GradleVersion
import org.jetbrains.kotlin.gradle.testbase.*
import org.jetbrains.kotlin.gradle.util.checkedReplace
import org.jetbrains.kotlin.test.KtAssert.assertTrue
import org.junit.jupiter.api.DisplayName
import java.nio.file.Path
import kotlin.io.path.*
@@ -32,6 +33,13 @@ class IncrementalCompilationJsMultiProjectIT : BaseIncrementalCompilationMultiPr
override val compileKotlinTaskName: String
get() = "compileKotlin2Js"
override val compileCacheFolderName: String
get() = "caches-js"
//compileKotlin2Js's modification doe not work
override fun testIncrementalBuildWithCompilationError(gradleVersion: GradleVersion) {}
override fun testValidOutputsWithCacheCorrupted(gradleVersion: GradleVersion) {}
}
@JvmGradlePluginTests
@@ -42,6 +50,9 @@ open class IncrementalCompilationJvmMultiProjectIT : BaseIncrementalCompilationM
override val compileKotlinTaskName: String
get() = "compileKotlin"
override val compileCacheFolderName: String
get() = "caches-jvm"
override val defaultProjectName: String = "incrementalMultiproject"
// todo: do the same for js backend
@@ -262,6 +273,8 @@ abstract class BaseIncrementalCompilationMultiProjectIT : IncrementalCompilation
protected abstract val compileKotlinTaskName: String
protected abstract val compileCacheFolderName: String
protected abstract val additionalLibDependencies: String
protected fun TestProject.changeMethodSignatureInLib() {
@@ -648,4 +661,64 @@ abstract class BaseIncrementalCompilationMultiProjectIT : IncrementalCompilation
}
}
}
@DisplayName("KT-49780: Valid outputs after cache corruption exception")
@GradleTest
open fun testValidOutputsWithCacheCorrupted(gradleVersion: GradleVersion) {
defaultProject(gradleVersion) {
breakCachesAfterCompileKotlinExecution(this)
build("assemble")
subProject("lib").kotlinSourcesDir().resolve("bar/B.kt").modify {
it.replace("fun b() {}", "fun b() = 123")
}
build("assemble") {
assertOutputContains("Non-incremental compilation will be performed: CACHE_CORRUPTION")
}
val lookupFile = projectPath.resolve("lib/build/kotlin/${compileKotlinTaskName}/cacheable/${compileCacheFolderName}/lookups/file-to-id.tab")
assertTrue("Output is empty", lookupFile.exists())
}
}
@DisplayName("KT-49780: No need to rebuild invalid code due to cache corruption")
@GradleTest
open fun testIncrementalBuildWithCompilationError(gradleVersion: GradleVersion) {
defaultProject(gradleVersion) {
breakCachesAfterCompileKotlinExecution(this)
build("assemble")
subProject("lib").kotlinSourcesDir().resolve("bar/B.kt").modify {
it.replace("fun b() {}", "fun a() = 123")
}
buildAndFail("assemble") {
printBuildOutput()
assertOutputDoesNotContain("Possible caches corruption:")
assertOutputDoesNotContain("Non-incremental compilation will be performed:")
}
}
}
private fun breakCachesAfterCompileKotlinExecution(testProject: TestProject) {
listOf("app", "lib").forEach {
testProject.subProject(it).buildGradle.appendText(
"""
$compileKotlinTaskName {
doLast {
def file = new File(projectDir.path, "/build/kotlin/${compileKotlinTaskName}/cacheable/${compileCacheFolderName}/lookups/file-to-id.tab")
println("Update lookup file " + file.path)
file.write("la-la")
}
}
""".trimIndent()
)
}
}
}