JS: write and load pre-release flag on binaries
This commit is contained in:
+24
-2
@@ -16,16 +16,20 @@
|
||||
|
||||
package org.jetbrains.kotlin.serialization.js
|
||||
|
||||
import org.jetbrains.kotlin.config.KotlinCompilerVersion
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.SourceFile
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||
import org.jetbrains.kotlin.serialization.deserialization.AnnotationDeserializer
|
||||
import org.jetbrains.kotlin.serialization.deserialization.DeserializedPackageFragmentImpl
|
||||
import org.jetbrains.kotlin.serialization.deserialization.IncompatibleVersionErrorData
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassDescriptor
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedPropertyDescriptor
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedSimpleFunctionDescriptor
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
@@ -35,8 +39,9 @@ class KotlinJavascriptPackageFragment(
|
||||
fqName: FqName,
|
||||
storageManager: StorageManager,
|
||||
module: ModuleDescriptor,
|
||||
proto: ProtoBuf.PackageFragment
|
||||
) : DeserializedPackageFragmentImpl(fqName, storageManager, module, proto) {
|
||||
proto: ProtoBuf.PackageFragment,
|
||||
header: JsProtoBuf.Header
|
||||
) : DeserializedPackageFragmentImpl(fqName, storageManager, module, proto, JsContainerSource(fqName, header)) {
|
||||
private val fileMap: Map<Int, FileHolder> by storageManager.createLazyValue {
|
||||
this.proto.getExtension(JsProtoBuf.packageFragmentFiles).fileList.withIndex().associate { (index, file) ->
|
||||
(if (file.hasId()) file.id else index) to FileHolder(file.annotationList)
|
||||
@@ -66,4 +71,21 @@ class KotlinJavascriptPackageFragment(
|
||||
annotationsProto.map { annotationDeserializer.deserializeAnnotation(it, nameResolver) }
|
||||
}
|
||||
}
|
||||
|
||||
private class JsContainerSource(private val fqName: FqName, private val header: JsProtoBuf.Header) : DeserializedContainerSource {
|
||||
// TODO
|
||||
override fun getContainingFile(): SourceFile = SourceFile.NO_SOURCE_FILE
|
||||
|
||||
// This is null because we look for incompatible libraries in dependencies in the beginning of the compilation anyway,
|
||||
// and refuse to compile against them completely
|
||||
override val incompatibility: IncompatibleVersionErrorData<*>?
|
||||
get() = null
|
||||
|
||||
override val isPreReleaseInvisible: Boolean
|
||||
get() = (header.flags and 1) != 0 && !KotlinCompilerVersion.isPreRelease()
|
||||
|
||||
// TODO: this is not a class
|
||||
override val presentableString: String
|
||||
get() = "Package '$fqName'"
|
||||
}
|
||||
}
|
||||
|
||||
+13
-6
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.serialization.js
|
||||
|
||||
import org.jetbrains.kotlin.config.KotlinCompilerVersion
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
@@ -44,7 +45,10 @@ object KotlinJavascriptSerializationUtil {
|
||||
metadata: ByteArray, storageManager: StorageManager, module: ModuleDescriptor, configuration: DeserializationConfiguration
|
||||
): JsModuleDescriptor<PackageFragmentProvider?> {
|
||||
val jsModule = metadata.deserializeToLibraryParts(module.name.asString())
|
||||
return jsModule.copy(createKotlinJavascriptPackageFragmentProvider(storageManager, module, jsModule.data, configuration))
|
||||
val (header, packageFragmentProtos) = jsModule.data
|
||||
return jsModule.copy(createKotlinJavascriptPackageFragmentProvider(
|
||||
storageManager, module, header, packageFragmentProtos, configuration
|
||||
))
|
||||
}
|
||||
|
||||
private fun serializeMetadata(
|
||||
@@ -185,7 +189,10 @@ object KotlinJavascriptSerializationUtil {
|
||||
header.packageFqName = packageFqName.asString()
|
||||
}
|
||||
|
||||
// TODO: write pre-release flag if needed
|
||||
if (KotlinCompilerVersion.isPreRelease()) {
|
||||
header.flags = 1
|
||||
}
|
||||
|
||||
// TODO: write JS code binary version
|
||||
|
||||
return header.build()
|
||||
@@ -220,15 +227,15 @@ object KotlinJavascriptSerializationUtil {
|
||||
}.toByteArray()
|
||||
}
|
||||
|
||||
private fun ByteArray.deserializeToLibraryParts(name: String): JsModuleDescriptor<List<ProtoBuf.PackageFragment>> {
|
||||
val content = GZIPInputStream(ByteArrayInputStream(this)).use { stream ->
|
||||
JsProtoBuf.Header.parseDelimitedFrom(stream, JsSerializerProtocol.extensionRegistry)
|
||||
private fun ByteArray.deserializeToLibraryParts(name: String): JsModuleDescriptor<Pair<JsProtoBuf.Header, List<ProtoBuf.PackageFragment>>> {
|
||||
val (header, content) = GZIPInputStream(ByteArrayInputStream(this)).use { stream ->
|
||||
JsProtoBuf.Header.parseDelimitedFrom(stream, JsSerializerProtocol.extensionRegistry) to
|
||||
JsProtoBuf.Library.parseFrom(stream, JsSerializerProtocol.extensionRegistry)
|
||||
}
|
||||
|
||||
return JsModuleDescriptor(
|
||||
name = name,
|
||||
data = content.packageFragmentList,
|
||||
data = header to content.packageFragmentList,
|
||||
kind = when (content.kind) {
|
||||
null, JsProtoBuf.Library.Kind.PLAIN -> ModuleKind.PLAIN
|
||||
JsProtoBuf.Library.Kind.AMD -> ModuleKind.AMD
|
||||
|
||||
+2
-1
@@ -28,12 +28,13 @@ import org.jetbrains.kotlin.storage.StorageManager
|
||||
fun createKotlinJavascriptPackageFragmentProvider(
|
||||
storageManager: StorageManager,
|
||||
module: ModuleDescriptor,
|
||||
header: JsProtoBuf.Header,
|
||||
packageFragmentProtos: List<ProtoBuf.PackageFragment>,
|
||||
configuration: DeserializationConfiguration
|
||||
): PackageFragmentProvider {
|
||||
val packageFragments = packageFragmentProtos.mapNotNull { proto ->
|
||||
proto.fqName?.let { fqName ->
|
||||
KotlinJavascriptPackageFragment(fqName, storageManager, module, proto)
|
||||
KotlinJavascriptPackageFragment(fqName, storageManager, module, proto, header)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user