-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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 literal default for allow_multiple build setting in transitions #14908
Allow literal default for allow_multiple build setting in transitions #14908
Conversation
2e082a9
to
3afe347
Compare
Instead of requiring the new value for a build setting with allow_multiple = True specified by a transition to always be a list, we make an exception for the literal default value for two reasons: 1. It ensures that specifying a setting with allow_multiple as an input but not as an output of a transition does not run into the exception below. 2. It provides a clear way to reset the setting to its (literal) default.
38bd5a5
to
5cc7dc6
Compare
@gregestren @lberki could we get this looked at? This potentially fixes a 5.0 regression and it would great to have it in 5.1. |
@Wyverald there are a couple of PRs and issues (at least 4) related to I'll comment on them by today but I'm not ready as of this message to advocate any specific step forward. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally speaking, how much of this PR remains relevant after #14911?
"'%s' allows multiple values and must be set" | ||
+ " in transition using a starlark list instead of single value '%s'", | ||
actualSetting, newValue)); | ||
if (newValue.equals(rule.getAttr(STARLARK_BUILD_SETTING_DEFAULT_ATTR_NAME))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It really took me some time to realize changedSettingToRule
from line 310 is now a misleading name. As I understand, the reality is:
changedSettingToRule
was originally written to encapsulate settings the transition changedbuild_setting
inputs are implicitly changed by transition code as an implementation detail, from non-existent to their explicit default values, to guarantee the transition can read them- Trim input build settings after transition #13971 causes the original logic, which historically only checked user-changed settings, to also include these implicit changes. For the purpose of guaranteeing the default that the transition added are then removed.
I'm worried about these overloading of concepts, even if it keeps the code concise.
What if we broke out the logic some: revert https://github.com/bazelbuild/bazel/pull/13971/files, then do a separate distinct call to getRelevantStarlarkSettingsFromTransition(Settings.INPUTS)
which only replicates the part of validate
that removes an option if it's at its default value?
I realize that takes more refactoring, likely breaking out a helper method for validate()
. But I'd really like to keep the code as clear as possible in transition logic, since it's super-complicated as it is.
At the very least I'd like the naming and commenting (including method Javadoc) to remain accurate. I worry it could be more work to clearly make the commenting accurate than do the refactoring I'm suggesting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// We make an exception for the default value here for two reasons: | ||
// 1. It ensures that specifying a setting with allow_multiple as an input but not as | ||
// an output of a transition does not run into the exception below. | ||
// 2. It provides a clear way to reset the setting to its (literal) default from a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- here feels a bit API-shaky to me. Basically, a transition has to set a setting to a certain type unless it's set to a certain special value in which case it's exempt. I get the intended use case described here. But I can also see transitions that, say, read their values from attributes, which happen to set values to defaults - or not - by coincidence. i.e. whoever's setting the values has no insight into this and may be confused why some arbitrary string works while another fails.
To the point, do you think #14911 obsoletes all this complexity?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree it looks very hacky and is another reason to consider #14972 the better kind of fix. That said, I don't think this accidental resetting would be very realistic: The "magic" literal default value is the only valid one of its type (string rather than list of string) due to type validation and any attribute would only ever yield one type.
To the point, do you think #14911 obsoletes all this complexity?
The new representation of repeated string flags would no longer require any special handling for transitions, so we could eventually delete the entire allowsMultiple
branch. But given that finalizing the design of #14911 will take some more time, either this PR or #14972 are probably needed to deal with the regression for 5.1.0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed on your last point - I'm happy to fast track a temporary fix for the regression. I just wanted to verify the long-term expected state.
Superseded by #14972. |
Instead of requiring the new value for a build setting with
allow_multiple = True specified by a transition to always be a list, we
make an exception for the literal default value for two reasons:
but not as an output of a transition does not run into the exception
below.
Fixes #14894
RELNOTES: Fixed a bug that prevented build settings with
allow_multiple = True
from appearing only as inputs but not asoutputs of a transition.