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

Allow string_list flags to be set via repeated flag uses #14911

Closed

Conversation

fmeum
Copy link
Collaborator

@fmeum fmeum commented Feb 25, 2022

For all parts of Bazel other than option parsing, string build setting
flags with allow_multiple = True should behave just like string_list
settings, even though they are fundamentally of a different type. This
requires a lot of special casing all over the code base and also causes
confusing user-facing behavior when transitioning on such settings.

This commit deprecates the allow_multiple named parameter of
config.string and as a replacement introduces a new named parameter
repeatable on config.string_list. Settings with the latter set to True
behave exactly like string settings with allow_multiple = True with
respect to command-line option parsing and exactly like ordinary
string_list flags in all other situations.

Fixes #13817

@gregestren
Copy link
Contributor

gregestren commented Mar 4, 2022

I like what you're doing here but this is complicated enough (from an API perspective) where I'd like to see a proper design doc. Would you be up for that? I'm not asking anything complex: just a small doc that clearly states the issue and why this approach solves it effectively. And ensures everyone's collaboratively considering all angles.

For example, there are important nuances (which you acknowledge in the PR) I'd like to be upfront clear: a repeated string_list with --//foo=a,b is different than a singleton string_list with --//foo=a,b.

I'm asking this because build_setting is basically the "new" API for builtin Bazel flags. The idea is we can eventually replace all builtin flags that users - not core devs - should control. While that goal alone is great, there's also an opportunity to avoid the complicated typing API that powers native flags. Those grew over a long time, somewhat ad hoc in response to isolated use cases, and is now unfortunately complex.

I'd like to avoid the same outcome with build_setting. We're already running into nuanced complications and API tweaks. So I really want to make sure API changes are cautiously vetted with long-term, generic sustainability in mind. Keep the APIs as simple as possible while still powerful (in particular push as much complication as we can into Starlark, which is built for that). And try to minimize long-term API churn, migrations, and deprecations.

This isn't a knock at your proposal (which is super-promising!). It's general caution I have for any API changes in this area. But I agree there are real API issues to address, and the status quo is insufficient.

CC @brandjon @comius who are also thinking about general API curation.

@gregestren
Copy link
Contributor

gregestren commented Mar 4, 2022

I'm also curious how or if this applies to other types. Like a theoretical int_list, or any other novel data type. Would this API generalize that way? Should it? (there's a good argument that it shouldn't). Would love to hear some design brainstorming about that too.

@fmeum fmeum force-pushed the 13817-allow-multiple-list-default branch from 70a4290 to e33a5e4 Compare March 6, 2022 16:35
@fmeum
Copy link
Collaborator Author

fmeum commented Mar 6, 2022

I will try to get a short doc started. I'm now leaning towards using a more descriptive argument, e.g. something like flag_style = "repeated" vs. flag_style = "comma", and a doc would be a great way to get feedback on this.

I'm also curious how or if this applies to other types. Like a theoretical int_list, or any other novel data type. Would this API generalize that way? Should it? (there's a good argument that it shouldn't). Would love to hear some design brainstorming about that too.

It would not require any additional code apart from adding the parameter to intSetting. Given that there isn't even an int_list setting yet, I'm not sure it would make sense to add at this point though.

@fmeum
Copy link
Collaborator Author

fmeum commented Mar 7, 2022

@gregestren I submitted bazelbuild/proposals#248.

@gregestren
Copy link
Contributor

To be clear, I'm hesitant to support int_list. Once we're combining arbitrary data types I figure it's cleaner for the API to use string_list and have implementers parse that into whatever they need in Starlark.

@sgowroji sgowroji added the awaiting-user-response Awaiting a response from the author label May 5, 2022
@sgowroji sgowroji added awaiting-review PR is awaiting review from an assigned reviewer and removed awaiting-user-response Awaiting a response from the author labels Jun 13, 2022
@hlopko
Copy link
Member

hlopko commented Jun 15, 2022

(this is a super-useful feature and we from rules_rust are looking forward to using it :)

@gregestren
Copy link
Contributor

Sorry we're not faster on this, @hlopko and everyone else. Still on our radar. @fmeum and I also have an open communication channel so we'll get this properly worked out at some point.

@gregestren
Copy link
Contributor

FYI @fmeum , @aranguyen and I have a sync next week to try to move this forward.

@fmeum fmeum force-pushed the 13817-allow-multiple-list-default branch from 70a4290 to 72a44a3 Compare June 30, 2022 17:19
@fmeum
Copy link
Collaborator Author

fmeum commented Jun 30, 2022

@aranguyen I updated the PR to reflect the update to the proposal I submitted in bazelbuild/proposals#266

@fmeum fmeum force-pushed the 13817-allow-multiple-list-default branch 2 times, most recently from 90b0660 to e04ea41 Compare June 30, 2022 18:13
@aranguyen aranguyen self-assigned this Jul 8, 2022
@aranguyen aranguyen self-requested a review July 8, 2022 19:30
+ " implementation function will be a list of strings. Insertion order and"
+ " repeated values are both maintained. This list can be post-processed in the"
+ " build setting implementation function if different behavior is desired.",
"Deprecated, use a <code>string_list</code> setting with"
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this actually do anything beside doc? I was thinking it would be nice to emit a WARNING from now on if allowMultiple is being used. Thoughts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Outside Google, such a warning probably wouldn't work that well: The ones seeing the warning (ruleset users on a new Bazel version) would not be the ones in a position to fix it (ruleset authors). In the past, I think that this has been handled via an --incompatible_* flag, which is flipped at some point with a full downstream pipeline running against the popular rulesets before the flip.

@@ -3025,6 +3025,51 @@ public void testBuildSettingValue_allowMultipleSetting() throws Exception {
.containsExactly("some-other-value", "some-other-other-value");
}

@SuppressWarnings("unchecked")
@Test
Copy link
Contributor

Choose a reason for hiding this comment

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

all of these test cases are great. Thank you for adding them. Could we also add test case for this example

--copt=a,b,c        --> ["a,b,c"]
--copt=a --copt=b,c --> ["a", "b,c"]

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Great point, added.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you!

For all parts of Bazel other than option parsing, string build setting
flags with `allow_multiple = True` should behave just like `string_list`
settings, even though they are fundamentally of a different type. This
requires a lot of special casing all over the code base and also causes
confusing user-facing behavior when transitioning on such settings.

This commit deprecates the `allow_multiple` named parameter of
`config.string` and as a replacement introduces a new `repeatable`
parameter on `config.string_list`. Settings with the latter set to True
behave exactly like `string` settings with `allow_multiple = True` with
respect to command-line option parsing and exactly like ordinary
`string_list` flags in all other situations.
@fmeum fmeum force-pushed the 13817-allow-multiple-list-default branch from e04ea41 to 3b4b3a8 Compare July 13, 2022 11:08
Copy link
Contributor

@aranguyen aranguyen left a comment

Choose a reason for hiding this comment

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

This looks good to me. I'm trying out a new internal review process. If all goes well, this should be merged soon. Thanks for your patience.

@@ -3025,6 +3025,51 @@ public void testBuildSettingValue_allowMultipleSetting() throws Exception {
.containsExactly("some-other-value", "some-other-other-value");
}

@SuppressWarnings("unchecked")
@Test
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you!

@aranguyen aranguyen 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 15, 2022
@aranguyen aranguyen removed the request for review from gregestren July 15, 2022 12:59
@sgowroji sgowroji removed the awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally label Jul 20, 2022
@fmeum fmeum deleted the 13817-allow-multiple-list-default branch July 20, 2022 17:29
@fmeum
Copy link
Collaborator Author

fmeum commented Jul 20, 2022

@bazel-io flag

@bazel-io bazel-io added the potential release blocker Flagged by community members using "@bazel-io flag". Should be added to a release blocker milestone label Jul 20, 2022
@fmeum
Copy link
Collaborator Author

fmeum commented Jul 20, 2022

@gregestren Do you think we should add an incompatible flag disabling the old allow_multiple parameter?

@ShreeM01
Copy link
Contributor

@bazel-io fork 5.3.0

aranguyen pushed a commit to aranguyen/bazel that referenced this pull request Jul 20, 2022
For all parts of Bazel other than option parsing, string build setting
flags with `allow_multiple = True` should behave just like `string_list`
settings, even though they are fundamentally of a different type. This
requires a lot of special casing all over the code base and also causes
confusing user-facing behavior when transitioning on such settings.

This commit deprecates the `allow_multiple` named parameter of
`config.string` and as a replacement introduces a new named parameter
`repeatable` on `config.string_list`. Settings with the latter set to True
behave exactly like `string` settings with `allow_multiple = True` with
respect to command-line option parsing and exactly like ordinary
`string_list` flags in all other situations.

Fixes bazelbuild#13817

Closes bazelbuild#14911.

PiperOrigin-RevId: 462146752
Change-Id: I91ddc4328a1b2244f4303fcda7b4228b182a5d56
aranguyen pushed a commit to aranguyen/bazel that referenced this pull request Jul 20, 2022
For all parts of Bazel other than option parsing, string build setting
flags with `allow_multiple = True` should behave just like `string_list`
settings, even though they are fundamentally of a different type. This
requires a lot of special casing all over the code base and also causes
confusing user-facing behavior when transitioning on such settings.

This commit deprecates the `allow_multiple` named parameter of
`config.string` and as a replacement introduces a new named parameter
`repeatable` on `config.string_list`. Settings with the latter set to True
behave exactly like `string` settings with `allow_multiple = True` with
respect to command-line option parsing and exactly like ordinary
`string_list` flags in all other situations.

Fixes bazelbuild#13817

Closes bazelbuild#14911.

PiperOrigin-RevId: 462146752
Change-Id: I91ddc4328a1b2244f4303fcda7b4228b182a5d56
@fmeum
Copy link
Collaborator Author

fmeum commented Jul 21, 2022

@kshyanashree The bazel-io fork command doesn't seem to have worked.

@sgowroji
Copy link
Member

@bazel-io fork 5.3.0

@bazel-io bazel-io removed the potential release blocker Flagged by community members using "@bazel-io flag". Should be added to a release blocker milestone label Jul 21, 2022
ckolli5 pushed a commit to ckolli5/bazel that referenced this pull request Jul 21, 2022
For all parts of Bazel other than option parsing, string build setting
flags with `allow_multiple = True` should behave just like `string_list`
settings, even though they are fundamentally of a different type. This
requires a lot of special casing all over the code base and also causes
confusing user-facing behavior when transitioning on such settings.

This commit deprecates the `allow_multiple` named parameter of
`config.string` and as a replacement introduces a new named parameter
`repeatable` on `config.string_list`. Settings with the latter set to True
behave exactly like `string` settings with `allow_multiple = True` with
respect to command-line option parsing and exactly like ordinary
`string_list` flags in all other situations.

Fixes bazelbuild#13817

Closes bazelbuild#14911.

PiperOrigin-RevId: 462146752
Change-Id: I91ddc4328a1b2244f4303fcda7b4228b182a5d56
sgowroji pushed a commit that referenced this pull request Jul 22, 2022
For all parts of Bazel other than option parsing, string build setting
flags with `allow_multiple = True` should behave just like `string_list`
settings, even though they are fundamentally of a different type. This
requires a lot of special casing all over the code base and also causes
confusing user-facing behavior when transitioning on such settings.

This commit deprecates the `allow_multiple` named parameter of
`config.string` and as a replacement introduces a new named parameter
`repeatable` on `config.string_list`. Settings with the latter set to True
behave exactly like `string` settings with `allow_multiple = True` with
respect to command-line option parsing and exactly like ordinary
`string_list` flags in all other situations.

Fixes #13817

Closes #14911.

PiperOrigin-RevId: 462146752
Change-Id: I91ddc4328a1b2244f4303fcda7b4228b182a5d56

Co-authored-by: Fabian Meumertzheim <[email protected]>
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.

config.string with allow_multiple=True should use list for build_setting_default
7 participants