Use JvmMetadataVersion/JvmBytecodeBinaryVersion in kotlinx-metadata
#KT-23198
This commit is contained in:
@@ -5,7 +5,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.load.kotlin
|
||||
|
||||
import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmMetadataVersion
|
||||
import org.jetbrains.kotlin.metadata.jvm.deserialization.ModuleMapping
|
||||
import org.jetbrains.kotlin.serialization.deserialization.DeserializationConfiguration
|
||||
|
||||
@@ -17,7 +16,6 @@ fun ModuleMapping.Companion.loadModuleMapping(
|
||||
loadModuleMapping(
|
||||
bytes,
|
||||
debugName,
|
||||
{ version -> JvmMetadataVersion(*version).isCompatible() },
|
||||
configuration.skipMetadataVersionCheck,
|
||||
configuration.isJvmPackageNameSupported
|
||||
)
|
||||
|
||||
+1
-2
@@ -33,7 +33,6 @@ class ModuleMapping private constructor(
|
||||
fun loadModuleMapping(
|
||||
bytes: ByteArray?,
|
||||
debugName: String,
|
||||
isVersionCompatible: (IntArray) -> Boolean,
|
||||
skipMetadataVersionCheck: Boolean,
|
||||
isJvmPackageNameSupported: Boolean
|
||||
): ModuleMapping {
|
||||
@@ -50,7 +49,7 @@ class ModuleMapping private constructor(
|
||||
return CORRUPTED
|
||||
}
|
||||
|
||||
if (skipMetadataVersionCheck || isVersionCompatible(versionNumber)) {
|
||||
if (skipMetadataVersionCheck || JvmMetadataVersion(*versionNumber).isCompatible()) {
|
||||
val moduleProto = JvmModuleProtoBuf.Module.parseFrom(stream) ?: return EMPTY
|
||||
val result = linkedMapOf<String, PackageParts>()
|
||||
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
|
||||
package kotlinx.metadata.jvm
|
||||
|
||||
import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmBytecodeBinaryVersion
|
||||
import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmMetadataVersion
|
||||
|
||||
/**
|
||||
* A mirror to the [Metadata] annotation on a JVM class file, containing the metadata of Kotlin declarations declared in the class file.
|
||||
* Properties of this class correspond to the properties of [Metadata], but the names are not shortened because there's no restriction
|
||||
@@ -142,7 +145,7 @@ class KotlinClassHeader(
|
||||
* @see metadataVersion
|
||||
*/
|
||||
@JvmField
|
||||
val COMPATIBLE_METADATA_VERSION = intArrayOf(1, 1, 10)
|
||||
val COMPATIBLE_METADATA_VERSION = JvmMetadataVersion.INSTANCE.toArray().copyOf()
|
||||
|
||||
/**
|
||||
* The latest bytecode version supported by this version of the library.
|
||||
@@ -150,6 +153,6 @@ class KotlinClassHeader(
|
||||
* @see bytecodeVersion
|
||||
*/
|
||||
@JvmField
|
||||
val COMPATIBLE_BYTECODE_VERSION = intArrayOf(1, 0, 2)
|
||||
val COMPATIBLE_BYTECODE_VERSION = JvmBytecodeBinaryVersion.INSTANCE.toArray().copyOf()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import kotlinx.metadata.impl.LambdaWriter
|
||||
import kotlinx.metadata.impl.PackageWriter
|
||||
import kotlinx.metadata.impl.accept
|
||||
import kotlinx.metadata.jvm.impl.writeProtoBufData
|
||||
import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmMetadataVersion
|
||||
import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmProtoBufUtil
|
||||
import org.jetbrains.kotlin.metadata.jvm.serialization.JvmStringTable
|
||||
import kotlin.LazyThreadSafetyMode.PUBLICATION
|
||||
@@ -312,8 +313,7 @@ sealed class KotlinClassMetadata(val header: KotlinClassHeader) {
|
||||
@JvmStatic
|
||||
fun read(header: KotlinClassHeader): KotlinClassMetadata? {
|
||||
// We only support metadata of version 1.1.* (this is Kotlin from 1.0 until today)
|
||||
val version = header.metadataVersion
|
||||
if (version.getOrNull(0) != 1 || version.getOrNull(1) != 1) return null
|
||||
if (!JvmMetadataVersion(*header.metadataVersion).isCompatible()) return null
|
||||
|
||||
return try {
|
||||
when (header.kind) {
|
||||
|
||||
@@ -5,9 +5,8 @@
|
||||
|
||||
package kotlinx.metadata.jvm
|
||||
|
||||
import kotlinx.metadata.KmAnnotation
|
||||
import kotlinx.metadata.ClassName
|
||||
import kotlinx.metadata.InconsistentKotlinMetadataException
|
||||
import kotlinx.metadata.KmAnnotation
|
||||
import org.jetbrains.kotlin.metadata.jvm.JvmModuleProtoBuf
|
||||
import org.jetbrains.kotlin.metadata.jvm.deserialization.ModuleMapping
|
||||
import org.jetbrains.kotlin.metadata.jvm.deserialization.PackageParts
|
||||
@@ -22,10 +21,9 @@ import org.jetbrains.kotlin.metadata.jvm.deserialization.serializeToByteArray
|
||||
* @property bytes the byte array representing the contents of a `.kotlin_module` file
|
||||
*/
|
||||
class KotlinModuleMetadata(@Suppress("CanBeParameter", "MemberVisibilityCanBePrivate") val bytes: ByteArray) {
|
||||
internal val data: ModuleMapping = ModuleMapping.loadModuleMapping(bytes, javaClass.name, isVersionCompatible = { version ->
|
||||
// We only support metadata of version 1.1.* (this is Kotlin from 1.0 until today)
|
||||
version.getOrNull(0) == 1 && version.getOrNull(1) == 1
|
||||
}, skipMetadataVersionCheck = false, isJvmPackageNameSupported = true)
|
||||
internal val data: ModuleMapping = ModuleMapping.loadModuleMapping(
|
||||
bytes, javaClass.name, skipMetadataVersionCheck = false, isJvmPackageNameSupported = true
|
||||
)
|
||||
|
||||
/**
|
||||
* A [KmModuleVisitor] that generates the metadata of a Kotlin JVM module file.
|
||||
|
||||
Reference in New Issue
Block a user