Write flags to .kotlin_module files since metadata version 1.4
This value will be used for flags like pre-release (KT-21256) and other similar info
This commit is contained in:
@@ -123,7 +123,7 @@ public class ClassFileFactory implements OutputFileCollection {
|
||||
generators.put(outputFilePath, new OutAndSourceFileList(CollectionsKt.toList(sourceFiles)) {
|
||||
@Override
|
||||
public byte[] asBytes(ClassBuilderFactory factory) {
|
||||
return ModuleMappingKt.serializeToByteArray(moduleProto, state.getMetadataVersion().toArray());
|
||||
return ModuleMappingKt.serializeToByteArray(moduleProto, state.getMetadataVersion(), 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -135,7 +135,7 @@ open class MetadataSerializer(
|
||||
for (table in packageTable.values) {
|
||||
table.addTo(this)
|
||||
}
|
||||
}.build().serializeToByteArray(JvmMetadataVersion.INSTANCE.toArray()) // TODO: use another version here, not JVM
|
||||
}.build().serializeToByteArray(JvmMetadataVersion.INSTANCE, 0) // TODO: use another version here, not JVM
|
||||
// TODO: also, use CommonConfigurationKeys.METADATA_VERSION if needed
|
||||
|
||||
kotlinModuleFile.parentFile.mkdirs()
|
||||
|
||||
+12
-1
@@ -5,7 +5,9 @@
|
||||
|
||||
package org.jetbrains.kotlin.metadata.jvm.deserialization
|
||||
|
||||
import org.jetbrains.kotlin.metadata.deserialization.BinaryVersion
|
||||
import org.jetbrains.kotlin.metadata.deserialization.NameResolverImpl
|
||||
import org.jetbrains.kotlin.metadata.deserialization.isKotlin1Dot4OrLater
|
||||
import org.jetbrains.kotlin.metadata.jvm.JvmModuleProtoBuf
|
||||
import java.io.*
|
||||
|
||||
@@ -54,6 +56,11 @@ class ModuleMapping private constructor(
|
||||
return EMPTY
|
||||
}
|
||||
|
||||
// Since Kotlin 1.4, we write integer flags between the version and the proto
|
||||
if (isKotlin1Dot4OrLater(version)) {
|
||||
stream.readInt()
|
||||
}
|
||||
|
||||
val moduleProto = JvmModuleProtoBuf.Module.parseFrom(stream) ?: return EMPTY
|
||||
val result = linkedMapOf<String, PackageParts>()
|
||||
|
||||
@@ -207,13 +214,17 @@ class PackageParts(val packageFqName: String) {
|
||||
(parts + metadataParts).toString()
|
||||
}
|
||||
|
||||
fun JvmModuleProtoBuf.Module.serializeToByteArray(versionArray: IntArray): ByteArray {
|
||||
fun JvmModuleProtoBuf.Module.serializeToByteArray(version: BinaryVersion, flags: Int): ByteArray {
|
||||
val moduleMapping = ByteArrayOutputStream(4096)
|
||||
val out = DataOutputStream(moduleMapping)
|
||||
val versionArray = version.toArray()
|
||||
out.writeInt(versionArray.size)
|
||||
for (number in versionArray) {
|
||||
out.writeInt(number)
|
||||
}
|
||||
if (isKotlin1Dot4OrLater(version)) {
|
||||
out.writeInt(flags)
|
||||
}
|
||||
writeTo(out)
|
||||
out.flush()
|
||||
return moduleMapping.toByteArray()
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.metadata.deserialization
|
||||
fun isVersionRequirementTableWrittenCorrectly(version: BinaryVersion): Boolean =
|
||||
isKotlin1Dot4OrLater(version)
|
||||
|
||||
private fun isKotlin1Dot4OrLater(version: BinaryVersion): Boolean {
|
||||
fun isKotlin1Dot4OrLater(version: BinaryVersion): Boolean {
|
||||
// All metadata versions (JVM, JS, common) will be advanced to 1.4.0 in Kotlin 1.4
|
||||
return version.major == 1 && version.minor >= 4
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ package kotlinx.metadata.jvm
|
||||
import kotlinx.metadata.InconsistentKotlinMetadataException
|
||||
import kotlinx.metadata.KmAnnotation
|
||||
import org.jetbrains.kotlin.metadata.jvm.JvmModuleProtoBuf
|
||||
import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmMetadataVersion
|
||||
import org.jetbrains.kotlin.metadata.jvm.deserialization.ModuleMapping
|
||||
import org.jetbrains.kotlin.metadata.jvm.deserialization.PackageParts
|
||||
import org.jetbrains.kotlin.metadata.jvm.deserialization.serializeToByteArray
|
||||
@@ -62,7 +63,7 @@ class KotlinModuleMetadata(@Suppress("CanBeParameter", "MemberVisibilityCanBePri
|
||||
* [KotlinClassHeader.COMPATIBLE_METADATA_VERSION] by default
|
||||
*/
|
||||
fun write(metadataVersion: IntArray = KotlinClassHeader.COMPATIBLE_METADATA_VERSION): KotlinModuleMetadata =
|
||||
KotlinModuleMetadata(b.build().serializeToByteArray(metadataVersion))
|
||||
KotlinModuleMetadata(b.build().serializeToByteArray(JvmMetadataVersion(*metadataVersion), 0))
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user