Skip to content

Commit c1b4fe6

Browse files
Kotlin: address KT-85816
Kotlin 2.4.20-RC removes the remaining ComponentRegistrar API under KT-85816. Use an RC-specific registrar that only implements CompilerPluginRegistrar, and package the legacy ComponentRegistrar service only for older compilers. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 93e6135 commit c1b4fe6

2 files changed

Lines changed: 61 additions & 2 deletions

File tree

java/kotlin-extractor/BUILD.bazel

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ _compiler_plugin_registrar_service_source = "src/main/resources/META-INF/service
5757

5858
_compiler_plugin_registrar_service_target = "META-INF/services/org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar"
5959

60+
_component_registrar_service_source = "src/main/resources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar"
61+
62+
_component_registrar_service_target = "META-INF/services/org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar"
63+
6064
py_binary(
6165
name = "generate_dbscheme",
6266
srcs = ["generate_dbscheme.py"],
@@ -68,14 +72,22 @@ _resources = [
6872
r[len("src/main/resources/"):],
6973
)
7074
for r in glob(["src/main/resources/**"])
71-
if r != _compiler_plugin_registrar_service_source
75+
if r not in (
76+
_compiler_plugin_registrar_service_source,
77+
_component_registrar_service_source,
78+
)
7279
]
7380

7481
_compiler_plugin_registrar_service = (
7582
_compiler_plugin_registrar_service_source,
7683
_compiler_plugin_registrar_service_target,
7784
)
7885

86+
_component_registrar_service = (
87+
_component_registrar_service_source,
88+
_component_registrar_service_target,
89+
)
90+
7991
kt_javac_options(
8092
name = "javac-options",
8193
release = "8",
@@ -93,7 +105,9 @@ kt_javac_options(
93105
"kotlin.RequiresOptIn",
94106
"org.jetbrains.kotlin.ir.symbols.%s" %
95107
("IrSymbolInternals" if version_less(v, "2.0.0") else "UnsafeDuringIrConstructionAPI"),
96-
] + ([] if version_less(v, "2.2.20") else ["org.jetbrains.kotlin.DeprecatedForRemovalCompilerApi"]),
108+
] + (
109+
[] if version_less(v, "2.2.20") else ["org.jetbrains.kotlin.DeprecatedForRemovalCompilerApi"]
110+
),
97111
x_suppress_version_warnings = True,
98112
),
99113
# * extractor.name is different for each version, so we need to put it in different output dirs
@@ -103,6 +117,8 @@ kt_javac_options(
103117
name = "resources-%s" % v,
104118
srcs = [src for src, _ in _resources] + (
105119
[_compiler_plugin_registrar_service[0]] if not version_less(v, "2.4.0") else []
120+
) + (
121+
[_component_registrar_service[0]] if version_less(v, "2.4.20") else []
106122
),
107123
outs = [
108124
"%s/com/github/codeql/extractor.name" % v,
@@ -114,6 +130,11 @@ kt_javac_options(
114130
v,
115131
_compiler_plugin_registrar_service[1],
116132
)] if not version_less(v, "2.4.0") else []
133+
) + (
134+
["%s/%s" % (
135+
v,
136+
_component_registrar_service[1],
137+
)] if version_less(v, "2.4.20") else []
117138
),
118139
cmd = "\n".join([
119140
"echo %s-%s > $(RULEDIR)/%s/com/github/codeql/extractor.name" % (_extractor_name_prefix, v, v),
@@ -126,6 +147,12 @@ kt_javac_options(
126147
v,
127148
_compiler_plugin_registrar_service[1],
128149
)] if not version_less(v, "2.4.0") else []
150+
) + (
151+
["cp $(execpath %s) $(RULEDIR)/%s/%s" % (
152+
_component_registrar_service[0],
153+
v,
154+
_component_registrar_service[1],
155+
)] if version_less(v, "2.4.20") else []
129156
)),
130157
),
131158
kt_jvm_library(
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.github.codeql
2+
3+
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
4+
import org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar
5+
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
6+
import org.jetbrains.kotlin.config.CompilerConfiguration
7+
8+
@OptIn(ExperimentalCompilerApi::class)
9+
abstract class Kotlin2ComponentRegistrar : CompilerPluginRegistrar() {
10+
override val supportsK2: Boolean
11+
get() = true
12+
13+
override val pluginId: String
14+
get() = "kotlin-extractor"
15+
16+
private var extensionStorage: CompilerPluginRegistrar.ExtensionStorage? = null
17+
18+
override fun ExtensionStorage.registerExtensions(configuration: CompilerConfiguration) {
19+
this@Kotlin2ComponentRegistrar.extensionStorage = this
20+
doRegisterExtensions(configuration)
21+
}
22+
23+
abstract fun doRegisterExtensions(configuration: CompilerConfiguration)
24+
25+
protected fun registerExtractorExtension(extension: IrGenerationExtension) {
26+
val storage = extensionStorage
27+
?: throw IllegalStateException("registerExtractorExtension called before registerExtensions")
28+
with(storage) {
29+
IrGenerationExtension.registerExtension(extension)
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)