Generate kotlinc options from kotlin-compiler-arguments-description#1406
Generate kotlinc options from kotlin-compiler-arguments-description#1406agluszak wants to merge 10 commits intobazelbuild:masterfrom
Conversation
restingbull
left a comment
There was a problem hiding this comment.
Aside from a few small backward compatibility issues, the approach looks ok.
Need to be solved:
- Enumerated flags will need a set of valid values -- because you'd rather have the build fail in analysis that compiler invocation. Some invocations can live very deep in a build graph, which will cause maintenance headaches.
- Flags must live on an allow list. The
friendsflag is the best example, as it pretty much cannot be used correctly, and overlaps with existing rule functionality.
Finally, please remove extra_kotlinc_args. That will inevitably be misused in large code repositories for all the reasons that the flags are treated as attributes.
...ain/starlark/core/repositories/kotlin/capabilities_2.2.bzl.com_github_jetbrains_kotlin.bazel
Outdated
Show resolved
Hide resolved
...n/starlark/core/repositories/kotlin/generated_opts_2.2.bzl.com_github_jetbrains_kotlin.bazel
Outdated
Show resolved
Hide resolved
...n/starlark/core/repositories/kotlin/generated_opts_2.2.bzl.com_github_jetbrains_kotlin.bazel
Outdated
Show resolved
Hide resolved
20c7b23 to
7993c70
Compare
… kotlin-compiler-arguments-description artifact from JetBrains. - Auto-generated options: WriteKotlincCapabilities generates both capabilities.bzl (flag existence/stability metadata) and generated_opts.bzl (full typed Starlark options) from the compiler metadata artifact. - Simplified maintenance: Manual _KOPTS dict replaced with GENERATED_KOPTS import, with _MANUAL_KOPTS for special cases only. Changes: - Add kotlin-compiler-arguments-description dependency (version must match kotlin compiler version) - Rewrite WriteKotlincCapabilities to use the new artifact - Generate generated_opts_X.Y.bzl with attr.bool for booleans, attr.string for strings, attr.string_list for arrays - Simplify opts.kotlinc.bzl to merge generated + manual options
...n/starlark/core/repositories/kotlin/generated_opts_2.3.bzl.com_github_jetbrains_kotlin.bazel
Outdated
Show resolved
Hide resolved
...n/starlark/core/repositories/kotlin/generated_opts_2.3.bzl.com_github_jetbrains_kotlin.bazel
Outdated
Show resolved
Hide resolved
...n/starlark/core/repositories/kotlin/generated_opts_2.3.bzl.com_github_jetbrains_kotlin.bazel
Outdated
Show resolved
Hide resolved
...n/starlark/core/repositories/kotlin/generated_opts_2.3.bzl.com_github_jetbrains_kotlin.bazel
Outdated
Show resolved
Hide resolved
...n/starlark/core/repositories/kotlin/generated_opts_2.3.bzl.com_github_jetbrains_kotlin.bazel
Outdated
Show resolved
Hide resolved
...n/starlark/core/repositories/kotlin/generated_opts_2.3.bzl.com_github_jetbrains_kotlin.bazel
Outdated
Show resolved
Hide resolved
...n/starlark/core/repositories/kotlin/generated_opts_2.3.bzl.com_github_jetbrains_kotlin.bazel
Outdated
Show resolved
Hide resolved
| map_value_to_flag = _map_string_flag("-jvm-default"), | ||
| ), | ||
| "jvm_target": struct( | ||
| flag = "-jvm-target", |
There was a problem hiding this comment.
This is set by the task, so it shouldn't be visible.
src/main/kotlin/io/bazel/kotlin/generate/WriteKotlincCapabilities.kt
Outdated
Show resolved
Hide resolved
|
@agluszak if we are making incompatible release anyway (Boolean -> String), it's worth comparing compiler arguments before and after, including default values, so it won't be a complete surprise (and document those changes in changelog). |
that's reverted |
|
@restingbull okay, I think everything's been addressed |
# Conflicts: # docs/kotlin.md # src/main/starlark/core/options/opts.kotlinc.bzl # src/main/starlark/core/repositories/kotlin/capabilities_2.3.bzl.com_github_jetbrains_kotlin.bazel
| type = attr.bool, | ||
| value_to_flag = {True: ["-Xallow-unstable-dependencies"]}, | ||
| ), | ||
| "x_annotation_default_target": struct( |
| type = attr.bool, | ||
| value_to_flag = {True: ["-Xcheck-phase-conditions"]}, | ||
| ), | ||
| "x_common_sources": struct( |
There was a problem hiding this comment.
This adds source files to the compilation -- it's not a reasonable option for the compiler.
| value_to_flag = {True: ["-Xexplicit-backing-fields"]}, | ||
| ), | ||
| "x_fragment_dependency": struct( | ||
| flag = "-Xfragment-dependency", |
| value_to_flag = None, | ||
| map_value_to_flag = _map_string_list_flag("-Xfragment-dependency"), | ||
| ), | ||
| "x_fragment_friend_dependency": struct( |
| map_value_to_flag = _map_string_list_flag("-Xfragment-friend-dependency"), | ||
| ), | ||
| "x_fragment_refines": struct( | ||
| flag = "-Xfragment-refines", |
There was a problem hiding this comment.
This is a wierd one. I'm not sure this make sense to be exposed as an option -- it seems more like a feature that should be defined in the rules.
| value_to_flag = None, | ||
| map_value_to_flag = _map_string_list_flag("-Xfragment-refines"), | ||
| ), | ||
| "x_fragment_sources": struct( |
| value_to_flag = None, | ||
| map_value_to_flag = _map_string_list_flag("-Xfragment-sources"), | ||
| ), | ||
| "x_fragments": struct( |
There was a problem hiding this comment.
See other -Xfragment flags. Pretty sure this are difficult, if not impossible to use correct when compiling via the rules.
restingbull
left a comment
There was a problem hiding this comment.
Given how often flags that do not make sense within the rules are sneaking into the generated options, it seems like having an allow list would make a lot more sense than a disallow list.
Implement automatic generation of kotlinc options using the official kotlin-compiler-arguments-description artifact from JetBrains.
Changes:
Closes #1444