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

Add a repository_ctx field to accommodate default repo target names #24467

Open
mbland opened this issue Nov 22, 2024 · 0 comments
Open

Add a repository_ctx field to accommodate default repo target names #24467

mbland opened this issue Nov 22, 2024 · 0 comments
Assignees
Labels
team-Rules-API API for writing rules/aspects: providers, runfiles, actions, artifacts type: feature request untriaged

Comments

@mbland
Copy link

mbland commented Nov 22, 2024

Description of the feature request:

A repository_ctx parameter holding the original, user-provided name value, facilitating the creation of default repo target names without workarounds

Which category does this issue belong to?

Rules API

What underlying problem are you trying to solve with this feature?

Label supports default target names based on repo names. For example, @repo expands to @repo//:repo.

Under Bzlmod, repository_ctx.name is now the canonical repo name, invalidating previous repository_rule implementations that used this value to construct a default target name under WORKSPACE. One can work around this issue by adding a separate attr to duplicate the name parameter of a given repository rule, but this degrades the interface somewhat and is potentially error prone.

I've implemented a pattern in bazelbuild/rules_scala#1650 to wrap a repository_rule in a macro to handle this duplication on behalf of the user, keeping the ergonomics of the original rule, but with trade-offs. This came after my first workaround, parsing the original name from repository_ctx.name, from bazelbuild/rules_scala#1621 and the withdrawn bazelbuild/bazel-skylib#548. Both flavors of workaround, however, reflect extra effort to grab information already passed as the name parameter of a repository_rule.

As originally discussed with @Wyverald and @fmeum in a #bzlmod channel thread in the Bazel Slack Workspace, a dedicated repository_ctx field would eliminate the need for such workarounds in the future. I'd imagine it could be backported to Bazel 7, and even to Bazel 6, to remove friction from Bzlmod migrations.

Which operating system are you running Bazel on?

N/A

What is the output of bazel info release?

N/A

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

N/A

What's the output of git remote get-url origin; git rev-parse HEAD ?

N/A

Have you found anything relevant by searching the web?

N/A

Any other information, logs, or outputs that you want to share?

N/A

@github-actions github-actions bot added the team-Rules-API API for writing rules/aspects: providers, runfiles, actions, artifacts label Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-Rules-API API for writing rules/aspects: providers, runfiles, actions, artifacts type: feature request untriaged
Projects
None yet
Development

No branches or pull requests

4 participants