Move CacheFormatVersion to separate file

This commit is contained in:
Alexey Tsvetkov
2015-09-22 15:43:43 +03:00
parent 5c9b962567
commit 0904b4bae8
2 changed files with 66 additions and 46 deletions
@@ -0,0 +1,65 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.jps.incremental
import org.jetbrains.kotlin.config.IncrementalCompilation
import org.jetbrains.kotlin.jps.build.KotlinBuilder
import org.jetbrains.kotlin.load.java.JvmAbi
import java.io.File
class CacheFormatVersion(targetDataRoot: File) {
companion object {
// Change this when incremental cache format changes
private val INCREMENTAL_CACHE_OWN_VERSION = 5
private val CACHE_FORMAT_VERSION =
INCREMENTAL_CACHE_OWN_VERSION * 1000000 +
JvmAbi.VERSION.major * 1000 +
JvmAbi.VERSION.minor
private val NON_INCREMENTAL_MODE_PSEUDO_VERSION = Int.MAX_VALUE
val FORMAT_VERSION_FILE_PATH: String = "$CACHE_DIRECTORY_NAME/format-version.txt"
}
private val file = File(targetDataRoot, FORMAT_VERSION_FILE_PATH)
private fun actualCacheFormatVersion() = if (IncrementalCompilation.ENABLED) CACHE_FORMAT_VERSION else NON_INCREMENTAL_MODE_PSEUDO_VERSION
public fun isIncompatible(): Boolean {
if (!file.exists()) return false
val versionNumber = file.readText().toInt()
val expectedVersionNumber = actualCacheFormatVersion()
if (versionNumber != expectedVersionNumber) {
KotlinBuilder.LOG.info("Incompatible incremental cache version, expected $expectedVersionNumber, actual $versionNumber")
return true
}
return false
}
fun saveIfNeeded() {
if (file.parentFile.exists() && !file.exists()) {
file.writeText(actualCacheFormatVersion().toString())
}
}
fun clean() {
file.delete()
}
}
@@ -30,12 +30,10 @@ import org.jetbrains.jps.incremental.ModuleBuildTarget
import org.jetbrains.jps.incremental.storage.BuildDataManager
import org.jetbrains.jps.incremental.storage.PathStringDescriptor
import org.jetbrains.jps.incremental.storage.StorageOwner
import org.jetbrains.kotlin.config.IncrementalCompilation
import org.jetbrains.kotlin.jps.build.GeneratedJvmClass
import org.jetbrains.kotlin.jps.build.KotlinBuilder
import org.jetbrains.kotlin.jps.incremental.storage.BasicMap
import org.jetbrains.kotlin.jps.incremental.storage.BasicStringMap
import org.jetbrains.kotlin.load.java.JvmAbi
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
import org.jetbrains.kotlin.load.kotlin.ModuleMapping
import org.jetbrains.kotlin.load.kotlin.PackageClassUtils
@@ -56,52 +54,9 @@ import java.util.*
val INLINE_ANNOTATION_DESC = "Lkotlin/inline;"
private val CACHE_DIRECTORY_NAME = "kotlin"
internal val CACHE_DIRECTORY_NAME = "kotlin"
class CacheFormatVersion(targetDataRoot: File) {
companion object {
// Change this when incremental cache format changes
private val INCREMENTAL_CACHE_OWN_VERSION = 5
private val CACHE_FORMAT_VERSION =
INCREMENTAL_CACHE_OWN_VERSION * 1000000 +
JvmAbi.VERSION.major * 1000 +
JvmAbi.VERSION.minor
private val NON_INCREMENTAL_MODE_PSEUDO_VERSION = Int.MAX_VALUE
val FORMAT_VERSION_FILE_PATH: String = "$CACHE_DIRECTORY_NAME/format-version.txt"
}
private val file = File(targetDataRoot, FORMAT_VERSION_FILE_PATH)
private fun actualCacheFormatVersion() = if (IncrementalCompilation.ENABLED) CACHE_FORMAT_VERSION else NON_INCREMENTAL_MODE_PSEUDO_VERSION
public fun isIncompatible(): Boolean {
if (!file.exists()) return false
val versionNumber = file.readText().toInt()
val expectedVersionNumber = actualCacheFormatVersion()
if (versionNumber != expectedVersionNumber) {
KotlinBuilder.LOG.info("Incompatible incremental cache version, expected $expectedVersionNumber, actual $versionNumber")
return true
}
return false
}
fun saveIfNeeded() {
if (file.parentFile.exists() && !file.exists()) {
file.writeText(actualCacheFormatVersion().toString())
}
}
fun clean() {
file.delete()
}
}
public class IncrementalCacheImpl(
targetDataRoot: File,
private val target: ModuleBuildTarget