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

Validate that rules without toolchain context cannot create actions #20505

Open
katre opened this issue Dec 12, 2023 · 1 comment
Open

Validate that rules without toolchain context cannot create actions #20505

katre opened this issue Dec 12, 2023 · 1 comment
Labels
P2 We'll consider working on this in future. (Assignee optional) team-Configurability platforms, toolchains, cquery, select(), config transitions team-Rules-API API for writing rules/aspects: providers, runfiles, actions, artifacts type: feature request

Comments

@katre
Copy link
Member

katre commented Dec 12, 2023

In theory, RuleContext.getToolchainContext will only return null if the rule is not generating actions (as set in RuleClass.Builder.useToolchainResolution(ToolchainResolutionMode.DISABLED)). However, we aren't currently validating this, and it's possible that legacy rules are violating this.

We should add explicit validation around this to ensure that any rule which generates actions has a toolchain context (which includes both the target and exec platforms for that configured target).

@katre katre added type: feature request P2 We'll consider working on this in future. (Assignee optional) team-Configurability platforms, toolchains, cquery, select(), config transitions team-Rules-API API for writing rules/aspects: providers, runfiles, actions, artifacts labels Dec 12, 2023
@katre
Copy link
Member Author

katre commented Dec 14, 2023

Okay, did some testing on #20525 (downstream tests) and the google-internal version, and the only issue is that ~every rule creates file write actions, even if that rule doesn't use toolchains (and thus has no execution platform).

Really, file writes should have the host platform as the exec platform anyway, so this is a) ignorable, and b) trivially fixable.

However, there's no good way to add ongoing monitoring short of crashing the Bazel server, because RuleContext.registerAction is incredibly deeply used: after adding throws RuleErrorException to registerAction I had to update over 140 other files (to declare that it could be thrown, or to handle it), and I was still getting compilation errors when I gave up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 We'll consider working on this in future. (Assignee optional) team-Configurability platforms, toolchains, cquery, select(), config transitions team-Rules-API API for writing rules/aspects: providers, runfiles, actions, artifacts type: feature request
Projects
None yet
Development

No branches or pull requests

1 participant