facebook / facebook/buck2

It should be possible to consume multiple `default_outputs` in an `attrs.list(attrs.source())`

Open
#561 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
4.4k
Forks
394
PR merge metrics
No merged PRs in 30d

Description

I have a genrule that outputs multiple files by returning a `DefaultInfo()` whose `default_outputs` is set to a list with more than 1 item, it would be *really* nice if I could have these consumed by another rule as follows:

```
foo(
srcs = [":other_rule"] # srcs is an `attrs.list(attrs.source())`
```

If you look at [this documentation](https://buck2.build/docs/api/build/globals/#defaultinfo), it even explicitly states that it should work, because of this line:

```
genrule(name = "gen_stuff", ...., default_outs = ["foo.cpp"])

# ":gen_stuff" pulls the default_outputs for //subdir:gen_stuff
foo_binary_wrapper(name = "foo", srcs = glob(["*.cpp"]) + [":gen_stuff"])
```

I understand that it might be difficult to get the type checking to pass here, since technically the target label `:gen_stuff` is one thing, and expanding it would really expand to a list, at which point you have a list of lists. But I think if you introduced a global function called `default_outputs`, this would be very elegant. Then you'd write my original example as:

```
foo(
srcs = default_outputs(":other_rule")
```

Just like glob returns a list, this too could return a list.

What are the chances of seeing something like this implemented?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.