Support reading binary metadata of the next major release
Already existing tests testRequireKotlinInNestedClassesAgainst14{,Js}
now check that there's no error when loading a module/class with
metadata version 1.4.0
#KT-25972 Fixed
This commit is contained in:
+2
-5
@@ -316,15 +316,12 @@ class CompileKotlinAgainstCustomBinariesTest : AbstractKotlinCompilerIntegration
|
||||
|
||||
fun testRequireKotlinInNestedClassesAgainst14() {
|
||||
val library = compileLibrary("library", additionalOptions = listOf("-Xmetadata-version=1.4.0"))
|
||||
compileKotlin("source.kt", tmpdir, listOf(library), additionalOptions = listOf("-Xskip-metadata-version-check"))
|
||||
compileKotlin("source.kt", tmpdir, listOf(library))
|
||||
}
|
||||
|
||||
fun testRequireKotlinInNestedClassesAgainst14Js() {
|
||||
val library = compileJsLibrary("library", additionalOptions = listOf("-Xmetadata-version=1.4.0"))
|
||||
compileKotlin(
|
||||
"source.kt", File(tmpdir, "usage.js"), listOf(library), K2JSCompiler(),
|
||||
additionalOptions = listOf("-Xskip-metadata-version-check")
|
||||
)
|
||||
compileKotlin("source.kt", File(tmpdir, "usage.js"), listOf(library), K2JSCompiler())
|
||||
}
|
||||
|
||||
/*test source mapping generation when source info is absent*/
|
||||
|
||||
@@ -26,7 +26,8 @@ class KotlinJavascriptMetadata(val version: JsMetadataVersion, val moduleName: S
|
||||
|
||||
// TODO: move to JS modules
|
||||
class JsMetadataVersion(vararg numbers: Int) : BinaryVersion(*numbers) {
|
||||
override fun isCompatible() = this.isCompatibleTo(INSTANCE)
|
||||
override fun isCompatible(): Boolean =
|
||||
isMetadataVersionCompatible()
|
||||
|
||||
fun toInteger() = (patch shl 16) + (minOf(minor, 255) shl 8) + minOf(major, 255)
|
||||
|
||||
|
||||
+2
-2
@@ -12,9 +12,9 @@ import org.jetbrains.kotlin.metadata.deserialization.BinaryVersion
|
||||
* This version includes the version of the core protobuf messages (metadata.proto) as well as JVM extensions (jvm_metadata.proto).
|
||||
*/
|
||||
class JvmMetadataVersion(vararg numbers: Int) : BinaryVersion(*numbers) {
|
||||
// NOTE: 1.1 is incompatible with 1.0 and hence with any other version except 1.1.*
|
||||
// NOTE: 1.1 is incompatible with 1.0
|
||||
override fun isCompatible() =
|
||||
this.major == 1 && this.minor == 1
|
||||
isMetadataVersionCompatible() && minor != 0
|
||||
|
||||
companion object {
|
||||
@JvmField
|
||||
|
||||
@@ -14,7 +14,8 @@ import java.io.InputStream
|
||||
* of the core protobuf messages (metadata.proto).
|
||||
*/
|
||||
class BuiltInsBinaryVersion(vararg numbers: Int) : BinaryVersion(*numbers) {
|
||||
override fun isCompatible() = this.isCompatibleTo(INSTANCE)
|
||||
override fun isCompatible() =
|
||||
isMetadataVersionCompatible()
|
||||
|
||||
companion object {
|
||||
@JvmField
|
||||
|
||||
@@ -35,6 +35,12 @@ abstract class BinaryVersion(private vararg val numbers: Int) {
|
||||
else major == ourVersion.major && minor <= ourVersion.minor
|
||||
}
|
||||
|
||||
// In Kotlin 1.4, all metadata versions (JVM, JS, built-ins/metadata) are going to be advanced to 1.4.0.
|
||||
// Kotlin 1.3 is able to read metadata of versions up to Kotlin 1.4
|
||||
protected fun isMetadataVersionCompatible(): Boolean {
|
||||
return major == 1 && minor <= 4
|
||||
}
|
||||
|
||||
fun isAtLeast(major: Int, minor: Int, patch: Int): Boolean {
|
||||
if (this.major > major) return true
|
||||
if (this.major < major) return false
|
||||
|
||||
Reference in New Issue
Block a user