Skip to content

Commit 5f12d8b

Browse files
mazhukinevgeniySpace Team
authored and
Space Team
committed
[Cherry-picks] Update BTA specific parts for the release branch
1 parent f025799 commit 5f12d8b

File tree

8 files changed

+216
-152
lines changed

8 files changed

+216
-152
lines changed

compiler/build-tools/kotlin-build-tools-api-tests/src/main/kotlin/compilation/util/scenarioUtil.kt

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,3 @@ fun Scenario.moduleWithInlineSnapshotting(
2020
dependencies = dependencies,
2121
snapshotConfig = SnapshotConfig(ClassSnapshotGranularity.CLASS_MEMBER_LEVEL, true),
2222
)
23-
24-
fun Scenario.moduleWithFir(
25-
moduleName: String,
26-
additionalCompilerArguments: List<String> = emptyList()
27-
) = module(
28-
moduleName = moduleName,
29-
additionalCompilationArguments = additionalCompilerArguments + listOf("-Xuse-fir-ic"),
30-
incrementalCompilationOptionsModifier = { incrementalOptions ->
31-
(incrementalOptions as ClasspathSnapshotBasedIncrementalJvmCompilationConfiguration).useFirRunner(true)
32-
}
33-
)

compiler/build-tools/kotlin-build-tools-api-tests/src/testFirRunner/kotlin/TypeResolutionCyclesTest.kt

Lines changed: 0 additions & 65 deletions
This file was deleted.

compiler/build-tools/kotlin-build-tools-api-tests/src/testFirRunner/kotlin/TypealiasChangeTest.kt

Lines changed: 0 additions & 72 deletions
This file was deleted.

compiler/build-tools/kotlin-build-tools-api/src/main/kotlin/org/jetbrains/kotlin/buildtools/api/CompilationService.kt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
package org.jetbrains.kotlin.buildtools.api
77

8+
import org.jetbrains.kotlin.buildtools.api.internal.KotlinCompilerVersion
9+
import org.jetbrains.kotlin.buildtools.api.internal.wrappers.PreKotlin_2_1_21_Wrapper
810
import org.jetbrains.kotlin.buildtools.api.jvm.ClassSnapshotGranularity
911
import org.jetbrains.kotlin.buildtools.api.jvm.ClasspathEntrySnapshot
1012
import org.jetbrains.kotlin.buildtools.api.jvm.JvmCompilationConfiguration
@@ -112,7 +114,16 @@ public interface CompilationService {
112114
@ExperimentalBuildToolsApi
113115
public companion object {
114116
@JvmStatic
115-
public fun loadImplementation(classLoader: ClassLoader): CompilationService =
116-
loadImplementation(CompilationService::class, classLoader)
117+
public fun loadImplementation(classLoader: ClassLoader): CompilationService {
118+
val baseImplementation = loadImplementation(CompilationService::class, classLoader)
119+
val kotlinCompilerVersion = KotlinCompilerVersion(baseImplementation.getCompilerVersion())
120+
121+
return when {
122+
kotlinCompilerVersion <= KotlinCompilerVersion(2, 1, 20, null) -> {
123+
PreKotlin_2_1_21_Wrapper(baseImplementation)
124+
}
125+
else -> baseImplementation
126+
}
127+
}
117128
}
118129
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
/*
2+
* Copyright 2010-2025 JetBrains s.r.o. and Kotlin Programming Language contributors.
3+
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
4+
*/
5+
6+
package org.jetbrains.kotlin.buildtools.api.internal
7+
8+
import java.io.Serializable
9+
10+
// Copied from KotlinToolingVersion
11+
@OptIn(ExperimentalStdlibApi::class)
12+
internal class KotlinCompilerVersion(
13+
val major: Int,
14+
val minor: Int,
15+
val patch: Int,
16+
val classifier: String?
17+
) : Comparable<KotlinCompilerVersion>, Serializable {
18+
19+
enum class Maturity {
20+
SNAPSHOT, DEV, MILESTONE, ALPHA, BETA, RC, STABLE
21+
}
22+
23+
val maturity: Maturity = run {
24+
val classifier = this.classifier?.lowercase()
25+
when {
26+
classifier == null || classifier.matches(Regex("""(release-)?\d+""")) -> Maturity.STABLE
27+
classifier == "snapshot" -> Maturity.SNAPSHOT
28+
classifier.matches(Regex("""(rc)(\d*)?(-release)?(-?\d+)?""")) -> Maturity.RC
29+
classifier.matches(Regex("""beta(\d*)?(-release)?(-?\d+)?""")) -> Maturity.BETA
30+
classifier.matches(Regex("""alpha(\d*)?(-release)?(-?\d+)?""")) -> Maturity.ALPHA
31+
classifier.matches(Regex("""m\d+(-release)?(-\d+)?""")) -> Maturity.MILESTONE
32+
else -> Maturity.DEV
33+
}
34+
}
35+
36+
override fun compareTo(other: KotlinCompilerVersion): Int {
37+
if (this == other) return 0
38+
(this.major - other.major).takeIf { it != 0 }?.let { return it }
39+
(this.minor - other.minor).takeIf { it != 0 }?.let { return it }
40+
(this.patch - other.patch).takeIf { it != 0 }?.let { return it }
41+
(this.maturity.ordinal - other.maturity.ordinal).takeIf { it != 0 }?.let { return it }
42+
43+
if (this.classifier == null && other.classifier != null) {
44+
/* eg. 1.6.20 > 1.6.20-200 */
45+
return 1
46+
}
47+
48+
if (this.classifier != null && other.classifier == null) {
49+
/* e.g. 1.6.20-200 < 1.6.20 */
50+
return -1
51+
}
52+
53+
val thisClassifierNumber = this.classifierNumber
54+
val otherClassifierNumber = other.classifierNumber
55+
if (thisClassifierNumber != null && otherClassifierNumber != null) {
56+
(thisClassifierNumber - otherClassifierNumber).takeIf { it != 0 }?.let { return it }
57+
}
58+
59+
if (thisClassifierNumber != null && otherClassifierNumber == null) {
60+
/* e.g. 1.6.20-rc1 > 1.6.20-rc */
61+
return 1
62+
}
63+
64+
if (thisClassifierNumber == null && otherClassifierNumber != null) {
65+
/* e.g. 1.6.20-rc < 1.6.20-rc1 */
66+
return -1
67+
}
68+
69+
val thisBuildNumber = this.buildNumber
70+
val otherBuildNumber = other.buildNumber
71+
if (thisBuildNumber != null && otherBuildNumber != null) {
72+
(thisBuildNumber - otherBuildNumber).takeIf { it != 0 }?.let { return it }
73+
}
74+
75+
if (thisBuildNumber == null && otherBuildNumber != null) {
76+
/* e.g. 1.6.20-M1 > 1.6.20-M1-200 */
77+
return 1
78+
}
79+
80+
if (thisBuildNumber != null && otherBuildNumber == null) {
81+
/* e.g. 1.6.20-M1-200 < 1.6.20-M1 */
82+
return -1
83+
}
84+
85+
return 0
86+
}
87+
88+
override fun equals(other: Any?): Boolean {
89+
if (this === other) return true
90+
if (other !is KotlinCompilerVersion) return false
91+
if (this.major != other.major) return false
92+
if (this.minor != other.minor) return false
93+
if (this.patch != other.patch) return false
94+
if (this.classifier?.lowercase() != other.classifier?.lowercase()) return false
95+
return true
96+
}
97+
98+
override fun hashCode(): Int {
99+
var result = major
100+
result = 31 * result + minor
101+
result = 31 * result + patch
102+
result = 31 * result + (classifier?.hashCode() ?: 0)
103+
return result
104+
}
105+
106+
override fun toString(): String {
107+
return "$major.$minor.$patch" + if (classifier != null) "-$classifier" else ""
108+
}
109+
110+
private val classifierNumber: Int?
111+
get() {
112+
if (classifier == null) return null
113+
114+
/*
115+
dev builds allow additional wildcards in the version (like 1.6.20-dev-myWildcard21-510)
116+
In this case, 510 will be the buildNumber, but there is still no associated classifierNumber.
117+
In order to keep the regex below simple, we fast path out here, since we know that
118+
dev builds never carry classifier numbers
119+
*/
120+
if (maturity == KotlinCompilerVersion.Maturity.DEV) return null
121+
122+
/*
123+
Classifiers with only a buildNumber assigned
124+
*/
125+
val buildNumberOnlyClassifierRegex = Regex("\\d+")
126+
if (buildNumberOnlyClassifierRegex.matches(classifier)) {
127+
return null
128+
}
129+
130+
131+
val classifierRegex = Regex("""(.+?)(\d*)?(-release)?-?(\d*)?""")
132+
val classifierMatch = classifierRegex.matchEntire(classifier) ?: return null
133+
return classifierMatch.groupValues.getOrNull(2)?.toIntOrNull()
134+
}
135+
136+
private val buildNumber: Int?
137+
get() {
138+
if (classifier == null) return null
139+
140+
/*
141+
Handle classifiers that only consist of version + build number. This is used for stable releases
142+
like:
143+
1.6.20-1
144+
1.6.20-22
145+
1.6.
146+
*/
147+
val buildNumberOnlyClassifierRegex = Regex("\\d+")
148+
if (buildNumberOnlyClassifierRegex.matches(classifier)) {
149+
return classifier.toIntOrNull()
150+
}
151+
152+
val classifierRegex = Regex("""(.+?)(\d*)?(-release)?-?(\d*)?""")
153+
val classifierMatch = classifierRegex.matchEntire(classifier) ?: return null
154+
return classifierMatch.groupValues.getOrNull(4)?.toIntOrNull()
155+
}
156+
}
157+
158+
internal fun KotlinCompilerVersion(kotlinVersionString: String): KotlinCompilerVersion {
159+
val baseVersion = kotlinVersionString.split("-", limit = 2)[0]
160+
val classifier = kotlinVersionString.split("-", limit = 2).getOrNull(1)
161+
162+
val baseVersionSplit = baseVersion.split(".")
163+
164+
val majorVersion = baseVersionSplit[0].toIntOrNull()
165+
val minorVersion = baseVersionSplit.getOrNull(1)?.toIntOrNull()
166+
167+
if (majorVersion == null || minorVersion == null) {
168+
throw IllegalArgumentException("Invalid Kotlin version: $kotlinVersionString (Failed parsing major/minor version)")
169+
}
170+
171+
return KotlinCompilerVersion(
172+
major = majorVersion,
173+
minor = minorVersion,
174+
patch = baseVersionSplit.getOrNull(2)?.toIntOrNull() ?: 0,
175+
classifier = classifier
176+
)
177+
}

compiler/build-tools/kotlin-build-tools-api/src/main/kotlin/org/jetbrains/kotlin/buildtools/api/internal/wrappers/PreKotlin220Wrapper.kt

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2010-2025 JetBrains s.r.o. and Kotlin Programming Language contributors.
3+
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
4+
*/
5+
@file:OptIn(ExperimentalBuildToolsApi::class)
6+
7+
package org.jetbrains.kotlin.buildtools.api.internal.wrappers
8+
9+
import org.jetbrains.kotlin.buildtools.api.CompilationService
10+
import org.jetbrains.kotlin.buildtools.api.ExperimentalBuildToolsApi
11+
import org.jetbrains.kotlin.buildtools.api.jvm.ClassSnapshotGranularity
12+
import org.jetbrains.kotlin.buildtools.api.jvm.ClasspathEntrySnapshot
13+
import java.io.File
14+
15+
internal class PreKotlin_2_1_21_Wrapper(
16+
private val base: CompilationService
17+
) : CompilationService by base {
18+
override fun calculateClasspathSnapshot(
19+
classpathEntry: File,
20+
granularity: ClassSnapshotGranularity,
21+
parseInlinedLocalClasses: Boolean
22+
): ClasspathEntrySnapshot {
23+
// the parseInlinedLocalClasses api wasn't available before
24+
return base.calculateClasspathSnapshot(classpathEntry, granularity)
25+
}
26+
}

libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/PropertiesProvider.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -749,8 +749,6 @@ internal class PropertiesProvider private constructor(private val project: Proje
749749
val KOTLIN_COLLECT_FUS_METRICS_ENABLED = property("$KOTLIN_INTERNAL_NAMESPACE.collectFUSMetrics")
750750
val KOTLIN_USE_NON_PACKED_KLIBS = property("$KOTLIN_INTERNAL_NAMESPACE.klibs.non-packed")
751751
val KOTLIN_CLASSLOADER_CACHE_TIMEOUT = property("$KOTLIN_INTERNAL_NAMESPACE.classloaderCache.timeoutSeconds")
752-
val ABI_VALIDATION_BANNED_TARGETS = property(ABI_VALIDATION_BANNED_TARGETS_NAME)
753-
val ABI_VALIDATION_DISABLED = property(ABI_VALIDATION_DISABLED_NAME)
754752
val KOTLIN_PARSE_INLINED_LOCAL_CLASSES = property("$KOTLIN_INTERNAL_NAMESPACE.classpathSnapshot.parseInlinedLocalClasses")
755753
}
756754

0 commit comments

Comments
 (0)