Skip to content

Commit d309b84

Browse files
jketemaCopilot
andcommitted
Keep Kotlin warning mode scoped to Kotlin compilation
Avoid propagating Kotlin warn=error to javac in rules_kotlin 2.4. Preserve Java warnings as warnings instead of suppressing the JDK 25 options category, and remove the local javac lint override. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 6663517 commit d309b84

3 files changed

Lines changed: 28 additions & 3 deletions

File tree

‎java/kotlin-extractor/BUILD.bazel‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ _component_registrar_service = (
9191
kt_javac_options(
9292
name = "javac-options",
9393
release = "8",
94-
# JDK 25 reports Java 8 option warnings; keep them from becoming errors via Kotlin's warn = "error".
95-
x_lint = ["-options"],
9694
)
9795

9896
[
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Keep Kotlin warning settings scoped to Kotlin compilation. In particular, do not
2+
turn javac warnings into errors when Kotlin's warn = "error".
3+
--- a/kotlin/internal/jvm/compile.bzl
4+
+++ b/kotlin/internal/jvm/compile.bzl
5+
@@ -1162,21 +1162,6 @@
6+
for flag in javac_options_to_flags(plugin[JavacOptions])
7+
])
8+
9+
- # Compile the Java half with the same warning mode as the kotlin part, unless the javac
10+
- # options (or a plugin's) already set one: a single `warn` value governs the whole target.
11+
- # A per-diagnostic level in `x_warning_level` limits the derivation, because javac has no
12+
- # equivalent of `-Xwarning-level`. A diagnostic kept at `warning` or `disabled` under
13+
- # `warn = "error"` must not turn every javac warning into an error, and a diagnostic raised
14+
- # to `warning` or `error` under `warn = "off"` must not silence every javac warning.
15+
- if "-nowarn" not in javac_opts and "-Werror" not in javac_opts:
16+
- kotlinc_warn = getattr(kotlinc_options, "warn", None) if kotlinc_options else None
17+
- warning_levels = (getattr(kotlinc_options, "x_warning_level", None) if kotlinc_options else None) or {}
18+
- levels = warning_levels.values()
19+
- if kotlinc_warn == "off" and "error" not in levels and "warning" not in levels:
20+
- javac_opts.append("-nowarn")
21+
- elif kotlinc_warn == "error" and "warning" not in levels and "disabled" not in levels:
22+
- javac_opts.append("-Werror")
23+
-
24+
java_info = java_common.compile(
25+
ctx,
26+
source_files = srcs.java,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"url": "https://github.com/bazel-contrib/rules_kotlin/releases/download/v2.4.21/rules_kotlin-v2.4.21.tar.gz",
44
"patches": {
55
"codeql_add_language_version_option.patch": "sha256-ml0fzhPwNozMi6yKtEn9YLM8LSQE4BWiimdwYzennCo=",
6-
"codeql_do_not_emit_jdeps.patch": "sha256-yoBFnSWJyeF+gyhX+03TMTnRxUQJjup/f/KORdxVsAE="
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-IWR4wEbHNEcaAAwFnZA2uHy99kviyuLr5mjzc1TOTMs="
78
},
89
"patch_strip": 1
910
}

0 commit comments

Comments
 (0)