Skip to content

Commit 1a5ef3e

Browse files
ddolovovSpace Team
authored andcommitted
[JS, Wasm] Simplify and unify stdlib/kotlin-test version checkers
^KT-82208
1 parent 3914037 commit 1a5ef3e

File tree

3 files changed

+30
-52
lines changed

3 files changed

+30
-52
lines changed

compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/diagnostics/LibrarySpecialCompatibilityChecker.kt

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,24 +60,37 @@ abstract class LibrarySpecialCompatibilityChecker {
6060
val compilerVersion = Version.parseVersion(getRawCompilerVersion()) ?: return
6161

6262
for (library in libraries) {
63-
if (shouldCheckLibrary(library)) {
64-
val jarManifest = library.getComponent(JarManifestComponent.Kind)?.jarManifest ?: continue
65-
val libraryVersion = Version.parseVersion(jarManifest.mainAttributes.getValue(KLIB_JAR_LIBRARY_VERSION)) ?: continue
63+
val checkedLibrary = library.toCheckedLibrary() ?: continue
6664

67-
val messageToReport = getMessageToReport(compilerVersion, libraryVersion, library)
68-
if (messageToReport != null) {
69-
messageCollector.report(CompilerMessageSeverity.ERROR, messageToReport)
70-
}
65+
val jarManifest = library.getComponent(JarManifestComponent.Kind)?.jarManifest ?: continue
66+
val libraryVersion = Version.parseVersion(jarManifest.mainAttributes.getValue(KLIB_JAR_LIBRARY_VERSION)) ?: continue
67+
68+
val rootCause = when {
69+
libraryVersion < compilerVersion ->
70+
"The ${checkedLibrary.platformDisplayName} ${checkedLibrary.libraryDisplayName} library has an older version ($libraryVersion) than the compiler ($compilerVersion). Such a configuration is not supported."
71+
72+
!libraryVersion.hasSameLanguageVersion(compilerVersion) ->
73+
"The ${checkedLibrary.platformDisplayName} ${checkedLibrary.libraryDisplayName} library has a more recent version ($libraryVersion) than the compiler supports. The compiler version is $compilerVersion."
74+
75+
else -> continue
7176
}
77+
78+
messageCollector.report(
79+
CompilerMessageSeverity.ERROR,
80+
"$rootCause\nPlease, make sure that the ${checkedLibrary.libraryDisplayName} library has the version in the range " +
81+
"[${compilerVersion.toComparableVersionString()} .. ${compilerVersion.toLanguageVersionString()}.${KotlinVersion.MAX_COMPONENT_VALUE}]. " +
82+
"Adjust your project's settings if necessary."
83+
)
7284
}
7385
}
7486

7587
private fun getRawCompilerVersion(): String? {
7688
return customCompilerVersionForTest?.let { return it.version } ?: KotlinCompilerVersion.getVersion()
7789
}
7890

79-
protected abstract fun shouldCheckLibrary(library: KotlinLibrary): Boolean
80-
protected abstract fun getMessageToReport(compilerVersion: Version, libraryVersion: Version, library: KotlinLibrary): String?
91+
protected class CheckedLibrary(val libraryDisplayName: String, val platformDisplayName: String)
92+
93+
protected abstract fun KotlinLibrary.toCheckedLibrary(): CheckedLibrary?
8194

8295
companion object {
8396
private class CustomCompilerVersionForTest(val version: String?)

compiler/ir/serialization.js/src/org/jetbrains/kotlin/ir/backend/js/checkers/JsLibrarySpecialCompatibilityChecker.kt

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,9 @@ import org.jetbrains.kotlin.library.isJsKotlinTest
1111
import org.jetbrains.kotlin.library.isJsStdlib
1212

1313
object JsLibrarySpecialCompatibilityChecker : LibrarySpecialCompatibilityChecker() {
14-
override fun shouldCheckLibrary(library: KotlinLibrary) = library.isJsStdlib || library.isJsKotlinTest
15-
16-
override fun getMessageToReport(compilerVersion: Version, libraryVersion: Version, library: KotlinLibrary): String? {
17-
val libraryDisplayName = when {
18-
library.isJsStdlib -> "standard"
19-
library.isJsKotlinTest -> "kotlin-test"
20-
else -> null
21-
}
22-
val rootCause = when {
23-
libraryVersion < compilerVersion ->
24-
"The Kotlin/JS $libraryDisplayName library has an older version ($libraryVersion) than the compiler ($compilerVersion). Such a configuration is not supported."
25-
26-
!libraryVersion.hasSameLanguageVersion(compilerVersion) ->
27-
"The Kotlin/JS $libraryDisplayName library has a more recent version ($libraryVersion) than the compiler supports. The compiler version is $compilerVersion."
28-
29-
else -> return null
30-
}
31-
32-
return "$rootCause\nPlease, make sure that the $libraryDisplayName library has the version in the range " +
33-
"[${compilerVersion.toComparableVersionString()} .. ${compilerVersion.toLanguageVersionString()}.${KotlinVersion.MAX_COMPONENT_VALUE}]. " +
34-
"Adjust your project's settings if necessary."
14+
override fun KotlinLibrary.toCheckedLibrary(): CheckedLibrary? = when {
15+
isJsStdlib -> CheckedLibrary(libraryDisplayName = "standard", platformDisplayName = "Kotlin/JS")
16+
isJsKotlinTest -> CheckedLibrary(libraryDisplayName = "kotlin-test", platformDisplayName = "Kotlin/JS")
17+
else -> null
3518
}
3619
}

compiler/ir/serialization.js/src/org/jetbrains/kotlin/ir/backend/js/checkers/WasmLibrarySpecialCompatibilityChecker.kt

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,9 @@ import org.jetbrains.kotlin.library.isWasmKotlinTest
1111
import org.jetbrains.kotlin.library.isWasmStdlib
1212

1313
object WasmLibrarySpecialCompatibilityChecker : LibrarySpecialCompatibilityChecker() {
14-
override fun shouldCheckLibrary(library: KotlinLibrary) = library.isWasmStdlib || library.isWasmKotlinTest
15-
16-
override fun getMessageToReport(compilerVersion: Version, libraryVersion: Version, library: KotlinLibrary): String? {
17-
val libraryDisplayName = when {
18-
library.isWasmStdlib -> "standard"
19-
library.isWasmKotlinTest -> "kotlin-test"
20-
else -> null
21-
}
22-
23-
val rootCause = when {
24-
libraryVersion < compilerVersion ->
25-
"The Kotlin/Wasm $libraryDisplayName library has an older version ($libraryVersion) than the compiler ($compilerVersion). Such a configuration is not supported."
26-
27-
!libraryVersion.hasSameLanguageVersion(compilerVersion) ->
28-
"The Kotlin/Wasm $libraryDisplayName library has a more recent version ($libraryVersion) than the compiler supports. The compiler version is $compilerVersion."
29-
30-
else -> return null
31-
}
32-
33-
return "$rootCause\nPlease, make sure that the $libraryDisplayName library has the version in the range " +
34-
"[${compilerVersion.toComparableVersionString()} .. ${compilerVersion.toLanguageVersionString()}.${KotlinVersion.MAX_COMPONENT_VALUE}]. " +
35-
"Adjust your project's settings if necessary."
14+
override fun KotlinLibrary.toCheckedLibrary(): CheckedLibrary? = when {
15+
isWasmStdlib -> CheckedLibrary(libraryDisplayName = "standard", platformDisplayName = "Kotlin/Wasm")
16+
isWasmKotlinTest -> CheckedLibrary(libraryDisplayName = "kotlin-test", platformDisplayName = "Kotlin/Wasm")
17+
else -> null
3618
}
3719
}

0 commit comments

Comments
 (0)