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) + } }