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

Allow ctx.expand_location to skip mixing in hard-coded attributes #16382

Closed
rickeylev opened this issue Oct 4, 2022 · 5 comments
Closed

Allow ctx.expand_location to skip mixing in hard-coded attributes #16382

rickeylev opened this issue Oct 4, 2022 · 5 comments
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) stale Issues or PRs that are stale (no activity for 30 days) team-Rules-API API for writing rules/aspects: providers, runfiles, actions, artifacts type: feature request

Comments

@rickeylev
Copy link
Contributor

rickeylev commented Oct 4, 2022

Description of the feature request:

Essentially, add an arg to ctx.expand_location to tell it to not mixin hard-coded attribute names. Or otherwise expose args to help control this behavior.

Today, ctx.expand_location will automatically mixin files from various attributes in LocationExpander.java. The set of attributes and the files taken from them is a bit complicated. In short, the attributes deps and tools are always mixed in; I'm not sure if srcs is or not. data isn't always mixed in, but can be, depending on what the native rule does. Depending on the attribute/settings, LocationExpander will expand to the default outputs or just the executable. In comparison, ctx.expand_location will always expand to just the default outputs, plus inherit a subset of the behavior of LocationExpander. It is really quite confusing.

None of this is documented. It's also very confusing/surprising and differs from if native code (as done with args performs expansion).

I think there's a few different options here; some ideas:

  1. "add_extra_stuff=true/false" arg. This would control if LocationExpander mixins in any attributes.
  2. "attrs" arg. This would control which attributes LocationExpander mixes in.
  3. Add args for srcs, deps, tools, and data. This would replace LocationExpander looking up the attributes themselves so the caller can selectively include/exclude them.
  4. Add "executables" arg. This would replace the logic that looks at deps/data/tools and allow the caller to specify which targets should expanded to only their executable, if available.

IMHO, the (4: executables arg) is the most appealing. It allows the caller to control the expansion while keep the API pretty minimal. It doesn't sound unreasonable for a rule to want to exclude/include targets based on some arbitrary condition.

cc @f0rmiga who would probably be interested in this, too.

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

The underlying problem to solve is making ctx.expand_location behave more similarly to native rule expansion and with less surprising behavior.

Which operating system are you running Bazel on?

No response

What is the output of bazel info release?

No response

If bazel info release returns development 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

Have you found anything relevant by searching the web?

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

No response

@f0rmiga
Copy link
Contributor

f0rmiga commented Oct 4, 2022

Thanks. I'd add that this makes moving native rules to Starlark rules more easily without unexpectedly breaking current behaviours.

@f0rmiga
Copy link
Contributor

f0rmiga commented Oct 4, 2022

Also interested in more control over expand_location: bazelbuild/rules_python#846.

@brandjon brandjon added team-Rules-API API for writing rules/aspects: providers, runfiles, actions, artifacts and removed team-Build-Language labels Nov 5, 2022
@comius
Copy link
Contributor

comius commented Jan 16, 2023

From the list of proposals #2 "attrs" arg, looks the most promising.

@comius comius added P3 We're not considering working on this, but happy to review a PR. (No assignee) and removed untriaged labels Jan 16, 2023
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 Mar 22, 2024
Copy link

This issue has been automatically closed due to inactivity. If you're still interested in pursuing this, please post @bazelbuild/triage in a comment here and we'll take a look. Thanks!

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) stale Issues or PRs that are stale (no activity for 30 days) team-Rules-API API for writing rules/aspects: providers, runfiles, actions, artifacts type: feature request
Projects
None yet
Development

No branches or pull requests

5 participants