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 way to get the alias label in starlark #11044

Open
Jamie5 opened this issue Mar 30, 2020 · 7 comments · May be fixed by #18100
Open

Add a way to get the alias label in starlark #11044

Jamie5 opened this issue Mar 30, 2020 · 7 comments · May be fixed by #18100
Labels
not stale Issues or PRs that are inactive but not considered stale P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Rules-Server Issues for serverside rules included with Bazel type: feature request

Comments

@Jamie5
Copy link

Jamie5 commented Mar 30, 2020

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

@laurentlb laurentlb added team-Rules-Server Issues for serverside rules included with Bazel and removed team-Starlark labels Apr 27, 2020
@lberki lberki added P3 We're not considering working on this, but happy to review a PR. (No assignee) and removed untriaged labels Nov 18, 2020
@lberki
Copy link
Contributor

lberki commented Nov 18, 2020

I originally thought this is specifically harmful, but then realized that this functionality is already available to Java rules (AliasProvider.getDependencyLabel()) and it's used somewhat widely so it's probably okay.

@github-actions
Copy link

Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 2+ years. It will be closed in the next 14 days unless any other activity occurs or one of the following labels is added: "not stale", "awaiting-bazeler". Please reach out to the triage team (@bazelbuild/triage) if you think this issue is still relevant or you are interested in getting the issue resolved.

@github-actions github-actions bot added the stale Issues or PRs that are stale (no activity for 30 days) label Apr 12, 2023
@brentleyjones
Copy link
Contributor

Not stale. I would also love to have this for rules_xcodeproj.

@sgowroji sgowroji removed the stale Issues or PRs that are stale (no activity for 30 days) label Apr 12, 2023
@fmeum
Copy link
Collaborator

fmeum commented Apr 14, 2023

@lberki I would need this for #10309 (comment). Do you think this is safe enough that I could go ahead and implement it as a new struct field on ConfiguredTarget?

Edit: While looking into this for a bit, it seemed simple enough that I went ahead and turned it into a PR: #18100

@fmeum fmeum linked a pull request Apr 14, 2023 that will close this issue
Copy link

Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 1+ years. It will be closed in the next 90 days unless any other activity occurs. If you think this issue is still relevant and should stay open, please post any comment here and the issue will no longer be marked as stale.

@github-actions github-actions bot added the stale Issues or PRs that are stale (no activity for 30 days) label Jun 18, 2024
@fmeum
Copy link
Collaborator

fmeum commented Jun 18, 2024

@bazelbuild/triage not stale

@iancha1992 iancha1992 added not stale Issues or PRs that are inactive but not considered stale and removed stale Issues or PRs that are stale (no activity for 30 days) labels Jun 18, 2024
@smamessier
Copy link

Found a fun way to hack this with a macro btw:

def your_macro(name, deps):
    deps_map = {dep: str(dep) for dep in deps}
    your_rule(
        name = name,
        deps = deps_map,
    )
your_rule = rule(
    implementation = _your_rule,
    attrs = {
        "deps": attr.label_keyed_string_dict(mandatory=True),
    },
)

Then you have the original alias, and target maping available: for dep, label in ctx.attr.deps.items():

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
not stale Issues or PRs that are inactive but not considered stale P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Rules-Server Issues for serverside rules included with Bazel type: feature request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants