Fix Gradle IC cache version checking

This commit is contained in:
Alexey Tsvetkov
2017-08-24 02:42:24 +03:00
parent cf72b14b34
commit 66a77c7ec2
5 changed files with 22 additions and 16 deletions
@@ -95,18 +95,18 @@ class CacheVersion(
}
}
fun normalCacheVersion(dataRoot: File): CacheVersion =
fun normalCacheVersion(dataRoot: File, enabled: Boolean? = null): CacheVersion =
CacheVersion(ownVersion = NORMAL_VERSION,
versionFile = File(dataRoot, NORMAL_VERSION_FILE_NAME),
whenVersionChanged = CacheVersion.Action.REBUILD_CHUNK,
whenTurnedOn = CacheVersion.Action.REBUILD_CHUNK,
whenTurnedOff = CacheVersion.Action.CLEAN_NORMAL_CACHES,
isEnabled = { IncrementalCompilation.isEnabled() })
isEnabled = { enabled ?: IncrementalCompilation.isEnabled() })
fun dataContainerCacheVersion(dataRoot: File): CacheVersion =
fun dataContainerCacheVersion(dataRoot: File, enabled: Boolean? = null): CacheVersion =
CacheVersion(ownVersion = DATA_CONTAINER_VERSION,
versionFile = File(dataRoot, DATA_CONTAINER_VERSION_FILE_NAME),
whenVersionChanged = CacheVersion.Action.REBUILD_ALL_KOTLIN,
whenTurnedOn = CacheVersion.Action.REBUILD_ALL_KOTLIN,
whenTurnedOff = CacheVersion.Action.CLEAN_DATA_CONTAINER,
isEnabled = { IncrementalCompilation.isEnabled() })
isEnabled = { enabled ?: IncrementalCompilation.isEnabled() })
@@ -448,7 +448,10 @@ class CompileServiceImpl(
val workingDir = incrementalCompilationOptions.workingDir
val versions = commonCacheVersions(workingDir) +
customCacheVersion(incrementalCompilationOptions.customCacheVersion, incrementalCompilationOptions.customCacheVersionFileName, workingDir, forceEnable = true)
customCacheVersion(incrementalCompilationOptions.customCacheVersion,
incrementalCompilationOptions.customCacheVersionFileName,
workingDir,
enabled = true)
return IncrementalJsCompilerRunner(workingDir, versions, reporter)
.compile(allKotlinFiles, args, compilerMessageCollector, { changedFiles })
@@ -499,7 +502,10 @@ class CompileServiceImpl(
val workingDir = incrementalCompilationOptions.workingDir
val versions = commonCacheVersions(workingDir) +
customCacheVersion(incrementalCompilationOptions.customCacheVersion, incrementalCompilationOptions.customCacheVersionFileName, workingDir, forceEnable = true)
customCacheVersion(incrementalCompilationOptions.customCacheVersion,
incrementalCompilationOptions.customCacheVersionFileName,
workingDir,
enabled = true)
return IncrementalJvmCompilerRunner(workingDir, javaSourceRoots, versions, reporter, annotationFileUpdater,
artifactChanges, changesRegistry)
@@ -16,22 +16,21 @@
package org.jetbrains.kotlin.incremental
import org.jetbrains.kotlin.config.IncrementalCompilation
import java.io.File
internal const val STANDALONE_CACHE_VERSION = 2
internal const val STANDALONE_VERSION_FILE_NAME = "standalone-ic-format-version.txt"
fun standaloneCacheVersion(dataRoot: File): CacheVersion =
customCacheVersion(STANDALONE_CACHE_VERSION, STANDALONE_VERSION_FILE_NAME, dataRoot)
customCacheVersion(STANDALONE_CACHE_VERSION, STANDALONE_VERSION_FILE_NAME, dataRoot, enabled = true)
fun customCacheVersion(version: Int, fileName: String, dataRoot: File, forceEnable: Boolean = false): CacheVersion =
fun customCacheVersion(version: Int, fileName: String, dataRoot: File, enabled: Boolean): CacheVersion =
CacheVersion(ownVersion = version,
versionFile = File(dataRoot, fileName),
whenVersionChanged = CacheVersion.Action.REBUILD_ALL_KOTLIN,
whenTurnedOn = CacheVersion.Action.REBUILD_ALL_KOTLIN,
whenTurnedOff = CacheVersion.Action.REBUILD_ALL_KOTLIN,
isEnabled = { IncrementalCompilation.isEnabled() || forceEnable })
isEnabled = { enabled })
fun commonCacheVersions(cachesDir: File): List<CacheVersion> =
listOf(normalCacheVersion(cachesDir),
@@ -67,10 +67,11 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments>() : AbstractKo
internal val taskBuildDirectory: File
get() = File(File(project.buildDir, KOTLIN_BUILD_DIR_NAME), name).apply { mkdirs() }
private val cacheVersions: List<CacheVersion> =
listOf(normalCacheVersion(taskBuildDirectory),
dataContainerCacheVersion(taskBuildDirectory),
gradleCacheVersion(taskBuildDirectory))
private val cacheVersions: List<CacheVersion>
get() =
listOf(normalCacheVersion(taskBuildDirectory, enabled = incremental),
dataContainerCacheVersion(taskBuildDirectory, enabled = incremental),
gradleCacheVersion(taskBuildDirectory, enabled = incremental))
// indicates that task should compile kotlin incrementally if possible
// it's not possible when IncrementalTaskInputs#isIncremental returns false (i.e first build)
@@ -21,5 +21,5 @@ import java.io.File
internal const val GRADLE_CACHE_VERSION = 4
internal const val GRADLE_CACHE_VERSION_FILE_NAME = "gradle-format-version.txt"
internal fun gradleCacheVersion(dataRoot: File): CacheVersion =
customCacheVersion(GRADLE_CACHE_VERSION, GRADLE_CACHE_VERSION_FILE_NAME, dataRoot)
internal fun gradleCacheVersion(dataRoot: File, enabled: Boolean): CacheVersion =
customCacheVersion(GRADLE_CACHE_VERSION, GRADLE_CACHE_VERSION_FILE_NAME, dataRoot, enabled)