IC: move CacheVersionManager from build_common to jps plugin
This commit is contained in:
-33
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.incremental.storage.version
|
||||
|
||||
/**
|
||||
* Diff between actual and expected cache attributes.
|
||||
* [status] are calculated based on this diff (see [CacheStatus]).
|
||||
* Based on that [status] system may perform required actions (i.e. rebuild something, clearing caches, etc...).
|
||||
*
|
||||
* [CacheAttributesDiff] can be used to cache current attribute values and as facade for version operations.
|
||||
*/
|
||||
data class CacheAttributesDiff<Attrs: Any>(
|
||||
val manager: CacheAttributesManager<Attrs>,
|
||||
val actual: Attrs?,
|
||||
val expected: Attrs?
|
||||
) {
|
||||
val status: CacheStatus
|
||||
get() =
|
||||
if (expected != null) {
|
||||
if (actual != null && manager.isCompatible(actual, expected)) CacheStatus.VALID
|
||||
else CacheStatus.INVALID
|
||||
} else {
|
||||
if (actual != null) CacheStatus.SHOULD_BE_CLEARED
|
||||
else CacheStatus.CLEARED
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return "$status: actual=$actual -> expected=$expected"
|
||||
}
|
||||
}
|
||||
-62
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.incremental.storage.version
|
||||
|
||||
/**
|
||||
* Manages cache attributes values.
|
||||
*
|
||||
* Attribute values can be loaded by calling [loadActual].
|
||||
* Based on loaded actual and fixed [expected] values [CacheAttributesDiff] can be constructed which can calculate [CacheStatus].
|
||||
* Build system may perform required actions based on that (i.e. rebuild something, clearing caches, etc...).
|
||||
*
|
||||
* [CacheAttributesDiff] can be used to cache current attribute values and then can be used as facade for cache version operations.
|
||||
*/
|
||||
interface CacheAttributesManager<Attrs : Any> {
|
||||
/**
|
||||
* Cache attribute values expected by the current version of build system and compiler.
|
||||
* `null` means that cache is not required (incremental compilation is disabled).
|
||||
*/
|
||||
val expected: Attrs?
|
||||
|
||||
/**
|
||||
* Load actual cache attribute values.
|
||||
* `null` means that cache is not yet created.
|
||||
*
|
||||
* This is internal operation that should be implemented by particular implementation of CacheAttributesManager.
|
||||
* Consider using `loadDiff().actual` for getting actual values.
|
||||
*/
|
||||
fun loadActual(): Attrs?
|
||||
|
||||
/**
|
||||
* Write [values] as cache attributes for next build execution.
|
||||
*/
|
||||
fun writeVersion(values: Attrs? = expected)
|
||||
|
||||
/**
|
||||
* Check if cache with [actual] attributes values can be used when [expected] attributes are required.
|
||||
*/
|
||||
fun isCompatible(actual: Attrs, expected: Attrs): Boolean = actual == expected
|
||||
}
|
||||
|
||||
fun <Attrs : Any> CacheAttributesManager<Attrs>.loadDiff(
|
||||
actual: Attrs? = this.loadActual(),
|
||||
expected: Attrs? = this.expected
|
||||
) = CacheAttributesDiff(this, actual, expected)
|
||||
|
||||
fun <Attrs : Any> CacheAttributesManager<Attrs>.loadAndCheckStatus() =
|
||||
loadDiff().status
|
||||
|
||||
/**
|
||||
* This method is kept only for compatibility.
|
||||
* Delete actual cache attributes values if it existed.
|
||||
*/
|
||||
@Deprecated(
|
||||
message = "Consider using `this.loadDiff().saveExpectedIfNeeded()` and cache `loadDiff()` result.",
|
||||
replaceWith = ReplaceWith("writeVersion(null)")
|
||||
)
|
||||
fun CacheAttributesManager<*>.clean() {
|
||||
writeVersion(null)
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.incremental.storage.version
|
||||
|
||||
/**
|
||||
* Status that is used by system to perform required actions (i.e. rebuild something, clearing caches, etc...).
|
||||
*/
|
||||
enum class CacheStatus {
|
||||
/**
|
||||
* Cache is valid and ready to use.
|
||||
*/
|
||||
VALID,
|
||||
|
||||
/**
|
||||
* Cache is not exists or have outdated versions and/or other attributes.
|
||||
*/
|
||||
INVALID,
|
||||
|
||||
/**
|
||||
* Cache is exists, but not required anymore.
|
||||
*/
|
||||
SHOULD_BE_CLEARED,
|
||||
|
||||
/**
|
||||
* Cache is not exists and not required.
|
||||
*/
|
||||
CLEARED
|
||||
}
|
||||
-60
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.incremental.storage.version
|
||||
|
||||
import org.jetbrains.annotations.TestOnly
|
||||
import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmBytecodeBinaryVersion
|
||||
import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmMetadataVersion
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
|
||||
/**
|
||||
* Manages files with actual version [loadActual] and provides expected version [expected].
|
||||
* Based on that actual and expected versions [CacheStatus] can be calculated.
|
||||
* This can be done by constructing [CacheAttributesDiff] and calling [CacheAttributesDiff.status].
|
||||
* Based on that status system may perform required actions (i.e. rebuild something, clearing caches, etc...).
|
||||
*/
|
||||
class CacheVersionManager(
|
||||
private val versionFile: File,
|
||||
expectedOwnVersion: Int?
|
||||
) : CacheAttributesManager<CacheVersion> {
|
||||
override val expected: CacheVersion? =
|
||||
if (expectedOwnVersion == null) null
|
||||
else {
|
||||
val metadata = JvmMetadataVersion.INSTANCE
|
||||
val bytecode = JvmBytecodeBinaryVersion.INSTANCE
|
||||
|
||||
CacheVersion(
|
||||
expectedOwnVersion * 1000000 +
|
||||
bytecode.major * 10000 + bytecode.minor * 100 +
|
||||
metadata.major * 1000 + metadata.minor
|
||||
)
|
||||
}
|
||||
|
||||
override fun loadActual(): CacheVersion? =
|
||||
if (!versionFile.exists()) null
|
||||
else try {
|
||||
CacheVersion(versionFile.readText().toInt())
|
||||
} catch (e: NumberFormatException) {
|
||||
null
|
||||
} catch (e: IOException) {
|
||||
null
|
||||
}
|
||||
|
||||
override fun writeVersion(values: CacheVersion?) {
|
||||
if (values == null) versionFile.delete()
|
||||
else {
|
||||
versionFile.parentFile.mkdirs()
|
||||
versionFile.writeText(values.version.toString())
|
||||
}
|
||||
}
|
||||
|
||||
@get:TestOnly
|
||||
val versionFileForTesting: File
|
||||
get() = versionFile
|
||||
}
|
||||
|
||||
data class CacheVersion(val version: Int)
|
||||
@@ -1,17 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.incremental.storage.version
|
||||
|
||||
import java.io.File
|
||||
|
||||
private val NORMAL_VERSION = 9
|
||||
private val NORMAL_VERSION_FILE_NAME = "format-version.txt"
|
||||
|
||||
fun localCacheVersionManager(dataRoot: File, isCachesEnabled: Boolean) =
|
||||
CacheVersionManager(
|
||||
File(dataRoot, NORMAL_VERSION_FILE_NAME),
|
||||
if (isCachesEnabled) NORMAL_VERSION else null
|
||||
)
|
||||
@@ -1,17 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.incremental.storage.version
|
||||
|
||||
import java.io.File
|
||||
|
||||
private val DATA_CONTAINER_VERSION_FILE_NAME = "data-container-format-version.txt"
|
||||
private val DATA_CONTAINER_VERSION = 3
|
||||
|
||||
fun lookupsCacheVersionManager(dataRoot: File, isEnabled: Boolean) =
|
||||
CacheVersionManager(
|
||||
File(dataRoot, DATA_CONTAINER_VERSION_FILE_NAME),
|
||||
if (isEnabled) DATA_CONTAINER_VERSION else null
|
||||
)
|
||||
Reference in New Issue
Block a user