Allow ctx.expand_location to skip mixing in hard-coded attributes #16382
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
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:
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
returnsdevelopment 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
The text was updated successfully, but these errors were encountered: