From 8b2b36d61f936146bc29933c6f097ceccfd77705 Mon Sep 17 00:00:00 2001 From: Alexander Gorshenev Date: Thu, 5 Nov 2020 19:02:36 +0300 Subject: [PATCH] Enabled klib abi version compatibility --- .../kotlin/library/KotlinAbiVersion.kt | 33 ++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/compiler/util-klib/src/org/jetbrains/kotlin/library/KotlinAbiVersion.kt b/compiler/util-klib/src/org/jetbrains/kotlin/library/KotlinAbiVersion.kt index 8d747764f9b..fffc949035c 100644 --- a/compiler/util-klib/src/org/jetbrains/kotlin/library/KotlinAbiVersion.kt +++ b/compiler/util-klib/src/org/jetbrains/kotlin/library/KotlinAbiVersion.kt @@ -26,13 +26,38 @@ fun String.parseKotlinAbiVersion(): KotlinAbiVersion { } } -// For 1.4 compiler we switch klib abi_version to a triple, -// but we don't break if we still encounter a single digit from 1.3. +// TODO: it would be nice to inherit this one from BinaryVersion, +// but that requires a module structure refactoring. data class KotlinAbiVersion(val major: Int, val minor: Int, val patch: Int) { + // For 1.4 compiler we switched klib abi_version to a triple, + // but we don't break if we still encounter a single digit from 1.3. constructor(single: Int) : this(0, single, 0) - companion object { - val CURRENT = KotlinAbiVersion(1, 4, 1) + + fun isCompatible(): Boolean = isCompatibleTo(CURRENT) + + private fun isCompatibleTo(ourVersion: KotlinAbiVersion): Boolean { + return if (this.isAtLeast(1, 4, 1)) + major == ourVersion.major && minor <= ourVersion.minor + else + this == ourVersion + } + + fun isAtLeast(version: KotlinAbiVersion): Boolean = + isAtLeast(version.major, version.minor, version.patch) + + fun isAtLeast(major: Int, minor: Int, patch: Int): Boolean { + if (this.major > major) return true + if (this.major < major) return false + + if (this.minor > minor) return true + if (this.minor < minor) return false + + return this.patch >= patch } override fun toString() = "$major.$minor.$patch" + + companion object { + val CURRENT = KotlinAbiVersion(1, 4, 1) + } }