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

Convert Starlark options with Starlark#fromJava in build_options #18988

Closed

Conversation

fmeum
Copy link
Collaborator

@fmeum fmeum commented Jul 19, 2023

cquery's build_options function now ensures that Starlark option values are converted to Starlark types before being added to the dict of all options, fixing a crash observed for list-typed build settings specified on the command line.

Fixes #18977

`cquery`'s `build_config` function now ensures that Starlark option
values are converted to Starlark types before being added to the `dict`
of all options, fixing a crash observed for list-typed build settings
specified on the command line.
@fmeum fmeum marked this pull request as ready for review July 19, 2023 12:01
@fmeum fmeum requested a review from gregestren July 19, 2023 12:01
@github-actions github-actions bot added awaiting-review PR is awaiting review from an assigned reviewer team-Configurability platforms, toolchains, cquery, select(), config transitions labels Jul 19, 2023
@gregestren
Copy link
Contributor

cquery's build_config function now ensures that Starlark option values are converted to Starlark types before being added to the dict of all options, fixing a crash observed for list-typed build settings specified on the command line.

Nit: build_options.

As an aside, I didn't realize this function exists. Does it offer anything over a bazel config call?

@fmeum fmeum changed the title Convert Starlark options with Starlark#fromJava in build_config Convert Starlark options with Starlark#fromJava in build_options Jul 19, 2023
@fmeum
Copy link
Collaborator Author

fmeum commented Jul 19, 2023

I can't think of anything that couldn't also be done with bazel config, but I can see the convenience of not needing to chain two Bazel invocations and being able to use Starlark instead of e.g. bah.

@gregestren gregestren added awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally and removed awaiting-review PR is awaiting review from an assigned reviewer labels Jul 19, 2023
EOF

bazel cquery "//$pkg:bar" --output=starlark \
--starlark:file=$pkg/expr.star > output 2>"$TEST_log" || fail "Expected success"

assert_contains "//$pkg:bar%None%False" output
assert_contains "//$pkg:bar%None%False%None" output
Copy link

@Colecf Colecf Jul 19, 2023

Choose a reason for hiding this comment

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

Why is this None instead of the build_setting_default of ["c"]? This isn't necessarily something that needs to be changed if this is the behavior we want. I guess this does allow differentiating between an unset value and a value set to the default.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a consequence of how Starlark options are implemented: When they haven't been set anywhere, they aren't tracked and the dict of all options just won't contain any value for them, not even the default.

This makes sense given the decentralized nature of Bazel: Knowing all Starlark options and their default values would require loading all packages (and thus all repos) eagerly.

Copy link

Choose a reason for hiding this comment

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

Ah, that does make some sense, but then it is weird how then you can get the actual value when its set despite bar having no dependency on mylistflag.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's why build_options is "magic": It gives you access to the full internal view of all options that Bazel maintains. This has an entry for mylistflag simply because it has been set on the command-line. build_options doesn't care about dependencies here, which is why it is only made available in cquery, not in regular Starlark.

@github-actions github-actions bot removed the awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally label Jul 20, 2023
@fmeum fmeum deleted the 18977-starlark-from-java-build-options branch July 24, 2023 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-Configurability platforms, toolchains, cquery, select(), config transitions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bazel crashes when using cquery + build_options() + setting starlark string_list flags in platform_mappings
4 participants