Find all targets

616 views
Skip to first unread message

ar...@unity3d.com

unread,
Jan 15, 2016, 3:08:39 AM1/15/16
to Buck
I'm really happy with Buck currently and now I'm trying to enable CI for my monorepo. Can I query all the available targets for building somehow? Idea that my CI would fetch all the possible targets from the repo and then build all of them on each commit (shouldn't be a problem, because most of the staff would come from Buck cache)

Another reason for that - I would like to create a dependency graph for all of my projects in the repo, it would useful to have.

I guess I should dig in `buck query`, isn't it?

And a bit offtopic - in general is this a right approach, to have CI working like that? I'm really new to the monorepo and build systems like Buck

Thank you

Jakub Zika

unread,
Jan 15, 2016, 4:58:06 AM1/15/16
to ar...@unity3d.com, Buck
> I guess I should dig in `buck query`, isn't it?
Yes, `buck query` will help you with most of those issues.

> Can I query all the available targets for building somehow?
You can run `buck query //...` to get all the targets in the repo, or for example `buck query 'kind(java_binary, //...)’` to get all java_binary targets.

> Another reason for that - I would like to create a dependency graph for all of my projects in the repo, it would useful to have.
Run `buck query --dot ‘deps(//some:target)’` or `buck query --dot ‘deps(//...)’` to generate a dependency graph in the dot (text) format. Then (if you have graphviz installed) you can add `| dot -Tpng >deps.png` at the end of the command to generate a visual representation of the graph.

Depending on how you want to use the data returned by Buck, the --json option might be useful as well.
--
You received this message because you are subscribed to the Google Groups "Buck" group.
To unsubscribe from this group and stop receiving emails from it, send an email to buck-build+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

ar...@unity3d.com

unread,
Jan 15, 2016, 5:06:47 AM1/15/16
to Buck, ar...@unity3d.com, jaku...@fb.com
Cool, thanks, I ended up with those two commands:

buck query '//...' | xargs buck build to build all the projects
buck query 'deps(//...)' --dot | dot -T png > deps.png to create graph which represents whole repo 

Ben Hamilton

unread,
Jan 15, 2016, 1:37:30 PM1/15/16
to ar...@unity3d.com, Buck, jaku...@fb.com
If you're building a CI system, you may also be interested in knowing which target(s) changed as the result of a commit to source control, so you don't build or test too many things.

Buck supports this use-case via the command:

buck targets --show-target-hash [target1] [...]

You can run this twice (once before applying the commit, then again afterwards) to get an identifier for each of the target(s) which is guaranteed to change if any of the inputs or dependencies for the target changes.

This is documented here:


By default, this command hashes the contents of all the files involved in the targets. This might prove to be expensive for very large targets, so in that case you might want to specify the paths which are modified:

buck targets --show-target-hash --target-hash-file-mode=PATHS_ONLY --target-hash-modified-paths="/path/to/file1 /path/to/file2 ..." [target1] [...]

Ben

ar...@unity3d.com

unread,
Jan 15, 2016, 2:05:23 PM1/15/16
to Buck, ar...@unity3d.com, jaku...@fb.com
Thank you very much Ben.

For skipping tests it's really great to have it, but as far as I understand - build shouldn't take much time as Buck is smart enough to skip not changed modules, isn't it? It should take it from cache, so it doesn't make any difference if I query and build all of modules each time?

Thanks again

Ben Hamilton

unread,
Jan 15, 2016, 3:57:38 PM1/15/16
to ar...@unity3d.com, Buck, jaku...@fb.com
It's mainly useful for tests, as you might guess, as well as for distributed build systems which need to run on different machines each time without a shared cache.

Artem Yarulin

unread,
Jan 15, 2016, 3:58:45 PM1/15/16
to Ben Hamilton, Buck, jaku...@fb.com
Oh yeah, didn’t realised about the latest case. Thanks again!
Reply all
Reply to author
Forward
0 new messages