facebook / buck2

Build system, successor to Buck
https://buck2.build/
Apache License 2.0
3.53k stars 215 forks source link

Giving an alias for multiple target patterns #513

Open thoughtpolice opened 10 months ago

thoughtpolice commented 10 months ago

I have a bunch of top level cells called root//, third-party//, and cellar//, and I'd like to build everything across all of them when doing things like CI integration.

Currently, I have to do that with a very verbose command:

buck2 build root//... third-party//... cellar//...

There is an [alias] stanza in .buckconfig which lets you alias targets, but not target patterns. This does not work:

[alias]
world = root//... third-party//... cellar//...
$ buck2 build world
File changed: root//.buckconfig
Parsing target pattern `world`

Caused by:
    0: Error resolving alias `world`
    1: [alias] section produced a dangling chain: `world -> root//... third-party//... cellar//...`

Workarounds

I think you could use @ syntax on the command line to include a file, so something like buck2 build @world, but that requires an actual file existing which is pretty messy, and I don't see why [alias] should not work.

thoughtpolice commented 10 months ago

Having such a target would also be useful for bxl scripts where I want to hardcode a name referring to every target pattern, without needing to repeat all the cell names everywhere constantly. The @ workaround would not work for this case.

zjturner commented 10 months ago

Couldn’t you do this with a dummy target that has a dep on each of your patterns?

zjturner commented 10 months ago

I don’t remember if deps attribute allows expressions, but perhaps it allows query functions

JakobDegen commented 9 months ago

Couldn’t you do this with a dummy target that has a dep on each of your patterns?

That's not really the same thing, those targets will end up in the wrong configurations.

I think the "I want to build the world" problem is definitely a legit ask. You could imagine supporting syntax like ...//... for it. I don't know if we want to extend alias to support this though, I think I'd want to see some use examples of use cases outside of this particular one

thoughtpolice commented 9 months ago

You could imagine supporting syntax like ...//... for it.

I'd be perfectly happy with that, in this case; the syntax is perhaps a little less nice than buck2 build world (imo a little more intuitive), but I'm perfectly happy to compromise on that.

Really, this is the only thing I can think of for this, off the top of my head. I just asked for the generalized version since I figured it was a pretty natural extension of the existing feature, is all.

JakobDegen commented 9 months ago

@stepancheg had suggested that instead we should treat cells as being more like aliases, and so root//... should actually work to build the whole world. If that's the direction that we want to go then having support for the ...// thing would be a little bit weird, so I'm going to ask around internally after the holidays what kind of timeline we'd be looking at for getting cross-cell references working, and then we can go from there