Add a way to get the alias label in starlark
- Dominant language
- Java
- Stars
- 25.8k
- Forks
- 4.6k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 72
Description
### Description of the problem / feature request:
Within starlark, it would be useful to be able to access the original label (i.e. the alias label itself, and not the actual alias) of an alias label.
For example, if a rule was `foo_rule(deps = ["/some/alias"])`, in the rule impl we would like to do something like `for dep in ctx.attr.deps: if hasattr(dep, 'alias_original_label'): do_something(deps.alias_original_label)` and this would, for the above dep, do `do_something("/some/alias")`.
To be specific, the desire would be to expose `AliasConfiguredTarget.label` to starlark.
I don't think this would be too complex to implement and could try to do it, as long as this aligns with the principles of bazel.
### Feature requests: what underlying problem are you trying to solve with this feature?
We are trying to do some analysis during the build of the dependencies of a given rule, to make sure it conforms with some principles that we want, and would like to handle aliases specially for certain reasons. Having this ability would help us do so. It is useful for us that this is in starlark itself, rather than relying on `bazel query` or similar.
### Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
Not a bug
### What operating system are you running Bazel on?
Linux
### What's the output of `bazel info release`?
`release 1.0.0` (but docs don't show this ability still)
### 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 master ; git rev-parse HEAD` ?
N/A
### Have you found anything relevant by searching the web?
No
### Any other information, logs, or outputs that you want to share?
No
Contributor guide
Research direction
Start by locating AliasConfiguredTarget.label and the Starlark-facing configured-target entry points, then inspect existing alias handling and related tests. The work is done when the original alias label, such as "/some/alias", is accessible from a Starlark rule implementation and coverage verifies the example behavior.
Written by the indexing model from the issue text.
Assessment
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100