bazel icon indicating copy to clipboard operation
bazel copied to clipboard

Please document what substitutions are available in rule outputs

Open zrlk opened this issue 11 years ago • 5 comments

In the outputs of a rule, %{name} does something; %{src} also appears to do something, but I can't find this documented anywhere. What's the context in which these are evaluated? Can I write expressions or just variable lookups?

zrlk avatar Apr 13 '15 16:04 zrlk

AFAIK that's only supposed to work in a few attributes and it should be documented in the BE. Which rule and attribute name did you try? Can you tell more about what %{src} seems to do?

laszlocsomor avatar Apr 14 '15 07:04 laszlocsomor

You can basically refer to any attribute, no expressions. However, referring to anything other than %{name} is likely to run into problems, because these templates are evaluated at loading time, at which point we don't have full information about the attributes yet - things like select() and filegroup make this hard.

If you are writing a built-in (native) rule, you can subclass ImplicitOutputsFunction with custom code. If you don't need to be able to refer to the files by name in another rule, then you don't need to use this at all; you can just generate file names as you wish. However, you need to make sure that you don't get name conflicts with other rules in the same package.

It would be good if you could tell us what you're trying to do.

On Tue, Apr 14, 2015 at 9:37 AM, László Csomor [email protected] wrote:

AFAIK that's only supposed to work in a few attributes and it should be documented in the BE. Which rule and attribute name did you try? Can you tell more about what %{src} seems to do?

— Reply to this email directly or view it on GitHub https://github.com/google/bazel/issues/115#issuecomment-92677513.

ulfbot avatar Apr 14 '15 07:04 ulfbot

this commit expanded what %{attr} expansions are available: https://github.com/google/bazel/commit/6c8b0b6785d9907be81b300e1bde45f086d67b39

Let's use this issue for the missing documentation.

@zrlk - can you open a separate issue if there is functionality you are missing?

hanwen avatar Apr 15 '15 08:04 hanwen

Laurent, can you make the rule() documentation point to the relevant part of the BE, and/or document any other limitations on naming outputs?

hanwen avatar Apr 15 '15 08:04 hanwen

Won't fix: this feature is now deprecated (https://github.com/bazelbuild/bazel/issues/6241).

laurentlb avatar Oct 24 '18 17:10 laurentlb