-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -329,11 +329,20 @@ public static Map<String, BuildOptions> validate( | |
if (allowsMultiple) { | ||
// if this setting allows multiple settings | ||
if (!(newValue instanceof List)) { | ||
throw new TransitionException( | ||
String.format( | ||
"'%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))) { | ||
// 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 commentThe reason will be displayed to describe this comment to others. Learn more.
To the point, do you think #14911 obsoletes all this complexity? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
The new representation of repeated string flags would no longer require any special handling for transitions, so we could eventually delete the entire There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
// transition. | ||
newValue = ImmutableList.of(newValue); | ||
} else { | ||
throw new TransitionException( | ||
String.format( | ||
"'%s' allows multiple values and must be set" | ||
+ " in transition using a starlark list instead of single value '%s'", | ||
actualSetting, newValue)); | ||
} | ||
} | ||
List<?> rawNewValueAsList = (List<?>) newValue; | ||
List<Object> convertedValue = new ArrayList<>(); | ||
|
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 themI'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 ofvalidate
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.
That's a very good point - input build settings should be cleared unconditionally rather than undergo validation. I created #14972 for this refactoring and a better fix for #14894.