Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not pass default values of kotlinc options. #975

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/main/starlark/core/options/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
load("//src/main/starlark/release:packager.bzl", "release_archive")
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load(":opts.kotlinc.test.bzl", "kt_kotlinc_options_test")
load(":opts.kotlinc.bzl", "kt_kotlinc_options")

release_archive(
name = "pkg",
srcs = glob(
["*.bzl"],
exclude = ["*.test.bzl"],
),
src_map = {
"BUILD.release.bazel": "BUILD.bazel",
Expand All @@ -19,3 +22,13 @@ bzl_library(
"@com_github_jetbrains_kotlin//:capabilities",
],
)

kt_kotlinc_options(
name = "defaults",
)

kt_kotlinc_options_test(
name = "do_not_set_defaults",
target_under_test = ":defaults",
want_flags = [],
)
4 changes: 3 additions & 1 deletion src/main/starlark/core/options/convert.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ def _to_flags(opts, attr_provider):
list of flags to add to the command line.
"""
if not attr_provider:
return ""
return []

flags = []
for n, o in opts.items():
value = getattr(attr_provider, n, None)
if value == o.args["default"]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this logic comparing the input value on the user defined kt_kotlinc_options target to the default attr value specified in the opts value, and skipping if true?

continue
if o.value_to_flag and o.value_to_flag.get(derive.info, None):
info = o.value_to_flag[derive.info]
flag = info.derive(info.ctx, value)
Expand Down
2 changes: 1 addition & 1 deletion src/main/starlark/core/options/opts.kotlinc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -331,4 +331,4 @@ def kotlinc_options_to_flags(kotlinc_options):
Returns:
list of flags to add to the command line.
"""
return convert.javac_options_to_flags(_KOPTS, kotlinc_options)
return convert.kotlinc_options_to_flags(_KOPTS, kotlinc_options)
34 changes: 34 additions & 0 deletions src/main/starlark/core/options/opts.kotlinc.test.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
load("@bazel_skylib//lib:unittest.bzl", "analysistest", "unittest")
load(":opts.kotlinc.bzl", "KotlincOptions", "kotlinc_options_to_flags")

def _kt_kotlinc_options_test_impl(ctx):
Copy link
Collaborator

@Bencodes Bencodes May 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

env = analysistest.begin(ctx)

target_under_test = analysistest.target_under_test(env)

want = ctx.attr.want_flags

got = kotlinc_options_to_flags(target_under_test[KotlincOptions])

extra = [f for f in got if f not in want]
missing = [f for f in want if f not in got]

fails = []
if extra:
fails.append("not want %s" % extra)
if missing:
fails.append("want %s" % missing)

if fails:
unittest.fail(env, "\n".join(fails + ["Wanted %s" % want, "Got %s" % got]))

return analysistest.end(env)

kt_kotlinc_options_test = analysistest.make(
_kt_kotlinc_options_test_impl,
attrs = {
"want_flags": attr.string_list(
mandatory = True,
),
},
)