KT-31840: Fix caching for incremental annotation processing
Artifact transform that uses ASM to analyze KAPT classpath stored absolute paths in the output artifact. This resulted in remote build cache misses. This commit changes how analysis is stored. Actual analysis file is the output of the transform, and there is not need to use a marker file any more. Output does not store the classpath entry absolute path. Instead, it uses task action incremental information to find analysis outputs that changed. Additionally, class that handles analysis snapshot comparison has been simplified, and lazy loading of the structural information is handled in a more straightforward way.
This commit is contained in:
committed by
Yan Zhulanow
parent
6963424dfc
commit
251d8ccd97
+6
-2
@@ -286,7 +286,12 @@ abstract class BaseGradleIT {
|
||||
build(*params, options = options.copy(kotlinDaemonDebugPort = debugPort), check = check)
|
||||
}
|
||||
|
||||
fun Project.build(vararg params: String, options: BuildOptions = defaultBuildOptions(), check: CompiledProject.() -> Unit) {
|
||||
fun Project.build(
|
||||
vararg params: String,
|
||||
options: BuildOptions = defaultBuildOptions(),
|
||||
projectDir: File = File(workingDir, projectName),
|
||||
check: CompiledProject.() -> Unit
|
||||
) {
|
||||
val wrapperVersion = chooseWrapperVersionOrFinishTest()
|
||||
|
||||
val env = createEnvironmentVariablesMap(options)
|
||||
@@ -295,7 +300,6 @@ abstract class BaseGradleIT {
|
||||
|
||||
println("<=== Test build: ${this.projectName} $cmd ===>")
|
||||
|
||||
val projectDir = File(workingDir, projectName)
|
||||
if (!projectDir.exists()) {
|
||||
setupWorkingDir()
|
||||
}
|
||||
|
||||
+24
-25
@@ -135,34 +135,33 @@ class BuildCacheIT : BaseGradleIT() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testKaptCachingEnabledByDefault() = with(Project("simple", GRADLE_VERSION, directoryPrefix = "kapt2")) {
|
||||
prepareLocalBuildCache()
|
||||
fun testKaptCachingWithIncrementalApt() {
|
||||
with(Project("kaptAvoidance", GRADLE_VERSION, directoryPrefix = "kapt2")) {
|
||||
prepareLocalBuildCache()
|
||||
|
||||
build("clean", "build") {
|
||||
assertSuccessful()
|
||||
assertContains("Packing task ':kaptGenerateStubsKotlin'")
|
||||
assertContains("Packing task ':kaptKotlin'")
|
||||
}
|
||||
|
||||
build("clean", "build") {
|
||||
assertSuccessful()
|
||||
assertContains(":kaptGenerateStubsKotlin FROM-CACHE")
|
||||
assertContains(":kaptKotlin FROM-CACHE")
|
||||
}
|
||||
|
||||
File(projectDir, "build.gradle").appendText(
|
||||
"\n" + """
|
||||
afterEvaluate {
|
||||
kaptKotlin.useBuildCache = false
|
||||
val options = defaultBuildOptions().copy(
|
||||
kaptOptions = KaptOptions(
|
||||
verbose = true,
|
||||
useWorkers = false,
|
||||
incrementalKapt = true,
|
||||
includeCompileClasspath = false
|
||||
)
|
||||
)
|
||||
build(options = options, params = *arrayOf("clean", ":app:build")) {
|
||||
assertSuccessful()
|
||||
assertContains("Packing task ':app:kaptGenerateStubsKotlin'")
|
||||
assertContains("Packing task ':app:kaptKotlin'")
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
build("clean", "build") {
|
||||
assertSuccessful()
|
||||
assertContains(":kaptGenerateStubsKotlin FROM-CACHE")
|
||||
assertNotContains(":kaptKotlin FROM-CACHE")
|
||||
assertContains("Caching disabled for task ':kaptKotlin': 'Caching is disabled for kapt")
|
||||
// copy project to a new location
|
||||
val copyProject = projectDir.resolveSibling("copy_${projectDir.name}").also { it.mkdirs() }
|
||||
copyRecursively(projectDir, copyProject)
|
||||
|
||||
build(options = options, projectDir = copyProject.resolve(projectName), params = *arrayOf("clean", "build")) {
|
||||
assertSuccessful()
|
||||
assertContains(":app:kaptGenerateStubsKotlin FROM-CACHE")
|
||||
assertContains(":app:kaptKotlin FROM-CACHE")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user