KT-34862: Clean up tests for incremental compilation after cache hit
Make sure that:
- Compilation with -Pkotlin.incremental.useClasspathSnapshot=true or
-Dkotlin.incremental.classpath.snapshot.enabled=true is incremental
after cache hit.
- Default compilation (using build history files) is non-incremental
after cache hit.
Also unify the related tests into
BuildCacheRelocationIT.testKotlinIncrementalCompilation*. We don't need
corresponding tests in BuildCacheIT because BuildCacheRelocationIT
already covers it.
This commit is contained in:
committed by
nataliya.valtman
parent
33931bf010
commit
39b7c6e326
+4
-8
@@ -37,19 +37,15 @@ data class BuildInfo(val startTS: Long, val dependencyToAbiSnapshot: Map<String,
|
||||
private fun ObjectOutputStream.writeBuildInfo(buildInfo: BuildInfo) {
|
||||
writeLong(buildInfo.startTS)
|
||||
writeInt(buildInfo.dependencyToAbiSnapshot.size)
|
||||
for((identifier, abiSnapshot) in buildInfo.dependencyToAbiSnapshot) {
|
||||
for ((identifier, abiSnapshot) in buildInfo.dependencyToAbiSnapshot) {
|
||||
writeUTF(identifier)
|
||||
writeAbiSnapshot(abiSnapshot)
|
||||
}
|
||||
}
|
||||
|
||||
fun read(file: File): BuildInfo? =
|
||||
try {
|
||||
ObjectInputStream(FileInputStream(file)).use {
|
||||
it.readBuildInfo()
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
fun read(file: File): BuildInfo =
|
||||
ObjectInputStream(FileInputStream(file)).use {
|
||||
it.readBuildInfo()
|
||||
}
|
||||
|
||||
fun write(buildInfo: BuildInfo, file: File) {
|
||||
|
||||
+3
-10
@@ -46,7 +46,7 @@ abstract class IncrementalCompilerRunner<
|
||||
private val workingDir: File,
|
||||
cacheDirName: String,
|
||||
protected val reporter: BuildReporter,
|
||||
private val buildHistoryFile: File,
|
||||
protected val buildHistoryFile: File,
|
||||
// there might be some additional output directories (e.g. for generated java in kapt)
|
||||
// to remove them correctly on rebuild, we pass them as additional argument
|
||||
private val additionalOutputFiles: Collection<File> = emptyList()
|
||||
@@ -129,15 +129,8 @@ abstract class IncrementalCompilerRunner<
|
||||
else -> providedChangedFiles
|
||||
}
|
||||
|
||||
// Check whether the cache directory is populated (note that it may be deleted upon a Gradle build cache hit if the directory is
|
||||
// marked as @LocalState in the Gradle task).
|
||||
val cacheDirectoryNotPopulated = cacheDirectory.walk().none { it.isFile }
|
||||
|
||||
val compilationMode = if (cacheDirectoryNotPopulated) {
|
||||
CompilationMode.Rebuild(BuildAttribute.CACHE_DIRECTORY_NOT_POPULATED)
|
||||
} else {
|
||||
sourcesToCompile(caches, changedFiles, args, messageCollector, classpathAbiSnapshot)
|
||||
}
|
||||
@Suppress("MoveVariableDeclarationIntoWhen")
|
||||
val compilationMode = sourcesToCompile(caches, changedFiles, args, messageCollector, classpathAbiSnapshot)
|
||||
|
||||
val exitCode = when (compilationMode) {
|
||||
is CompilationMode.Incremental -> {
|
||||
|
||||
+3
-1
@@ -118,8 +118,10 @@ class IncrementalJsCompilerRunner(
|
||||
messageCollector: MessageCollector,
|
||||
classpathAbiSnapshots: Map<String, AbiSnapshot> //Ignore for now
|
||||
): CompilationMode {
|
||||
if (!withSnapshot && !buildHistoryFile.isFile) {
|
||||
return CompilationMode.Rebuild(BuildAttribute.NO_BUILD_HISTORY)
|
||||
}
|
||||
val lastBuildInfo = BuildInfo.read(lastBuildInfoFile)
|
||||
?: return CompilationMode.Rebuild(BuildAttribute.NO_BUILD_HISTORY)
|
||||
|
||||
val dirtyFiles = DirtyFilesContainer(caches, reporter, kotlinSourceFilesExtensions)
|
||||
initDirtyFiles(dirtyFiles, changedFiles)
|
||||
|
||||
+8
-1
@@ -256,7 +256,14 @@ class IncrementalJvmCompilerRunner(
|
||||
is NotAvailableDueToMissingClasspathSnapshot -> ChangesEither.Unknown(BuildAttribute.CLASSPATH_SNAPSHOT_NOT_FOUND)
|
||||
is NotAvailableForNonIncrementalRun -> ChangesEither.Unknown(BuildAttribute.UNKNOWN_CHANGES_IN_GRADLE_INPUTS)
|
||||
is ClasspathSnapshotDisabled -> reporter.measure(BuildTime.IC_ANALYZE_CHANGES_IN_DEPENDENCIES) {
|
||||
val lastBuildInfo = BuildInfo.read(lastBuildInfoFile) ?: return CompilationMode.Rebuild(BuildAttribute.NO_BUILD_HISTORY)
|
||||
if (!withSnapshot && !buildHistoryFile.isFile) {
|
||||
// If the previous build was a Gradle cache hit, the build history file must have been deleted as it is marked as
|
||||
// @LocalState in the Gradle task. Therefore, this compilation will need to run non-incrementally.
|
||||
// (Note that buildHistoryFile is outside workingDir. We don't need to perform the same check for files inside
|
||||
// workingDir as workingDir is an @OutputDirectory, so the files must be present in an incremental build.)
|
||||
return CompilationMode.Rebuild(BuildAttribute.NO_BUILD_HISTORY)
|
||||
}
|
||||
val lastBuildInfo = BuildInfo.read(lastBuildInfoFile)
|
||||
reporter.reportVerbose { "Last Kotlin Build info -- $lastBuildInfo" }
|
||||
val scopes = caches.lookupCache.lookupSymbols.map { it.scope.ifBlank { it.name } }.distinct()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user