-
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
Add incompatible_disallow_rule_execution_platform_constraints_allowed flag. #8145
Conversation
flag. Part of bazelbuild#8136 and bazelbuild#8134. RELNOTES: Adds incompatible_disallow_rule_execution_platform_constraints_allowed, which disallows the use of the "execution_platform_constraints_allowed" attribute when defining new rules.
@@ -398,8 +398,13 @@ public BaseFunction rule( | |||
execCompatibleWith.getContents(String.class, "exec_compatile_with"), | |||
ast.getLocation())); | |||
} | |||
if (executionPlatformConstraintsAllowed) { | |||
|
|||
if (funcallEnv.getSemantics().incompatibleDisallowRuleExecutionPlatformConstraintsAllowed()) { |
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.
This doesn't look like the fully incompatible change you want -- a user can still specify rule(..., execution_platform_constraints_allowed = False), it just would have no effect.
I'd recommend the following instead of any change in this class:
- Introduce a new FlagIdentifier entry in StarlarkSemantics.java for the new flag
- In SkylarkRuleFunctionsApi.java, find the @param for execution_platform_constraints_allowed, and set the following fields on it:
A. disableWithFlag = [new flag identifier]
B. valueWhenDisabled = "True"
This should work out-of-the-box (but you should write a specific test for it, just in case :)) Let me know if you run into any issues!
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.
Thanks, this is much cleaner.
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.
Don't forget to add a test~!
@@ -623,6 +637,8 @@ public StarlarkSemantics toSkylarkSemantics() { | |||
.incompatibleDisallowOldOctalNotation(incompatibleDisallowOldOctalNotation) | |||
.incompatibleDisallowOldStyleArgsAdd(incompatibleDisallowOldStyleArgsAdd) | |||
.incompatibleDisallowStructProviderSyntax(incompatibleDisallowStructProviderSyntax) | |||
.incompatibleDisallowRuleExecutionPlatformConstraintsAllowed( |
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.
When introducing new flags, you also need to update SkylarkSemanticsConsistencyTest.java
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.
Done.
@@ -54,6 +54,7 @@ | |||
INCOMPATIBLE_NO_TARGET_OUTPUT_GROUP(StarlarkSemantics::incompatibleNoTargetOutputGroup), | |||
INCOMPATIBLE_NO_ATTR_LICENSE(StarlarkSemantics::incompatibleNoAttrLicense), | |||
INCOMPATIBLE_OBJC_FRAMEWORK_CLEANUP(StarlarkSemantics::incompatibleObjcFrameworkCleanup), | |||
INCOMPATIBLE_DISALLOW_RULE_EXECUTION_PLATFORM_CONSTRAINTS_ALLOWED(StarlarkSemantics::incompatibleDisallowRuleExecutionPlatformConstraintsAllowed), |
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.
wrap to avoid line length limit
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.
Grr my formatter script didn't work, sorry.
@@ -398,8 +398,13 @@ public BaseFunction rule( | |||
execCompatibleWith.getContents(String.class, "exec_compatile_with"), | |||
ast.getLocation())); | |||
} | |||
if (executionPlatformConstraintsAllowed) { | |||
|
|||
if (funcallEnv.getSemantics().incompatibleDisallowRuleExecutionPlatformConstraintsAllowed()) { |
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.
Don't forget to add a test~!
Tests added. |
scratch.file("test/BUILD", "toolchain_type(name = 'my_toolchain_type')"); | ||
evalAndExport( | ||
"def impl():", | ||
" return 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.
Nit: AFAIK creating a target with these rules in these tests would fail with a different error anyway because you can't return an int from a rule implementation. return []
instead or just pass
Same for the other new tests
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 was just copying registerDummyUserDefinedFunction, which I have switched back to using and also fixed.
@@ -164,6 +166,8 @@ public boolean flagValue(FlagIdentifier flagIdentifier) { | |||
|
|||
public abstract boolean incompatibleDisallowStructProviderSyntax(); | |||
|
|||
public abstract boolean incompatibleDisallowRuleExecutionPlatformConstraintsAllowed(); |
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 know this is nitty, but the docs above mandate listing variables here and in the other places alphabetically, and I know there's some precedent for enforcing that.
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.
Good point, I'll fix that on the imported version.
Part of #8136 and #8134.
RELNOTES: Adds
incompatible_disallow_rule_execution_platform_constraints_allowed, which
disallows the use of the "execution_platform_constraints_allowed"
attribute when defining new rules.