Skip to content

Commit e5cb6b4

Browse files
Kotlin: address reviewer feedback on versioning and registrar wiring
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 4723dfc commit e5cb6b4

4 files changed

Lines changed: 33 additions & 12 deletions

File tree

MODULE.bazel

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ use_repo(
237237
kotlin_extractor_deps,
238238
"codeql_kotlin_defaults",
239239
"codeql_kotlin_embeddable",
240+
"kotlin-compiler-1.8.0",
241+
"kotlin-compiler-1.9.0-Beta",
242+
"kotlin-compiler-1.9.20-Beta",
240243
"kotlin-compiler-2.0.0-RC1",
241244
"kotlin-compiler-2.0.20-Beta2",
242245
"kotlin-compiler-2.1.0-Beta1",
@@ -246,6 +249,9 @@ use_repo(
246249
"kotlin-compiler-2.3.0",
247250
"kotlin-compiler-2.3.20",
248251
"kotlin-compiler-2.4.0",
252+
"kotlin-compiler-embeddable-1.8.0",
253+
"kotlin-compiler-embeddable-1.9.0-Beta",
254+
"kotlin-compiler-embeddable-1.9.20-Beta",
249255
"kotlin-compiler-embeddable-2.0.0-RC1",
250256
"kotlin-compiler-embeddable-2.0.20-Beta2",
251257
"kotlin-compiler-embeddable-2.1.0-Beta1",
@@ -255,6 +261,9 @@ use_repo(
255261
"kotlin-compiler-embeddable-2.3.0",
256262
"kotlin-compiler-embeddable-2.3.20",
257263
"kotlin-compiler-embeddable-2.4.0",
264+
"kotlin-stdlib-1.8.0",
265+
"kotlin-stdlib-1.9.0-Beta",
266+
"kotlin-stdlib-1.9.20-Beta",
258267
"kotlin-stdlib-2.0.0-RC1",
259268
"kotlin-stdlib-2.0.20-Beta2",
260269
"kotlin-stdlib-2.1.0-Beta1",

java/kotlin-extractor/BUILD.bazel

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ _extractor_name_prefix = "%s-%s" % (
5353
"embeddable" if _for_embeddable else "standalone",
5454
)
5555

56+
_compiler_plugin_registrar_service_source = "src/main/resources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar"
57+
_compiler_plugin_registrar_service_target = "META-INF/services/org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar"
58+
5659
py_binary(
5760
name = "generate_dbscheme",
5861
srcs = ["generate_dbscheme.py"],
@@ -64,12 +67,12 @@ _resources = [
6467
r[len("src/main/resources/"):],
6568
)
6669
for r in glob(["src/main/resources/**"])
67-
if r != "src/main/resources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar"
70+
if r != _compiler_plugin_registrar_service_source
6871
]
6972

7073
_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",
74+
_compiler_plugin_registrar_service_source,
75+
_compiler_plugin_registrar_service_target,
7376
)
7477

7578
kt_javac_options(
Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
@file:Suppress("DEPRECATION", "DEPRECATION_ERROR")
2-
@file:OptIn(ExperimentalCompilerApi::class)
3-
41
package com.github.codeql
52

63
import com.intellij.mock.MockProject
4+
import com.intellij.openapi.extensions.LoadingOrder
75
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
86
import org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar
97
import org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar
108
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
119
import org.jetbrains.kotlin.config.CompilerConfiguration
1210

11+
@OptIn(ExperimentalCompilerApi::class)
12+
@Suppress("DEPRECATION", "DEPRECATION_ERROR")
1313
abstract class Kotlin2ComponentRegistrar : CompilerPluginRegistrar(), ComponentRegistrar {
1414
override val supportsK2: Boolean
1515
get() = true
@@ -22,11 +22,11 @@ abstract class Kotlin2ComponentRegistrar : CompilerPluginRegistrar(), ComponentR
2222
project: MockProject,
2323
configuration: CompilerConfiguration
2424
) {
25-
// In 2.4.0, we use CompilerPluginRegistrar path instead.
26-
// This is only called if the compiler uses the ComponentRegistrar service file.
27-
// We do nothing here since registerExtensions will be called separately.
25+
this.project = project
26+
doRegisterExtensions(configuration)
2827
}
2928

29+
private var project: MockProject? = null
3030
private var extensionStorage: CompilerPluginRegistrar.ExtensionStorage? = null
3131

3232
override fun ExtensionStorage.registerExtensions(configuration: CompilerConfiguration) {
@@ -37,9 +37,15 @@ abstract class Kotlin2ComponentRegistrar : CompilerPluginRegistrar(), ComponentR
3737
abstract fun doRegisterExtensions(configuration: CompilerConfiguration)
3838

3939
protected fun registerExtractorExtension(extension: IrGenerationExtension) {
40-
val storage = extensionStorage ?: throw IllegalStateException("registerExtractorExtension called before registerExtensions")
41-
with(storage) {
42-
IrGenerationExtension.registerExtension(extension)
40+
extensionStorage?.let { storage ->
41+
with(storage) {
42+
IrGenerationExtension.registerExtension(extension)
43+
}
44+
return
4345
}
46+
// Fallback for ComponentRegistrar-based registration to keep legacy ordering semantics.
47+
val p = project ?: throw IllegalStateException("registerExtractorExtension called before registration")
48+
val extensionPoint = p.extensionArea.getExtensionPoint(IrGenerationExtension.extensionPointName)
49+
extensionPoint.registerExtension(extension, LoadingOrder.LAST, p)
4450
}
4551
}

java/kotlin-extractor/versions.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# when updating this list, `bazel mod tidy` should be run from `codeql` to update `MODULE.bazel`
22
VERSIONS = [
3+
"1.8.0",
4+
"1.9.0-Beta",
5+
"1.9.20-Beta",
36
"2.0.0-RC1",
47
"2.0.20-Beta2",
58
"2.1.0-Beta1",

0 commit comments

Comments
 (0)