KT-34862: Add kotlin build dir as output

build history files are non cacheable outputs
#KT-34862
This commit is contained in:
nataliya.valtman
2022-01-12 15:17:35 +03:00
committed by Space
parent 7c9000b8ac
commit 56207abc27
3 changed files with 41 additions and 17 deletions
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.gradle.testbase.*
import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.DisplayName
import kotlin.io.path.ExperimentalPathApi import kotlin.io.path.ExperimentalPathApi
import kotlin.io.path.readText import kotlin.io.path.readText
import kotlin.io.path.relativeTo
import kotlin.io.path.writeText import kotlin.io.path.writeText
@ExperimentalPathApi @ExperimentalPathApi
@@ -147,4 +148,29 @@ class BuildCacheIT : KGPBaseTest() {
} }
} }
} }
//doesn't work for build history files approach
@DisplayName("Restore from build cache should not break incremental compilation")
@GradleTest
fun testIncrementalCompilationAfterCacheHit(gradleVersion: GradleVersion) {
val withSnapshotProperty = "-Dkotlin.incremental.classpath.snapshot.enabled=true"
project("incrementalMultiproject", gradleVersion) {
enableLocalBuildCache(localBuildCacheDir)
build("assemble", withSnapshotProperty)
build("clean", "assemble", withSnapshotProperty) {
assertTasksFromCache(":lib:compileKotlin")
assertTasksFromCache(":app:compileKotlin")
}
val bKtSourceFile = projectPath.resolve("lib/src/main/kotlin/bar/B.kt")
bKtSourceFile.modify { it.replace("fun b() {}", "fun b() {}\nfun b2() {}") }
build("assemble", withSnapshotProperty, buildOptions = defaultBuildOptions.copy(logLevel = LogLevel.DEBUG)) {
assertOutputDoesNotContain("[KOTLIN] [IC] Non-incremental compilation will be performed")
assertCompiledKotlinSources(setOf(bKtSourceFile).map { it.relativeTo(projectPath)}, output)
}
}
}
} }
@@ -309,15 +309,6 @@ internal open class GradleCompilerRunner(
jarToModule[it] = module jarToModule[it] = module
} }
} }
// for (target in task.targets) {
// if (target is KotlinWithJavaTarget<*>) {
// val jar = project.tasks.getByName(target.artifactsTaskName) as Jar
// jarToClassListFile[jar.archivePathCompatible.canonicalFile] = target.defaultArtifactClassesListFile.get()
// //configure abiSnapshot mapping for jars
// jarToAbiSnapshot[jar.archivePathCompatible.canonicalFile] =
// target.buildDir.get().file(task.abiSnapshotRelativePath).asFile
// }
// }
} else if (task is InspectClassesForMultiModuleIC) { } else if (task is InspectClassesForMultiModuleIC) {
jarToClassListFile[File(task.archivePath.get())] = task.classesListFile jarToClassListFile[File(task.archivePath.get())] = task.classesListFile
} }
@@ -199,8 +199,10 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments> : AbstractKotl
project.plugins.any { it is KotlinPlatformPluginBase || it is KotlinMultiplatformPluginWrapper || it is KotlinPm20PluginWrapper } project.plugins.any { it is KotlinPlatformPluginBase || it is KotlinMultiplatformPluginWrapper || it is KotlinPm20PluginWrapper }
} }
).disallowChanges() ).disallowChanges()
task.taskBuildDirectory.value(getKotlinBuildDir(task)).disallowChanges() task.taskBuildCacheableOutputDirectory.value(getKotlinBuildDir(task).map { it.dir("cacheable") }).disallowChanges()
task.localStateDirectories.from(task.taskBuildDirectory).disallowChanges() task.taskBuildLocalStateDirectory.value(getKotlinBuildDir(task).map { it.dir("localstate") }).disallowChanges()
task.localStateDirectories.from(task.taskBuildLocalStateDirectory, task.taskBuildCacheableOutputDirectory).disallowChanges()
PropertiesProvider(task.project).mapKotlinDaemonProperties(task) PropertiesProvider(task.project).mapKotlinDaemonProperties(task)
} }
@@ -224,13 +226,17 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments> : AbstractKotl
@get:Internal @get:Internal
protected val objects: ObjectFactory = project.objects protected val objects: ObjectFactory = project.objects
// avoid creating directory in getter: this can lead to failure in parallel build
@get:OutputDirectory
internal val taskBuildCacheableOutputDirectory: DirectoryProperty = objects.directoryProperty()
// avoid creating directory in getter: this can lead to failure in parallel build // avoid creating directory in getter: this can lead to failure in parallel build
@get:LocalState @get:LocalState
internal val taskBuildDirectory: DirectoryProperty = objects.directoryProperty() internal val taskBuildLocalStateDirectory: DirectoryProperty = objects.directoryProperty()
@get:Internal @get:Internal
internal val buildHistoryFile internal val buildHistoryFile
get() = taskBuildDirectory.file("build-history.bin") get() = taskBuildLocalStateDirectory.file("build-history.bin")
// indicates that task should compile kotlin incrementally if possible // indicates that task should compile kotlin incrementally if possible
// it's not possible when IncrementalTaskInputs#isIncremental returns false (i.e first build) // it's not possible when IncrementalTaskInputs#isIncremental returns false (i.e first build)
@@ -300,7 +306,7 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments> : AbstractKotl
@get:Internal @get:Internal
val abiSnapshotFile val abiSnapshotFile
get() = taskBuildDirectory.file(IncrementalCompilerRunner.ABI_SNAPSHOT_FILE_NAME) get() = taskBuildCacheableOutputDirectory.file(IncrementalCompilerRunner.ABI_SNAPSHOT_FILE_NAME)
@get:Input @get:Input
val abiSnapshotRelativePath: Property<String> = objects.property(String::class.java).value( val abiSnapshotRelativePath: Property<String> = objects.property(String::class.java).value(
@@ -419,7 +425,8 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments> : AbstractKotl
sourceRoots.log(this.name, logger) sourceRoots.log(this.name, logger)
val args = prepareCompilerArguments() val args = prepareCompilerArguments()
taskBuildDirectory.get().asFile.mkdirs() taskBuildCacheableOutputDirectory.get().asFile.mkdirs()
taskBuildLocalStateDirectory.get().asFile.mkdirs()
callCompilerAsync( callCompilerAsync(
args, args,
sourceRoots, sourceRoots,
@@ -758,7 +765,7 @@ abstract class KotlinCompile @Inject constructor(
IncrementalCompilationEnvironment( IncrementalCompilationEnvironment(
changedFiles = getChangedFiles(inputChanges, incrementalProps), changedFiles = getChangedFiles(inputChanges, incrementalProps),
classpathChanges = getClasspathChanges(inputChanges), classpathChanges = getClasspathChanges(inputChanges),
workingDir = taskBuildDirectory.get().asFile, workingDir = taskBuildCacheableOutputDirectory.get().asFile,
usePreciseJavaTracking = usePreciseJavaTracking, usePreciseJavaTracking = usePreciseJavaTracking,
disableMultiModuleIC = disableMultiModuleIC, disableMultiModuleIC = disableMultiModuleIC,
multiModuleICSettings = multiModuleICSettings multiModuleICSettings = multiModuleICSettings
@@ -1129,7 +1136,7 @@ abstract class Kotlin2JsCompile @Inject constructor(
IncrementalCompilationEnvironment( IncrementalCompilationEnvironment(
getChangedFiles(inputChanges, incrementalProps), getChangedFiles(inputChanges, incrementalProps),
ClasspathChanges.NotAvailableForJSCompiler, ClasspathChanges.NotAvailableForJSCompiler,
taskBuildDirectory.get().asFile, taskBuildCacheableOutputDirectory.get().asFile,
multiModuleICSettings = multiModuleICSettings multiModuleICSettings = multiModuleICSettings
) )
} else null } else null