Skip to content

Commit 8cdc109

Browse files
authored
Add support for x_warning_level (#1391)
* Add support for x_warning_level * Docs * Better docs * Better docs
1 parent ac136e7 commit 8cdc109

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

docs/kotlin.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,8 @@ kt_kotlinc_options(<a href="#kt_kotlinc_options-name">name</a>, <a href="#kt_kot
394394
<a href="#kt_kotlinc_options-x_no_param_assertions">x_no_param_assertions</a>, <a href="#kt_kotlinc_options-x_no_receiver_assertions">x_no_receiver_assertions</a>, <a href="#kt_kotlinc_options-x_no_source_debug_extension">x_no_source_debug_extension</a>,
395395
<a href="#kt_kotlinc_options-x_optin">x_optin</a>, <a href="#kt_kotlinc_options-x_report_perf">x_report_perf</a>, <a href="#kt_kotlinc_options-x_sam_conversions">x_sam_conversions</a>, <a href="#kt_kotlinc_options-x_skip_prerelease_check">x_skip_prerelease_check</a>,
396396
<a href="#kt_kotlinc_options-x_suppress_version_warnings">x_suppress_version_warnings</a>, <a href="#kt_kotlinc_options-x_suppress_warning">x_suppress_warning</a>,
397-
<a href="#kt_kotlinc_options-x_type_enhancement_improvements_strict_mode">x_type_enhancement_improvements_strict_mode</a>, <a href="#kt_kotlinc_options-x_use_fir_lt">x_use_fir_lt</a>, <a href="#kt_kotlinc_options-x_use_k2">x_use_k2</a>)
397+
<a href="#kt_kotlinc_options-x_type_enhancement_improvements_strict_mode">x_type_enhancement_improvements_strict_mode</a>, <a href="#kt_kotlinc_options-x_use_fir_lt">x_use_fir_lt</a>, <a href="#kt_kotlinc_options-x_use_k2">x_use_k2</a>,
398+
<a href="#kt_kotlinc_options-x_warning_level">x_warning_level</a>)
398399
</pre>
399400

400401
Define kotlin compiler options.
@@ -439,6 +440,7 @@ Define kotlin compiler options.
439440
| <a id="kt_kotlinc_options-x_type_enhancement_improvements_strict_mode"></a>x_type_enhancement_improvements_strict_mode | Enables strict mode for type enhancement improvements, enforcing stricter type checking and enhancements. | Boolean | optional | `False` |
440441
| <a id="kt_kotlinc_options-x_use_fir_lt"></a>x_use_fir_lt | Compile using LightTree parser with Front-end IR. Warning: this feature is far from being production-ready | Boolean | optional | `False` |
441442
| <a id="kt_kotlinc_options-x_use_k2"></a>x_use_k2 | Compile using experimental K2. K2 is a new compiler pipeline, no compatibility guarantees are yet provided | Boolean | optional | `False` |
443+
| <a id="kt_kotlinc_options-x_warning_level"></a>x_warning_level | Suppress specific warnings globally. Ex: 'OPTION': '(error\|warning\|disabled)' | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{}` |
442444

443445

444446
<a id="kt_ksp_plugin"></a>

src/main/starlark/core/options/opts.kotlinc.bzl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,23 @@ load("@com_github_jetbrains_kotlin//:capabilities.bzl", _KOTLIN_OPTS = "KOTLIN_O
1616
load("//src/main/starlark/core/options:convert.bzl", "convert")
1717
load("//src/main/starlark/core/options:derive.bzl", "derive")
1818

19+
_ALLOWED_SUPPRESS_LEVELS = [
20+
"error",
21+
"warning",
22+
"disabled",
23+
]
24+
25+
def _map_warning_level(values):
26+
if not values:
27+
return None
28+
29+
args = []
30+
for k, v in values.items():
31+
if v not in _ALLOWED_SUPPRESS_LEVELS:
32+
fail("Error: Suppress key '{}' has an invalid value of '{}'".format(k, v))
33+
args.append("-Xwarning-level={}:{}".format(k, v))
34+
return args
35+
1936
def _map_optin_class_to_flag(values):
2037
return ["-opt-in=%s" % v for v in values]
2138

@@ -469,6 +486,15 @@ default: 'first-only-warn' in language version 2.2+, 'first-only' in version 2.1
469486
True: ["-Xuse-k2"],
470487
},
471488
),
489+
"x_warning_level": struct(
490+
args = dict(
491+
default = {},
492+
doc = "Suppress specific warnings globally. Ex: 'OPTION': '(error|warning|disabled)'",
493+
),
494+
type = attr.string_dict,
495+
value_to_flag = None,
496+
map_value_to_flag = _map_warning_level,
497+
),
472498
}
473499

474500
def _merge(key, rule_defined):

0 commit comments

Comments
 (0)