Make lookup storage addAll order independent

Lookup storage output files could differ for projects
with different absolute paths.
This happened because, paths for lookups were
relativized only before writing to the underlying storage.
Storing absolute paths in a hash table could
result in different order of adding files to the lookup storage.
This commit fixes the issue by sorting lookups and files in
LookupStorage#addAll

    #KT-32674 Fixed

Original commit: a4c62d156f
This commit is contained in:
Alexey Tsvetkov
2019-07-14 20:39:15 +03:00
parent 21487a7b5e
commit b767adc66d
2 changed files with 5 additions and 27 deletions
@@ -7,30 +7,8 @@ package org.jetbrains.kotlin.jps.build
import org.jetbrains.jps.model.JpsProject
import org.jetbrains.jps.model.serialization.JpsModelSerializationDataService
import org.jetbrains.kotlin.incremental.storage.FileToPathConverter
import java.io.File
import org.jetbrains.kotlin.incremental.storage.RelativeFileToPathConverter
private const val PROJECT_DIR_PLACEHOLDER = "${'$'}PROJECT_DIR$"
internal class JpsFileToPathConverter(jpsProject: JpsProject) : FileToPathConverter {
private val baseDirPath = JpsModelSerializationDataService
.getBaseDirectory(jpsProject)?.canonicalFile?.invariantSeparatorsPath
override fun toPath(file: File): String {
val path = file.canonicalFile.invariantSeparatorsPath
return when {
baseDirPath != null && path.startsWith(baseDirPath) ->
PROJECT_DIR_PLACEHOLDER + path.substring(baseDirPath.length)
else -> path
}
}
override fun toFile(path: String): File =
when {
path.startsWith(PROJECT_DIR_PLACEHOLDER) -> {
val basePath = baseDirPath ?: error("Could not get project root dir")
File(basePath + path.substring(PROJECT_DIR_PLACEHOLDER.length))
}
else -> File(path)
}
}
internal class JpsFileToPathConverter(
jpsProject: JpsProject
) : RelativeFileToPathConverter(JpsModelSerializationDataService.getBaseDirectory(jpsProject))
@@ -648,7 +648,7 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
lookupStorageManager.withLookupStorage { lookupStorage ->
lookupStorage.removeLookupsFrom(dirtyFilesHolder.allDirtyFiles.asSequence() + dirtyFilesHolder.allRemovedFilesFiles.asSequence())
lookupStorage.addAll(lookupTracker.lookups.entrySet(), lookupTracker.pathInterner.values)
lookupStorage.addAll(lookupTracker.lookups, lookupTracker.pathInterner.values)
}
}
}