From 79337a6b96b5256c7739a927f74a9cd5c316e5c7 Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Fri, 12 Apr 2019 16:35:23 +0300 Subject: [PATCH] Allow customizing source file path conversion in local IC caches --- .../incremental/AbstractIncrementalCache.kt | 19 +++-- .../kotlin/incremental/IncrementalJsCache.kt | 78 ++++++++++--------- .../kotlin/incremental/IncrementalJvmCache.kt | 25 +++--- .../storage/ComplementarySourceFilesMap.kt | 30 +++++++ .../storage/SourceFileToPathConverter.kt | 25 ++++++ .../incremental/storage/SourceToOutputMaps.kt | 28 ++++--- .../incremental/IncrementalCachesManager.kt | 11 ++- .../kotlin/incremental/InputsCache.kt | 2 +- .../storage/SourceToOutputFilesMap.kt | 27 +++++++ .../kotlin/jps/build/KotlinCompileContext.kt | 4 + .../jps/incremental/JpsIncrementalCache.kt | 11 ++- .../jps/targets/KotlinJsModuleBuildTarget.kt | 2 +- .../jps/targets/KotlinJvmModuleBuildTarget.kt | 3 +- 13 files changed, 191 insertions(+), 74 deletions(-) create mode 100644 build-common/src/org/jetbrains/kotlin/incremental/storage/ComplementarySourceFilesMap.kt create mode 100644 build-common/src/org/jetbrains/kotlin/incremental/storage/SourceFileToPathConverter.kt create mode 100644 compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/storage/SourceToOutputFilesMap.kt diff --git a/build-common/src/org/jetbrains/kotlin/incremental/AbstractIncrementalCache.kt b/build-common/src/org/jetbrains/kotlin/incremental/AbstractIncrementalCache.kt index 14969438dc0..dada248fcfc 100644 --- a/build-common/src/org/jetbrains/kotlin/incremental/AbstractIncrementalCache.kt +++ b/build-common/src/org/jetbrains/kotlin/incremental/AbstractIncrementalCache.kt @@ -45,7 +45,10 @@ interface IncrementalCacheCommon { /** * Incremental cache common for JVM and JS for specifit ClassName type */ -abstract class AbstractIncrementalCache(workingDir: File) : BasicMapsOwner(workingDir), IncrementalCacheCommon { +abstract class AbstractIncrementalCache( + workingDir: File, + protected val sourcePathConverter: SourceFileToPathConverter +) : BasicMapsOwner(workingDir), IncrementalCacheCommon { companion object { private val SUBTYPES = "subtypes" private val SUPERTYPES = "supertypes" @@ -70,17 +73,16 @@ abstract class AbstractIncrementalCache(workingDir: File) : BasicMaps private val subtypesMap = registerMap(SubtypesMap(SUBTYPES.storageFile)) private val supertypesMap = registerMap(SupertypesMap(SUPERTYPES.storageFile)) - protected val classFqNameToSourceMap = registerMap(ClassFqNameToSourceMap(CLASS_FQ_NAME_TO_SOURCE.storageFile)) + protected val classFqNameToSourceMap = registerMap(ClassFqNameToSourceMap(CLASS_FQ_NAME_TO_SOURCE.storageFile, sourcePathConverter)) internal abstract val sourceToClassesMap: AbstractSourceToOutputMap internal abstract val dirtyOutputClassesMap: AbstractDirtyClassesMap - /** * A file X is a complementary to a file Y if they contain corresponding expect/actual declarations. * Complementary files should be compiled together during IC so the compiler does not complain * about missing parts. * TODO: provide a better solution (maintain an index of expect/actual declarations akin to IncrementalPackagePartProvider) */ - private val complementaryFilesMap = registerMap(FilesMap(COMPLEMENTARY_FILES.storageFile)) + private val complementaryFilesMap = registerMap(ComplementarySourceFilesMap(COMPLEMENTARY_FILES.storageFile, sourcePathConverter)) override fun classesFqNamesBySources(files: Iterable): Collection = files.flatMapTo(HashSet()) { sourceToClassesMap.getFqNames(it) } @@ -153,14 +155,17 @@ abstract class AbstractIncrementalCache(workingDir: File) : BasicMaps removedFqNames.forEach { classFqNameToSourceMap.remove(it) } } - protected class ClassFqNameToSourceMap(storageFile: File) : + protected class ClassFqNameToSourceMap( + storageFile: File, + private val sourcePathConverter: SourceFileToPathConverter + ) : BasicStringMap(storageFile, EnumeratorStringDescriptor(), PathStringDescriptor) { operator fun set(fqName: FqName, sourceFile: File) { - storage[fqName.asString()] = sourceFile.canonicalPath + storage[fqName.asString()] = sourcePathConverter.toPath(sourceFile) } operator fun get(fqName: FqName): File? = - storage[fqName.asString()]?.let(::File) + storage[fqName.asString()]?.let(sourcePathConverter::toFile) fun remove(fqName: FqName) { storage.remove(fqName.asString()) diff --git a/build-common/src/org/jetbrains/kotlin/incremental/IncrementalJsCache.kt b/build-common/src/org/jetbrains/kotlin/incremental/IncrementalJsCache.kt index f0a178cf4bc..e27e5c34062 100644 --- a/build-common/src/org/jetbrains/kotlin/incremental/IncrementalJsCache.kt +++ b/build-common/src/org/jetbrains/kotlin/incremental/IncrementalJsCache.kt @@ -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(cachesDir) { +open class IncrementalJsCache( + cachesDir: File, + sourcePathConverter: SourceFileToPathConverter +) : AbstractIncrementalCache(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() @@ -113,14 +113,14 @@ open class IncrementalJsCache(cachesDir: File) : AbstractIncrementalCache = - hashMapOf().apply { - for (path in translationResults.keys()) { - val file = File(path) - if (file !in dirtySources) { - put(file, translationResults[path]!!) - } + hashMapOf().apply { + for (path in translationResults.keys()) { + val file = File(path) + if (file !in dirtySources) { + put(file, translationResults[file]!!) } } + } } private object TranslationResultValueExternalizer : DataExternalizer { @@ -152,31 +152,33 @@ private object TranslationResultValueExternalizer : DataExternalizer(storageFile, TranslationResultValueExternalizer) { +private class TranslationResultMap( + storageFile: File, + private val sourcePathConverter: SourceFileToPathConverter +) : BasicStringMap(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 = - 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 return classes } -private class InlineFunctionsMap(storageFile: File) : BasicStringMap>(storageFile, StringToLongMapExternalizer) { +private class InlineFunctionsMap( + storageFile: File, + private val sourcePathConverter: SourceFileToPathConverter +) : BasicStringMap>(storageFile, StringToLongMapExternalizer) { fun process(srcFile: File, newMap: Map, 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): String = - value.dumpMap { java.lang.Long.toHexString(it) } + value.dumpMap { java.lang.Long.toHexString(it) } } \ No newline at end of file diff --git a/build-common/src/org/jetbrains/kotlin/incremental/IncrementalJvmCache.kt b/build-common/src/org/jetbrains/kotlin/incremental/IncrementalJvmCache.kt index 77e52183740..93dbc0eaaf1 100644 --- a/build-common/src/org/jetbrains/kotlin/incremental/IncrementalJvmCache.kt +++ b/build-common/src/org/jetbrains/kotlin/incremental/IncrementalJvmCache.kt @@ -43,8 +43,12 @@ val KOTLIN_CACHE_DIRECTORY_NAME = "kotlin" open class IncrementalJvmCache( private val targetDataRoot: File, - targetOutputDir: File? -) : AbstractIncrementalCache(File(targetDataRoot, KOTLIN_CACHE_DIRECTORY_NAME)), IncrementalCache { + targetOutputDir: File?, + sourcePathConverter: SourceFileToPathConverter +) : AbstractIncrementalCache( + workingDir = File(targetDataRoot, KOTLIN_CACHE_DIRECTORY_NAME), + sourcePathConverter = sourcePathConverter +), IncrementalCache { companion object { private val PROTO_MAP = "proto" private val CONSTANTS_MAP = "constants" @@ -58,7 +62,7 @@ open class IncrementalJvmCache( private val MODULE_MAPPING_FILE_NAME = "." + ModuleMapping.MAPPING_FILE_EXT } - override val sourceToClassesMap = registerMap(SourceToJvmNameMap(SOURCE_TO_CLASSES.storageFile)) + override val sourceToClassesMap = registerMap(SourceToJvmNameMap(SOURCE_TO_CLASSES.storageFile, sourcePathConverter)) override val dirtyOutputClassesMap = registerMap(DirtyClassesJvmNameMap(DIRTY_OUTPUT_CLASSES.storageFile)) private val protoMap = registerMap(ProtoMap(PROTO_MAP.storageFile)) @@ -68,7 +72,8 @@ open class IncrementalJvmCache( private val partToMultifileFacade = registerMap(MultifileClassPartMap(MULTIFILE_CLASS_PARTS.storageFile)) private val inlineFunctionsMap = registerMap(InlineFunctionsMap(INLINE_FUNCTIONS.storageFile)) // todo: try to use internal names only? - private val internalNameToSource = registerMap(InternalNameToSourcesMap(INTERNAL_NAME_TO_SOURCE.storageFile)) + private val internalNameToSource = registerMap(InternalNameToSourcesMap(INTERNAL_NAME_TO_SOURCE.storageFile, sourcePathConverter)) + // gradle only private val javaSourcesProtoMap = registerMap(JavaSourcesProtoMap(JAVA_SOURCES_PROTO_MAP.storageFile)) private val outputDir by lazy(LazyThreadSafetyMode.NONE) { requireNotNull(targetOutputDir) { "Target is expected to have output directory" } } @@ -440,14 +445,16 @@ open class IncrementalJvmCache( override fun dumpValue(value: String): String = value } - inner class InternalNameToSourcesMap(storageFile: File) : - BasicStringMap>(storageFile, EnumeratorStringDescriptor(), PathCollectionExternalizer) { - operator fun set(internalName: String, sourceFiles: Iterable) { - storage[internalName] = sourceFiles.map { it.canonicalPath } + inner class InternalNameToSourcesMap( + storageFile: File, + private val sourcePathConverter: SourceFileToPathConverter + ) : BasicStringMap>(storageFile, EnumeratorStringDescriptor(), PathCollectionExternalizer) { + operator fun set(internalName: String, sourceFiles: Collection) { + storage[internalName] = sourcePathConverter.toPaths(sourceFiles) } operator fun get(internalName: String): Collection = - (storage[internalName] ?: emptyList()).map(::File) + sourcePathConverter.toFiles(storage[internalName] ?: emptyList()) fun remove(internalName: String) { storage.remove(internalName) diff --git a/build-common/src/org/jetbrains/kotlin/incremental/storage/ComplementarySourceFilesMap.kt b/build-common/src/org/jetbrains/kotlin/incremental/storage/ComplementarySourceFilesMap.kt new file mode 100644 index 00000000000..12d0ccdcce4 --- /dev/null +++ b/build-common/src/org/jetbrains/kotlin/incremental/storage/ComplementarySourceFilesMap.kt @@ -0,0 +1,30 @@ +/* + * 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 + +import org.jetbrains.kotlin.incremental.dumpCollection +import java.io.File + +class ComplementarySourceFilesMap( + storageFile: File, + private val sourcePathConverter: SourceFileToPathConverter +) : BasicStringMap>(storageFile, PathStringDescriptor, StringCollectionExternalizer) { + + operator fun set(sourceFile: File, complementaryFiles: Collection) { + storage[sourcePathConverter.toPath(sourceFile)] = sourcePathConverter.toPaths(complementaryFiles) + } + + operator fun get(sourceFile: File): Collection { + val paths = storage[sourcePathConverter.toPath(sourceFile)].orEmpty() + return sourcePathConverter.toFiles(paths) + } + + override fun dumpValue(value: Collection) = + value.dumpCollection() + + fun remove(file: File): Collection = + get(file).also { storage.remove(sourcePathConverter.toPath(file)) } +} \ No newline at end of file diff --git a/build-common/src/org/jetbrains/kotlin/incremental/storage/SourceFileToPathConverter.kt b/build-common/src/org/jetbrains/kotlin/incremental/storage/SourceFileToPathConverter.kt new file mode 100644 index 00000000000..a6fe8fd8698 --- /dev/null +++ b/build-common/src/org/jetbrains/kotlin/incremental/storage/SourceFileToPathConverter.kt @@ -0,0 +1,25 @@ +/* + * Copyright 2010-2019 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 + +import java.io.File + +interface SourceFileToPathConverter { + fun toPath(file: File): String + fun toFile(path: String): File +} + +fun SourceFileToPathConverter.toPaths(files: Collection): List = + files.map { toPath(it) } + +fun SourceFileToPathConverter.toFiles(paths: Collection): List = + paths.map { toFile(it) } + +object SourceFileToCanonicalPathConverter : SourceFileToPathConverter { + override fun toPath(file: File): String = file.canonicalPath + + override fun toFile(path: String): File = File(path) +} diff --git a/build-common/src/org/jetbrains/kotlin/incremental/storage/SourceToOutputMaps.kt b/build-common/src/org/jetbrains/kotlin/incremental/storage/SourceToOutputMaps.kt index f2687d2993f..63b7a7072df 100644 --- a/build-common/src/org/jetbrains/kotlin/incremental/storage/SourceToOutputMaps.kt +++ b/build-common/src/org/jetbrains/kotlin/incremental/storage/SourceToOutputMaps.kt @@ -21,32 +21,40 @@ import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.resolve.jvm.JvmClassName import java.io.File -internal class SourceToJvmNameMap(storageFile: File) : AbstractSourceToOutputMap(JvmClassNameTransformer, storageFile) -internal class SourceToFqNameMap(storageFile: File) : AbstractSourceToOutputMap(FqNameTransformer, storageFile) +internal class SourceToJvmNameMap( + storageFile: File, + sourcePathConverter: SourceFileToPathConverter +) : AbstractSourceToOutputMap(JvmClassNameTransformer, storageFile, sourcePathConverter) + +internal class SourceToFqNameMap( + storageFile: File, + sourcePathConverter: SourceFileToPathConverter +) : AbstractSourceToOutputMap(FqNameTransformer, storageFile, sourcePathConverter) internal abstract class AbstractSourceToOutputMap( - private val nameTransformer: NameTransformer, - storageFile: File + private val nameTransformer: NameTransformer, + storageFile: File, + private val sourcePathConverter: SourceFileToPathConverter ) : BasicStringMap>(storageFile, PathStringDescriptor, StringCollectionExternalizer) { fun clearOutputsForSource(sourceFile: File) { - remove(sourceFile.absolutePath) + remove(sourcePathConverter.toPath(sourceFile)) } fun add(sourceFile: File, className: Name) { - storage.append(sourceFile.absolutePath, nameTransformer.asString(className)) + storage.append(sourcePathConverter.toPath(sourceFile), nameTransformer.asString(className)) } fun contains(sourceFile: File): Boolean = - sourceFile.absolutePath in storage + sourcePathConverter.toPath(sourceFile) in storage operator fun get(sourceFile: File): Collection = - storage[sourceFile.absolutePath].orEmpty().map(nameTransformer::asName) + storage[sourcePathConverter.toPath(sourceFile)].orEmpty().map(nameTransformer::asName) fun getFqNames(sourceFile: File): Collection = - storage[sourceFile.absolutePath].orEmpty().map(nameTransformer::asFqName) + storage[sourcePathConverter.toPath(sourceFile)].orEmpty().map(nameTransformer::asFqName) override fun dumpValue(value: Collection) = - value.dumpCollection() + value.dumpCollection() private fun remove(path: String) { storage.remove(path) diff --git a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalCachesManager.kt b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalCachesManager.kt index 8916c02b0bb..239c78f9ad6 100644 --- a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalCachesManager.kt +++ b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalCachesManager.kt @@ -17,8 +17,11 @@ package org.jetbrains.kotlin.incremental import org.jetbrains.kotlin.incremental.storage.BasicMapsOwner +import org.jetbrains.kotlin.incremental.storage.SourceFileToCanonicalPathConverter import java.io.File +private val PATH_CONVERTER = SourceFileToCanonicalPathConverter + abstract class IncrementalCachesManager>( cachesRootDir: File, protected val reporter: ICReporter @@ -67,14 +70,14 @@ class IncrementalJvmCachesManager( ) : IncrementalCachesManager(cacheDirectory, reporter) { private val jvmCacheDir = File(cacheDirectory, "jvm").apply { mkdirs() } - override val platformCache = IncrementalJvmCache(jvmCacheDir, outputDir).apply { registerCache() } + override val platformCache = IncrementalJvmCache(jvmCacheDir, outputDir, PATH_CONVERTER).apply { registerCache() } } class IncrementalJsCachesManager( - cachesRootDir: File, - reporter: ICReporter + cachesRootDir: File, + reporter: ICReporter ) : IncrementalCachesManager(cachesRootDir, reporter) { private val jsCacheFile = File(cachesRootDir, "js").apply { mkdirs() } - override val platformCache = IncrementalJsCache(jsCacheFile).apply { registerCache() } + override val platformCache = IncrementalJsCache(jsCacheFile, PATH_CONVERTER).apply { registerCache() } } \ No newline at end of file diff --git a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/InputsCache.kt b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/InputsCache.kt index 918a1793a5a..f1d43ce4ea7 100644 --- a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/InputsCache.kt +++ b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/InputsCache.kt @@ -34,7 +34,7 @@ class InputsCache( } internal val sourceSnapshotMap = registerMap(FileSnapshotMap(SOURCE_SNAPSHOTS.storageFile)) - private val sourceToOutputMap = registerMap(FilesMap(SOURCE_TO_OUTPUT_FILES.storageFile)) + private val sourceToOutputMap = registerMap(SourceToOutputFilesMap(SOURCE_TO_OUTPUT_FILES.storageFile)) fun removeOutputForSourceFiles(sources: Iterable) { for (sourceFile in sources) { diff --git a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/storage/SourceToOutputFilesMap.kt b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/storage/SourceToOutputFilesMap.kt new file mode 100644 index 00000000000..3d7dfbe18fd --- /dev/null +++ b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/storage/SourceToOutputFilesMap.kt @@ -0,0 +1,27 @@ +/* + * Copyright 2010-2019 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 + +import org.jetbrains.kotlin.incremental.dumpCollection +import java.io.File + +class SourceToOutputFilesMap( + storageFile: File +) : BasicStringMap>(storageFile, PathStringDescriptor, StringCollectionExternalizer) { + + operator fun set(sourceFile: File, outputFiles: Collection) { + storage[sourceFile.absolutePath] = outputFiles.map { it.absolutePath } + } + + operator fun get(sourceFile: File): Collection = + storage[sourceFile.absolutePath].orEmpty().map(::File) + + override fun dumpValue(value: Collection) = + value.dumpCollection() + + fun remove(file: File): Collection = + get(file).also { storage.remove(file.absolutePath) } +} \ No newline at end of file diff --git a/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinCompileContext.kt b/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinCompileContext.kt index 5d1446d52a3..ec3ff7385b1 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinCompileContext.kt +++ b/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinCompileContext.kt @@ -14,6 +14,8 @@ import org.jetbrains.jps.incremental.messages.BuildMessage import org.jetbrains.jps.incremental.messages.CompilerMessage import org.jetbrains.kotlin.config.CompilerRunnerConstants import org.jetbrains.kotlin.incremental.LookupSymbol +import org.jetbrains.kotlin.incremental.storage.SourceFileToCanonicalPathConverter +import org.jetbrains.kotlin.incremental.storage.SourceFileToPathConverter import org.jetbrains.kotlin.jps.incremental.* import org.jetbrains.kotlin.jps.targets.KotlinTargetsIndex import org.jetbrains.kotlin.jps.targets.KotlinTargetsIndexBuilder @@ -66,6 +68,8 @@ class KotlinCompileContext(val jpsContext: CompileContext) { val hasKotlinMarker = HasKotlinMarker(dataManager) + val sourceFileToPathConverter: SourceFileToPathConverter = SourceFileToCanonicalPathConverter + /** * Flag to prevent rebuilding twice. * diff --git a/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/JpsIncrementalCache.kt b/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/JpsIncrementalCache.kt index 3d999048d4e..7437c4daa4a 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/JpsIncrementalCache.kt +++ b/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/JpsIncrementalCache.kt @@ -24,6 +24,7 @@ import org.jetbrains.jps.incremental.storage.StorageOwner import org.jetbrains.kotlin.incremental.IncrementalCacheCommon import org.jetbrains.kotlin.incremental.IncrementalJsCache import org.jetbrains.kotlin.incremental.IncrementalJvmCache +import org.jetbrains.kotlin.incremental.storage.SourceFileToPathConverter import org.jetbrains.kotlin.jps.build.KotlinBuilder import org.jetbrains.kotlin.jps.targets.KotlinModuleBuildTarget import java.io.File @@ -34,8 +35,9 @@ interface JpsIncrementalCache : IncrementalCacheCommon, StorageOwner { class JpsIncrementalJvmCache( target: ModuleBuildTarget, - paths: BuildDataPaths -) : IncrementalJvmCache(paths.getTargetDataRoot(target), target.outputDir), JpsIncrementalCache { + paths: BuildDataPaths, + sourcePathConverter: SourceFileToPathConverter +) : IncrementalJvmCache(paths.getTargetDataRoot(target), target.outputDir, sourcePathConverter), JpsIncrementalCache { override fun addJpsDependentCache(cache: JpsIncrementalCache) { if (cache is JpsIncrementalJvmCache) { addDependentCache(cache) @@ -49,8 +51,9 @@ class JpsIncrementalJvmCache( class JpsIncrementalJsCache( target: ModuleBuildTarget, - paths: BuildDataPaths -) : IncrementalJsCache(paths.getTargetDataRoot(target)), JpsIncrementalCache { + paths: BuildDataPaths, + sourcePathConverter: SourceFileToPathConverter +) : IncrementalJsCache(paths.getTargetDataRoot(target), sourcePathConverter), JpsIncrementalCache { override fun addJpsDependentCache(cache: JpsIncrementalCache) { if (cache is JpsIncrementalJsCache) { addDependentCache(cache) diff --git a/jps-plugin/src/org/jetbrains/kotlin/jps/targets/KotlinJsModuleBuildTarget.kt b/jps-plugin/src/org/jetbrains/kotlin/jps/targets/KotlinJsModuleBuildTarget.kt index 9b805a8e6a6..fbd08ad2834 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/jps/targets/KotlinJsModuleBuildTarget.kt +++ b/jps-plugin/src/org/jetbrains/kotlin/jps/targets/KotlinJsModuleBuildTarget.kt @@ -208,7 +208,7 @@ class KotlinJsModuleBuildTarget(kotlinContext: KotlinCompileContext, jpsModuleBu } override fun createCacheStorage(paths: BuildDataPaths) = - JpsIncrementalJsCache(jpsModuleBuildTarget, paths) + JpsIncrementalJsCache(jpsModuleBuildTarget, paths, kotlinContext.sourceFileToPathConverter) override fun updateCaches( dirtyFilesHolder: KotlinDirtySourceFilesHolder, diff --git a/jps-plugin/src/org/jetbrains/kotlin/jps/targets/KotlinJvmModuleBuildTarget.kt b/jps-plugin/src/org/jetbrains/kotlin/jps/targets/KotlinJvmModuleBuildTarget.kt index d24a71ec0ff..126b50961c7 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/jps/targets/KotlinJvmModuleBuildTarget.kt +++ b/jps-plugin/src/org/jetbrains/kotlin/jps/targets/KotlinJvmModuleBuildTarget.kt @@ -55,7 +55,8 @@ class KotlinJvmModuleBuildTarget(kotlinContext: KotlinCompileContext, jpsModuleB override val isIncrementalCompilationEnabled: Boolean get() = IncrementalCompilation.isEnabledForJvm() - override fun createCacheStorage(paths: BuildDataPaths) = JpsIncrementalJvmCache(jpsModuleBuildTarget, paths) + override fun createCacheStorage(paths: BuildDataPaths) = + JpsIncrementalJvmCache(jpsModuleBuildTarget, paths, kotlinContext.sourceFileToPathConverter) override val buildMetaInfoFactory get() = JvmBuildMetaInfo