Skip to content

Remove Label wrappers for target string literals #1728

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

Merged
merged 1 commit into from
Apr 28, 2025

Conversation

mbland
Copy link
Contributor

@mbland mbland commented Apr 27, 2025

Description

Removes all the Label wrappers added in #1696 that aren't strictly necessary.

Removed instances:

$ git show -p | grep '^- .*Label(' | wc -l
    88

Remaining instances:

$ git ls-files | xargs grep '[^A-Za-z0-9]Label(' | wc -l
    31

Motivation

Inspired by research I did while writing a blog post reflecting upon the motivations behind #1696.

Bazel evaluates target string literals in the context of the repository that appears to contain the assignment of the literal to a Label attribute. Label wrappers are necessary for target string literals within macros, passed to external functions, and included in files generated by a repository rule. This ensures that the targets refer to the originating repository by preventing Bazel from interpreting them within the context of the repository using them.

Keeping the Label wrappers doesn't hurt, but leaving only the ones that are required helps those instances stand out.

Removes all the `Label` wrappers added in bazel-contrib#1696 that aren't strictly
necessary.

Removed instances:

```sh
$ git show -p | grep '^- .*Label(' | wc -l
    88
```

Remaining instances:

```sh
$ git ls-files | xargs grep '[^A-Za-z0-9]Label(' | wc -l
    31
```

Inspired by research I did while writing a blog post reflecting upon the
motivations behind bazel-contrib#1696.

Bazel evaluates target string literals in the context of the repository
that appears to contain the assignment of the literal to a `Label`
attribute. `Label` wrappers are necessary for target string literals
within macros, passed to external functions, and included in files
generated by a repository rule. This ensures that the targets refer to
the originating repository by preventing Bazel from interpreting them
within the context of the repository using them.

Keeping the `Label` wrappers doesn't hurt, but leaving only the ones
that are required helps those instances stand out.
@mbland mbland requested review from liucijus and simuons as code owners April 27, 2025 12:27
Copy link
Collaborator

@simuons simuons left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @mbland

@simuons simuons merged commit 1aced65 into bazel-contrib:master Apr 28, 2025
2 checks passed
@mbland mbland deleted the remove-label-wrappers branch April 28, 2025 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants