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

Throw exception if 'None' value given to List-type command line options in Bazel transitions #13286

Closed
wants to merge 2 commits into from

Conversation

tobiade
Copy link
Contributor

@tobiade tobiade commented Apr 1, 2021

@google-cla google-cla bot added the cla: yes label Apr 1, 2021
@@ -332,6 +332,8 @@ private static BuildOptions applyTransition(
.convert(
optionValueAsList.stream().map(Object::toString).collect(joining(",")));
}
} else if (def.getType() == List.class && optionValue == null) {
convertedValue = def.getDefaultValue();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please let me know if it's okay to replace with the default value here or if we should be using StarlarkList.empty() instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm also curious if it's okay to perform the override here, or if it makes sense to do it within this block of code above:

        if (optionValue instanceof NoneType) {
          optionValue = null;
        }

I need the OptionDefinition to check if it's a List, so the current spot seemed more convenient.

Copy link
Contributor

Choose a reason for hiding this comment

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

About the first question, it's a good question. My first intuition was None = empty, but there really is something to say for it meaning default. Especially if we already have ways to express empty ("", []).

There's a sensible interpretation that says None = unset, which implies the default.

@brandjon - does None have any incompatible implications in Starlark? Can

   "//command_line_option:copt": None,

(in a transition) reasonably imply unsetting the flag?

Copy link
Contributor

Choose a reason for hiding this comment

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

I just posted an update in the associated issue. I'm still trying to wrap my mind around the three conceptual options:

  1. disallow None
  2. None = empty
  3. None = the flag's default value (as you currently have encoded).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @gregestren. Makes sense. I think if a use-case exists where a user wants to set a flag back to its default (without actually knowing what the default value is), then maybe None might be a good way to achieve this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, I also asked some other core devs. including @brandjon who curates the core Starlark API.

The short consensus, which I find compelling, is these are intriguing design issues. But they're not trivial. Not only are all the above interpretations possible, but None could potentially be a distinct value in its own right, since it's a legitimate value Starlark variables can take.

So basically, we shouldn't try to answer these questions yet. They deserve a deeper and broader design about what flag parsing looks like and how it mixes with Starlark. So if we simply disallow None with a clear error message now, we've solved the crash in #12559, can give users clear enough guidance with the error message, and aren't narrowing our options yet for however we'd ultimately want this to work.

How does that sound to you?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Understood - that makes sense. I'll make that change, thanks for the following up!

@aiuto aiuto requested a review from gregestren April 1, 2021 20:41
@aiuto aiuto added the team-Configurability platforms, toolchains, cquery, select(), config transitions label Apr 1, 2021
…y when given 'None' Starlark value during Bazel transitions
@tobiade tobiade changed the title Default cmd line opts with Java List type to empty when given 'None' value in Bazel transitions Throw exception if 'None' value given to List-type command line options in Bazel transitions Apr 28, 2021
@tobiade
Copy link
Contributor Author

tobiade commented Apr 29, 2021

@gregestren Updated as discussed.

Copy link
Contributor

@gregestren gregestren left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@gregestren
Copy link
Contributor

Please hold for the PR to auto-merge in a timely manner...

@bazel-io bazel-io closed this in ced45af May 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes team-Configurability platforms, toolchains, cquery, select(), config transitions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants