Allow customizing source file path conversion in local IC caches
This commit is contained in:
@@ -19,10 +19,7 @@ package org.jetbrains.kotlin.incremental
|
||||
import com.intellij.util.io.DataExternalizer
|
||||
import org.jetbrains.kotlin.incremental.js.IncrementalResultsConsumerImpl
|
||||
import org.jetbrains.kotlin.incremental.js.TranslationResultValue
|
||||
import org.jetbrains.kotlin.incremental.storage.BasicStringMap
|
||||
import org.jetbrains.kotlin.incremental.storage.DirtyClassesFqNameMap
|
||||
import org.jetbrains.kotlin.incremental.storage.SourceToFqNameMap
|
||||
import org.jetbrains.kotlin.incremental.storage.StringToLongMapExternalizer
|
||||
import org.jetbrains.kotlin.incremental.storage.*
|
||||
import org.jetbrains.kotlin.metadata.ProtoBuf
|
||||
import org.jetbrains.kotlin.metadata.deserialization.NameResolverImpl
|
||||
import org.jetbrains.kotlin.metadata.deserialization.getExtensionOrNull
|
||||
@@ -36,19 +33,22 @@ import java.io.DataInput
|
||||
import java.io.DataOutput
|
||||
import java.io.File
|
||||
|
||||
open class IncrementalJsCache(cachesDir: File) : AbstractIncrementalCache<FqName>(cachesDir) {
|
||||
open class IncrementalJsCache(
|
||||
cachesDir: File,
|
||||
sourcePathConverter: SourceFileToPathConverter
|
||||
) : AbstractIncrementalCache<FqName>(cachesDir, sourcePathConverter) {
|
||||
companion object {
|
||||
private val TRANSLATION_RESULT_MAP = "translation-result"
|
||||
private val INLINE_FUNCTIONS = "inline-functions"
|
||||
private val HEADER_FILE_NAME = "header.meta"
|
||||
private const val TRANSLATION_RESULT_MAP = "translation-result"
|
||||
private const val INLINE_FUNCTIONS = "inline-functions"
|
||||
private const val HEADER_FILE_NAME = "header.meta"
|
||||
|
||||
fun hasHeaderFile(cachesDir: File) = File(cachesDir, HEADER_FILE_NAME).exists()
|
||||
}
|
||||
|
||||
override val sourceToClassesMap = registerMap(SourceToFqNameMap(SOURCE_TO_CLASSES.storageFile))
|
||||
override val sourceToClassesMap = registerMap(SourceToFqNameMap(SOURCE_TO_CLASSES.storageFile, sourcePathConverter))
|
||||
override val dirtyOutputClassesMap = registerMap(DirtyClassesFqNameMap(DIRTY_OUTPUT_CLASSES.storageFile))
|
||||
private val translationResults = registerMap(TranslationResultMap(TRANSLATION_RESULT_MAP.storageFile))
|
||||
private val inlineFunctions = registerMap(InlineFunctionsMap(INLINE_FUNCTIONS.storageFile))
|
||||
private val translationResults = registerMap(TranslationResultMap(TRANSLATION_RESULT_MAP.storageFile, sourcePathConverter))
|
||||
private val inlineFunctions = registerMap(InlineFunctionsMap(INLINE_FUNCTIONS.storageFile, sourcePathConverter))
|
||||
|
||||
private val dirtySources = hashSetOf<File>()
|
||||
|
||||
@@ -113,14 +113,14 @@ open class IncrementalJsCache(cachesDir: File) : AbstractIncrementalCache<FqName
|
||||
}
|
||||
|
||||
fun nonDirtyPackageParts(): Map<File, TranslationResultValue> =
|
||||
hashMapOf<File, TranslationResultValue>().apply {
|
||||
for (path in translationResults.keys()) {
|
||||
val file = File(path)
|
||||
if (file !in dirtySources) {
|
||||
put(file, translationResults[path]!!)
|
||||
}
|
||||
hashMapOf<File, TranslationResultValue>().apply {
|
||||
for (path in translationResults.keys()) {
|
||||
val file = File(path)
|
||||
if (file !in dirtySources) {
|
||||
put(file, translationResults[file]!!)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private object TranslationResultValueExternalizer : DataExternalizer<TranslationResultValue> {
|
||||
@@ -152,31 +152,33 @@ private object TranslationResultValueExternalizer : DataExternalizer<Translation
|
||||
}
|
||||
}
|
||||
|
||||
private class TranslationResultMap(storageFile: File) : BasicStringMap<TranslationResultValue>(storageFile, TranslationResultValueExternalizer) {
|
||||
private class TranslationResultMap(
|
||||
storageFile: File,
|
||||
private val sourcePathConverter: SourceFileToPathConverter
|
||||
) : BasicStringMap<TranslationResultValue>(storageFile, TranslationResultValueExternalizer) {
|
||||
override fun dumpValue(value: TranslationResultValue): String =
|
||||
"Metadata: ${value.metadata.md5()}, Binary AST: ${value.binaryAst.md5()}, InlineData: ${value.inlineData.md5()}"
|
||||
"Metadata: ${value.metadata.md5()}, Binary AST: ${value.binaryAst.md5()}, InlineData: ${value.inlineData.md5()}"
|
||||
|
||||
fun put(file: File, newMetadata: ByteArray, newBinaryAst: ByteArray, newInlineData: ByteArray) {
|
||||
storage[file.canonicalPath] = TranslationResultValue(metadata = newMetadata, binaryAst = newBinaryAst, inlineData = newInlineData)
|
||||
fun put(sourceFile: File, newMetadata: ByteArray, newBinaryAst: ByteArray, newInlineData: ByteArray) {
|
||||
storage[sourcePathConverter.toPath(sourceFile)] =
|
||||
TranslationResultValue(metadata = newMetadata, binaryAst = newBinaryAst, inlineData = newInlineData)
|
||||
}
|
||||
|
||||
operator fun get(file: File): TranslationResultValue? =
|
||||
storage[file.canonicalPath]
|
||||
|
||||
operator fun get(key: String): TranslationResultValue? =
|
||||
storage[key]
|
||||
operator fun get(sourceFile: File): TranslationResultValue? =
|
||||
storage[sourcePathConverter.toPath(sourceFile)]
|
||||
|
||||
fun keys(): Collection<String> =
|
||||
storage.keys
|
||||
storage.keys
|
||||
|
||||
fun remove(file: File, changesCollector: ChangesCollector) {
|
||||
val protoBytes = storage[file.canonicalPath]!!.metadata
|
||||
val protoMap = getProtoData(file, protoBytes)
|
||||
fun remove(sourceFile: File, changesCollector: ChangesCollector) {
|
||||
val path = sourcePathConverter.toPath(sourceFile)
|
||||
val protoBytes = storage[path]!!.metadata
|
||||
val protoMap = getProtoData(sourceFile, protoBytes)
|
||||
|
||||
for ((_, protoData) in protoMap) {
|
||||
changesCollector.collectProtoChanges(oldData = protoData, newData = null)
|
||||
}
|
||||
storage.remove(file.canonicalPath)
|
||||
storage.remove(path)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,15 +201,17 @@ fun getProtoData(sourceFile: File, metadata: ByteArray): Map<ClassId, ProtoData>
|
||||
return classes
|
||||
}
|
||||
|
||||
private class InlineFunctionsMap(storageFile: File) : BasicStringMap<Map<String, Long>>(storageFile, StringToLongMapExternalizer) {
|
||||
private class InlineFunctionsMap(
|
||||
storageFile: File,
|
||||
private val sourcePathConverter: SourceFileToPathConverter
|
||||
) : BasicStringMap<Map<String, Long>>(storageFile, StringToLongMapExternalizer) {
|
||||
fun process(srcFile: File, newMap: Map<String, Long>, changesCollector: ChangesCollector) {
|
||||
val key = srcFile.canonicalPath
|
||||
val key = sourcePathConverter.toPath(srcFile)
|
||||
val oldMap = storage[key] ?: emptyMap()
|
||||
|
||||
if (newMap.isNotEmpty()) {
|
||||
storage[key] = newMap
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
storage.remove(key)
|
||||
}
|
||||
|
||||
@@ -219,9 +223,9 @@ private class InlineFunctionsMap(storageFile: File) : BasicStringMap<Map<String,
|
||||
}
|
||||
|
||||
fun remove(sourceFile: File) {
|
||||
storage.remove(sourceFile.canonicalPath)
|
||||
storage.remove(sourcePathConverter.toPath(sourceFile))
|
||||
}
|
||||
|
||||
override fun dumpValue(value: Map<String, Long>): String =
|
||||
value.dumpMap { java.lang.Long.toHexString(it) }
|
||||
value.dumpMap { java.lang.Long.toHexString(it) }
|
||||
}
|
||||
Reference in New Issue
Block a user