-
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
repository_rule no longer supports making attrs inside a function #19459
Comments
The use-case here is that we use a repository rule to get a build number for stamping from an environment variable. We want changes to the environment variable to invalidate the repository rule (so that the new value will be used). And we want different instantiations of the repository rule (which may in fact be in different repositories) to be able to specify which environment variable they want to use as the build number. So one repo may say: make_my_stamping_context(
name = "stamp_context",
env_var_name = "BUILD_NUMBER",
) And another repo may say: make_my_stamping_context(
name = "stamp_context",
env_var_name = "OTHER_BUILD_NUMBER",
) Because the If there was a way for a repository rule impl to return back "Here are env vars I want to rerun on", like you can specifty files that should trigger reruns, I wouldn't need this functionality any more. |
Hmm. This could be worth pursuing. There's nothing technically preventing us from such an API, as far as I'm aware. |
Can we file another issue to track this feature request? |
@meteorcloudy I opened #19511 :) Thanks! |
Thanks! Do we close this one or keep it as a P3? |
IMO close. In Bzlmod it's expressly forbidden to instantiate a repo rule that hasn't been exported. Per #10441 this is a bug in the WORKSPACE repo rule code. |
Description of the bug:
In Bazel 6, we could write a repository rule which read an env var, and was re-run when that env var changed, but where the particular env var could be specified by the instantiator of the repository rule, like:
In Bazel 7, this pattern no longer works because of this error:
It looks like the commit which introduced this restriction was attempting to avoid pointless calls to
attr.string()
, but accidentally catches "creating a repository_rule inside a function".It looks like we can extract the
attrs
value to a top-level variable, assuming it itself isn't parameterised in the containing function, and things start working again, but this seems unnecessarily fiddly/restrictive?Which category does this issue belong to?
External Dependency, Rules API
What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
/WORKSPACE
file:/rr.bzl
file:Run:
bazel query @foo//...
Which operating system are you running Bazel on?
macOS
What is the output of
bazel info release
?release 7.0.0-pre.20230823.4
If
bazel info release
returnsdevelopment version
or(@non-git)
, tell us how you built Bazel.No response
What's the output of
git remote get-url origin; git rev-parse master; git rev-parse HEAD
?No response
Is this a regression? If yes, please try to identify the Bazel commit where the bug was introduced.
835512a /cc @brandj
Have you found anything relevant by searching the web?
No response
Any other information, logs, or outputs that you want to share?
No response
The text was updated successfully, but these errors were encountered: