Skip to content

Commit 86050c1

Browse files
jketemaCopilot
andcommitted
Update rules_kotlin to 2.4.21 with CodeQL patches
Carry forward CodeQL's jdeps and language/API-version customizations for the new upstream release, and fix redundant string conversions rejected by the upgraded Kotlin compiler. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent a61f577 commit 86050c1

11 files changed

Lines changed: 80 additions & 56 deletions

File tree

‎MODULE.bazel‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ bazel_dep(name = "bazel_skylib", version = "1.9.0")
2626
bazel_dep(name = "abseil-cpp", version = "20260107.1", repo_name = "absl")
2727
bazel_dep(name = "nlohmann_json", version = "3.12.0.bcr.1", repo_name = "json")
2828
bazel_dep(name = "fmt", version = "12.1.0-codeql.1")
29-
bazel_dep(name = "rules_kotlin", version = "2.2.2-codeql.1")
29+
bazel_dep(name = "rules_kotlin", version = "2.4.21-codeql.1")
3030
bazel_dep(name = "gazelle", version = "0.54.0")
3131
bazel_dep(name = "rules_dotnet", version = "0.21.5-codeql.1")
3232
bazel_dep(name = "googletest", version = "1.18.0.bcr.1")
@@ -37,6 +37,14 @@ bazel_dep(name = "zstd", version = "1.5.7.bcr.1")
3737

3838
bazel_dep(name = "buildifier_prebuilt", version = "10.1.0", dev_dependency = True)
3939

40+
# Pin the compiler to support the Kotlin 1.8 and 1.9 language versions required by older extractors.
41+
kotlin = use_extension("@rules_kotlin//src/main/starlark/core/repositories:bzlmod_setup.bzl", "rules_kotlin_extensions")
42+
kotlin.kotlinc_version(
43+
sha256 = "a623871f1cd9c938946948b70ef9170879f0758043885bbd30c32f024e511714",
44+
version = "2.2.21",
45+
)
46+
use_repo(kotlin, "btapi_impl", "com_github_google_ksp", "com_github_jetbrains_kotlin", "com_github_jetbrains_kotlin_git", "com_github_pinterest_ktlint", "jarjar", "kotlin_build_tools_api", "kotlinx_coroutines_core_jvm", "kotlinx_serialization_core_jvm", "kotlinx_serialization_json", "kotlinx_serialization_json_jvm")
47+
4048
# Keep edition and version approximately in sync with internal repo.
4149
# the versions there are canonical, the versions here are used for CI in github/codeql, as well as for the vendoring of dependencies.
4250
RUST_EDITION = "2024"

‎java/kotlin-extractor/deps.bzl‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def _kotlin_dep_impl(repository_ctx):
2727
"kotlin-stdlib.jar",
2828
"kotlin-reflect.jar",
2929
"kotlin-script-runtime.jar",
30+
"kotlinx-coroutines-core-jvm.jar",
3031
"trove4j.jar",
3132
):
3233
repository_ctx.symlink("empty.zip", jar)

‎java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6966,7 +6966,7 @@ open class KotlinFileExtractor(
69666966
tw.writeExprs_stringliteral(id, type.javaResult.id, parent, idx)
69676967
tw.writeExprsKotlinType(id, type.kotlinResult.id)
69686968
extractExprContext(id, locId, enclosingCallable, enclosingStmt)
6969-
tw.writeNamestrings(toQuotedLiteral(v.toString()), v.toString(), id)
6969+
tw.writeNamestrings(toQuotedLiteral(v), v, id)
69706970
}
69716971
}
69726972
v == null -> {

‎misc/bazel/registry/modules/rules_kotlin/2.2.2-codeql.1/patches/codeql_add_language_version_option.patch‎

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

‎misc/bazel/registry/modules/rules_kotlin/2.2.2-codeql.1/source.json‎

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

misc/bazel/registry/modules/rules_kotlin/2.2.2-codeql.1/MODULE.bazel renamed to misc/bazel/registry/modules/rules_kotlin/2.4.21-codeql.1/MODULE.bazel

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1+
"""Bazel module manifest for the released rules_kotlin package."""
2+
13
module(
24
name = "rules_kotlin",
3-
version = "2.2.2-codeql.1",
5+
version = "2.4.21-codeql.1",
46
compatibility_level = 1,
57
repo_name = "rules_kotlin",
68
)
79

810
bazel_dep(name = "platforms", version = "0.0.11")
9-
bazel_dep(name = "bazel_skylib", version = "1.7.1")
11+
bazel_dep(name = "bazel_skylib", version = "1.8.2")
1012
bazel_dep(name = "rules_java", version = "8.9.0")
11-
bazel_dep(name = "rules_android", version = "0.6.4")
12-
bazel_dep(name = "bazel_features", version = "1.25.0")
13-
bazel_dep(name = "protobuf", version = "29.0", repo_name = "com_google_protobuf")
14-
bazel_dep(name = "rules_proto", version = "6.0.2", repo_name = "rules_proto")
15-
bazel_dep(name = "abseil-py", version = "2.1.0", repo_name = "py_absl")
16-
bazel_dep(name = "rules_cc", version = "0.0.16")
17-
bazel_dep(name = "bazel_worker_api", version = "0.0.8")
18-
bazel_dep(name = "bazel_worker_java", version = "0.0.8")
13+
bazel_dep(name = "rules_license", version = "1.0.0")
14+
bazel_dep(name = "rules_android", version = "0.7.3")
15+
bazel_dep(name = "bazel_features", version = "1.39.0")
16+
bazel_dep(name = "bazel_lib", version = "3.1.0")
1917

2018
rules_java_toolchains = use_extension("@rules_java//java:extensions.bzl", "toolchains")
2119
use_repo(rules_java_toolchains, "remote_java_tools")
@@ -26,13 +24,16 @@ rules_kotlin_extensions = use_extension(
2624
)
2725
use_repo(
2826
rules_kotlin_extensions,
27+
"btapi_impl",
2928
"com_github_google_ksp",
3029
"com_github_jetbrains_kotlin",
3130
"com_github_pinterest_ktlint",
32-
"kotlin_build_tools_impl",
31+
"jarjar",
32+
"kotlin_build_tools_api",
33+
"kotlinx_coroutines_core_jvm",
3334
"kotlinx_serialization_core_jvm",
3435
"kotlinx_serialization_json",
3536
"kotlinx_serialization_json_jvm",
3637
)
3738

38-
register_toolchains("//kotlin/internal:default_toolchain")
39+
register_toolchains("//kotlin:default_toolchain")
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
CodeQL still builds extractors with Kotlin 1.8 and 1.9 language/API versions.
2+
Keep those supported and keep the API version aligned with the language version.
3+
--- a/src/main/starlark/core/options/opts.kotlinc.bzl
4+
+++ b/src/main/starlark/core/options/opts.kotlinc.bzl
5+
@@ -93,9 +93,7 @@
6+
def _map_language_version_to_flag(version):
7+
if not version:
8+
return None
9+
- if int(version.split(".")[0]) < 2:
10+
- fail("rules_kotlin requires language_version 2.0 or newer; got %s" % version)
11+
- return ["-language-version=%s" % version]
12+
+ return ["-language-version=%s" % version, "-api-version=%s" % version]
13+
14+
def _map_xxlanguage_to_flag(values):
15+
return ["-XXLanguage:%s" % v for v in values]

misc/bazel/registry/modules/rules_kotlin/2.2.2-codeql.1/patches/codeql_do_not_emit_jdeps.patch renamed to misc/bazel/registry/modules/rules_kotlin/2.4.21-codeql.1/patches/codeql_do_not_emit_jdeps.patch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ allows us to not have to specify that option (and therefore pull in `rules_kotli
44
internal repo.
55
--- a/kotlin/settings/BUILD.bazel
66
+++ b/kotlin/settings/BUILD.bazel
7-
@@ -16,6 +16,6 @@ release_archive(
7+
@@ -16,7 +16,7 @@
88
# Flag that controls the emission of jdeps files during kotlin jvm compilation.
99
bool_flag(
1010
name = "jvm_emit_jdeps",
1111
- build_setting_default = True, # Upstream default behavior
1212
+ build_setting_default = False,
1313
visibility = ["//visibility:public"],
1414
)
15-
15+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
rules_kotlin 2.4 propagates the Kotlin warning mode to javac, so the extractor's
2+
Kotlin warn = "error" setting also makes Java warnings fatal. This breaks the
3+
Java 8 target with JDK 25's obsolete source/target option warnings. Keep Kotlin
4+
warnings-as-errors for Kotlin compilation without changing javac warning behavior.
5+
--- a/kotlin/internal/jvm/compile.bzl
6+
+++ b/kotlin/internal/jvm/compile.bzl
7+
@@ -1162,21 +1162,6 @@
8+
for flag in javac_options_to_flags(plugin[JavacOptions])
9+
])
10+
11+
- # Compile the Java half with the same warning mode as the kotlin part, unless the javac
12+
- # options (or a plugin's) already set one: a single `warn` value governs the whole target.
13+
- # A per-diagnostic level in `x_warning_level` limits the derivation, because javac has no
14+
- # equivalent of `-Xwarning-level`. A diagnostic kept at `warning` or `disabled` under
15+
- # `warn = "error"` must not turn every javac warning into an error, and a diagnostic raised
16+
- # to `warning` or `error` under `warn = "off"` must not silence every javac warning.
17+
- if "-nowarn" not in javac_opts and "-Werror" not in javac_opts:
18+
- kotlinc_warn = getattr(kotlinc_options, "warn", None) if kotlinc_options else None
19+
- warning_levels = (getattr(kotlinc_options, "x_warning_level", None) if kotlinc_options else None) or {}
20+
- levels = warning_levels.values()
21+
- if kotlinc_warn == "off" and "error" not in levels and "warning" not in levels:
22+
- javac_opts.append("-nowarn")
23+
- elif kotlinc_warn == "error" and "warning" not in levels and "disabled" not in levels:
24+
- javac_opts.append("-Werror")
25+
-
26+
java_info = java_common.compile(
27+
ctx,
28+
source_files = srcs.java,
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"integrity": "sha256-qjJVRS2+m1LaK6d4fwhl8QeAWIUQnznD1br8IaUhvLY=",
3+
"url": "https://github.com/bazel-contrib/rules_kotlin/releases/download/v2.4.21/rules_kotlin-v2.4.21.tar.gz",
4+
"patches": {
5+
"codeql_add_language_version_option.patch": "sha256-ml0fzhPwNozMi6yKtEn9YLM8LSQE4BWiimdwYzennCo=",
6+
"codeql_do_not_emit_jdeps.patch": "sha256-yoBFnSWJyeF+gyhX+03TMTnRxUQJjup/f/KORdxVsAE=",
7+
"codeql_do_not_propagate_kotlin_warning_mode_to_javac.patch": "sha256-TvfKfINvi1/tcLq3HDUs2doD4kr8AkMv0nsZvUHPjwg="
8+
},
9+
"patch_strip": 1
10+
}

0 commit comments

Comments
 (0)