Add debugName to ModuleMapping
This commit is contained in:
@@ -36,7 +36,7 @@ private fun List<PackageParts>.addCompiledParts(state: GenerationState): List<Pa
|
||||
val incrementalCache = state.incrementalCacheForThisTarget ?: return this
|
||||
val moduleMappingData = incrementalCache.getModuleMappingData() ?: return this
|
||||
|
||||
val mapping = ModuleMapping.create(moduleMappingData)
|
||||
val mapping = ModuleMapping.create(moduleMappingData, "<incremental>")
|
||||
|
||||
incrementalCache.getObsoletePackageParts().forEach {
|
||||
val i = it.lastIndexOf('/')
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.cli.jvm.compiler
|
||||
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.util.SmartList
|
||||
import org.jetbrains.kotlin.cli.jvm.config.JvmClasspathRoot
|
||||
import org.jetbrains.kotlin.config.JVMConfigurationKeys
|
||||
@@ -61,13 +60,13 @@ class JvmPackagePartProvider(val env: KotlinCoreEnvironment) : PackagePartProvid
|
||||
loadedModules.addAll(relevantRoots.mapNotNull {
|
||||
it.findChild("META-INF")
|
||||
}.flatMap {
|
||||
it.children.filter<VirtualFile> { it.name.endsWith(ModuleMapping.MAPPING_FILE_EXT) }
|
||||
}.map {
|
||||
it.children.filter { it.name.endsWith(ModuleMapping.MAPPING_FILE_EXT) }
|
||||
}.map { file ->
|
||||
try {
|
||||
ModuleMapping.create(it.contentsToByteArray())
|
||||
ModuleMapping.create(file.contentsToByteArray(), file.toString())
|
||||
}
|
||||
catch (e: EOFException) {
|
||||
throw RuntimeException("Error on reading package parts for '$packageFqName' package in '$it', roots: $notLoadedRoots", e)
|
||||
throw RuntimeException("Error on reading package parts for '$packageFqName' package in '$file', roots: $notLoadedRoots", e)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
+1
-1
@@ -90,7 +90,7 @@ class IncrementalPackageFragmentProvider(
|
||||
MemberScope.Empty
|
||||
}
|
||||
else {
|
||||
val moduleMapping = incrementalCache.getModuleMappingData()?.let { ModuleMapping.create(it) }
|
||||
val moduleMapping = incrementalCache.getModuleMappingData()?.let { ModuleMapping.create(it, "<incremental>") }
|
||||
|
||||
val actualPackagePartFiles =
|
||||
moduleMapping?.findPackageParts(fqName.asString())?.let {
|
||||
|
||||
+5
-1
@@ -28,7 +28,11 @@ internal class IncrementalPackagePartProvider private constructor(
|
||||
incrementalCaches: List<IncrementalCache>,
|
||||
storageManager: StorageManager
|
||||
) : PackagePartProvider {
|
||||
private val moduleMappings = storageManager.createLazyValue { incrementalCaches.map { ModuleMapping.create(it.getModuleMappingData()) } }
|
||||
private val moduleMappings = storageManager.createLazyValue {
|
||||
incrementalCaches.map { cache ->
|
||||
ModuleMapping.create(cache.getModuleMappingData(), "<incremental>")
|
||||
}
|
||||
}
|
||||
|
||||
override fun findPackageParts(packageFqName: String): List<String> {
|
||||
return (moduleMappings().mapNotNull { it.findPackageParts(packageFqName) }.flatMap { it.parts } +
|
||||
|
||||
@@ -20,20 +20,21 @@ import org.jetbrains.kotlin.serialization.jvm.JvmPackageTable
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.DataInputStream
|
||||
|
||||
class ModuleMapping private constructor(val packageFqName2Parts: Map<String, PackageParts>) {
|
||||
|
||||
class ModuleMapping private constructor(val packageFqName2Parts: Map<String, PackageParts>, private val debugName: String) {
|
||||
fun findPackageParts(packageFqName: String): PackageParts? {
|
||||
return packageFqName2Parts[packageFqName]
|
||||
}
|
||||
|
||||
override fun toString() = debugName
|
||||
|
||||
companion object {
|
||||
@JvmField
|
||||
val MAPPING_FILE_EXT: String = "kotlin_module"
|
||||
|
||||
@JvmField
|
||||
val EMPTY: ModuleMapping = ModuleMapping(emptyMap())
|
||||
val EMPTY: ModuleMapping = ModuleMapping(emptyMap(), "EMPTY")
|
||||
|
||||
fun create(proto: ByteArray? = null): ModuleMapping {
|
||||
fun create(proto: ByteArray?, debugName: String?): ModuleMapping {
|
||||
if (proto == null) {
|
||||
return EMPTY
|
||||
}
|
||||
@@ -52,7 +53,7 @@ class ModuleMapping private constructor(val packageFqName2Parts: Map<String, Pac
|
||||
packageParts.parts.add(it)
|
||||
}
|
||||
}
|
||||
return ModuleMapping(packageFqNameParts)
|
||||
return ModuleMapping(packageFqNameParts, debugName ?: "<unknown>")
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
+3
-2
@@ -25,8 +25,9 @@ class RuntimePackagePartProvider(private val classLoader: ClassLoader) : Package
|
||||
|
||||
fun registerModule(moduleName: String) {
|
||||
val mapping = try {
|
||||
classLoader.getResourceAsStream("META-INF/$moduleName.${ModuleMapping.MAPPING_FILE_EXT}")?.use { stream ->
|
||||
ModuleMapping.create(stream.readBytes())
|
||||
val resourcePath = "META-INF/$moduleName.${ModuleMapping.MAPPING_FILE_EXT}"
|
||||
classLoader.getResourceAsStream(resourcePath)?.use { stream ->
|
||||
ModuleMapping.create(stream.readBytes(), resourcePath)
|
||||
}
|
||||
}
|
||||
catch (e: Exception) {
|
||||
|
||||
+9
-10
@@ -77,17 +77,16 @@ object KotlinModuleMappingIndex : FileBasedIndexExtension<String, PackageParts>(
|
||||
override fun getVersion(): Int = 1
|
||||
|
||||
override fun getIndexer(): DataIndexer<String, PackageParts, FileContent> {
|
||||
return object : DataIndexer<String, PackageParts, FileContent> {
|
||||
override fun map(inputData: FileContent): Map<String, PackageParts> {
|
||||
val content = inputData.content
|
||||
try {
|
||||
val moduleMapping = ModuleMapping.create(content)
|
||||
return moduleMapping.packageFqName2Parts
|
||||
} catch(e : Exception) {
|
||||
throw RuntimeException("Error on indexing ${inputData.file.path}", e)
|
||||
}
|
||||
return DataIndexer<String, PackageParts, FileContent> { inputData ->
|
||||
val content = inputData.content
|
||||
val file = inputData.file
|
||||
try {
|
||||
val moduleMapping = ModuleMapping.create(content, file.toString())
|
||||
return@DataIndexer moduleMapping.packageFqName2Parts
|
||||
}
|
||||
catch(e: Exception) {
|
||||
throw RuntimeException("Error on indexing $file", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user