Skip to content

Commit 4c29409

Browse files
Kotlin: add extractor support for Kotlin 2.4.0
Add 2.4.0 compiler artifacts and API compatibility shims, including updated plugin registration and version-agnostic IR accessors. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 11b5e2c commit 4c29409

24 files changed

Lines changed: 503 additions & 171 deletions

MODULE.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ use_repo(
248248
"kotlin-compiler-2.2.20-Beta2",
249249
"kotlin-compiler-2.3.0",
250250
"kotlin-compiler-2.3.20",
251+
"kotlin-compiler-2.4.0",
251252
"kotlin-compiler-embeddable-1.8.0",
252253
"kotlin-compiler-embeddable-1.9.0-Beta",
253254
"kotlin-compiler-embeddable-1.9.20-Beta",
@@ -259,6 +260,7 @@ use_repo(
259260
"kotlin-compiler-embeddable-2.2.20-Beta2",
260261
"kotlin-compiler-embeddable-2.3.0",
261262
"kotlin-compiler-embeddable-2.3.20",
263+
"kotlin-compiler-embeddable-2.4.0",
262264
"kotlin-stdlib-1.8.0",
263265
"kotlin-stdlib-1.9.0-Beta",
264266
"kotlin-stdlib-1.9.20-Beta",
@@ -270,6 +272,7 @@ use_repo(
270272
"kotlin-stdlib-2.2.20-Beta2",
271273
"kotlin-stdlib-2.3.0",
272274
"kotlin-stdlib-2.3.20",
275+
"kotlin-stdlib-2.4.0",
273276
)
274277

275278
go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")

java/kotlin-extractor/BUILD.bazel

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,14 @@ _resources = [
6464
r[len("src/main/resources/"):],
6565
)
6666
for r in glob(["src/main/resources/**"])
67+
if r != "src/main/resources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar"
6768
]
6869

70+
_compiler_plugin_registrar_service = (
71+
"src/main/resources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar",
72+
"META-INF/services/org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar",
73+
)
74+
6975
kt_javac_options(
7076
name = "javac-options",
7177
release = "8",
@@ -91,19 +97,32 @@ kt_javac_options(
9197
# * `resource_strip_prefix` is unique per jar, so we must also put other resources under the same version prefix
9298
genrule(
9399
name = "resources-%s" % v,
94-
srcs = [src for src, _ in _resources],
100+
srcs = [src for src, _ in _resources] + (
101+
[_compiler_plugin_registrar_service[0]] if not version_less(v, "2.4.0") else []
102+
),
95103
outs = [
96104
"%s/com/github/codeql/extractor.name" % v,
97105
] + [
98106
"%s/%s" % (v, target)
99107
for _, target in _resources
100-
],
108+
] + (
109+
["%s/%s" % (
110+
v,
111+
_compiler_plugin_registrar_service[1],
112+
)] if not version_less(v, "2.4.0") else []
113+
),
101114
cmd = "\n".join([
102115
"echo %s-%s > $(RULEDIR)/%s/com/github/codeql/extractor.name" % (_extractor_name_prefix, v, v),
103116
] + [
104117
"cp $(execpath %s) $(RULEDIR)/%s/%s" % (source, v, target)
105118
for source, target in _resources
106-
]),
119+
] + (
120+
["cp $(execpath %s) $(RULEDIR)/%s/%s" % (
121+
_compiler_plugin_registrar_service[0],
122+
v,
123+
_compiler_plugin_registrar_service[1],
124+
)] if not version_less(v, "2.4.0") else []
125+
)),
107126
),
108127
kt_jvm_library(
109128
name = "%s-%s" % (_extractor_name_prefix, v),
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:66e73eacd619c9beb7c22042117af36b443529c4d80237ee82cc4b2acb6f3d0b
3+
size 61902486
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:c2b25e8c1c93ec416ba4327f5e31eaec0f0c8847241b9353e294b8db9dce564f
3+
size 60351320
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:ccb14ff83fabcb11458b798dbc9824748ccdffeec79c9aba789e6ed1cda86b1c
3+
size 1841929

java/kotlin-extractor/dev/wrapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import io
2828
import os
2929

30-
DEFAULT_VERSION = "2.3.20"
30+
DEFAULT_VERSION = "2.4.0"
3131

3232

3333
def options():

java/kotlin-extractor/src/main/kotlin/KotlinExtractorComponentRegistrar.kt

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,21 @@
33

44
package com.github.codeql
55

6-
import com.intellij.mock.MockProject
7-
import com.intellij.openapi.extensions.LoadingOrder
8-
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
96
import org.jetbrains.kotlin.config.CompilerConfiguration
107

118
class KotlinExtractorComponentRegistrar : Kotlin2ComponentRegistrar() {
12-
override fun registerProjectComponents(
13-
project: MockProject,
14-
configuration: CompilerConfiguration
15-
) {
9+
override fun doRegisterExtensions(configuration: CompilerConfiguration) {
1610
val invocationTrapFile = configuration[KEY_INVOCATION_TRAP_FILE]
1711
if (invocationTrapFile == null) {
1812
throw Exception("Required argument for TRAP invocation file not given")
1913
}
20-
// Register with LoadingOrder.LAST to ensure the extractor runs after other
21-
// IR generation plugins (like kotlinx.serialization) have generated their code.
22-
val extensionPoint = project.extensionArea.getExtensionPoint(IrGenerationExtension.extensionPointName)
23-
extensionPoint.registerExtension(
14+
registerExtractorExtension(
2415
KotlinExtractorExtension(
2516
invocationTrapFile,
2617
configuration[KEY_CHECK_TRAP_IDENTICAL] ?: false,
2718
configuration[KEY_COMPILATION_STARTTIME],
2819
configuration[KEY_EXIT_AFTER_EXTRACTION] ?: false
29-
),
30-
LoadingOrder.LAST,
31-
project
20+
)
3221
)
3322
}
3423
}

0 commit comments

Comments
 (0)