Search code examples
graphbuildbazel

Workaround for output=graph with bazel cquery


I'm trying to obtain a dependency graph (either as an image or in text-form) from a bazel cquery. According to the documentation, the option --output=graph is currently only supported by bazel query, but not by cquery. Unfortunately, in our project it's not possible to use query since it fetches some external dependencies with restricted access. Only using a config (with cquery) prevents fetching these restricted dependencies.

Is there a work-around to somehow get a graph-like structure from cquery? The default output is just a flattened list which seems to contain no information on the inter-dependencies between the targets.

If the inter-dependencies can somehow be printed, I guess it would be quite easy to reconstruct an image from it.


Solution

  • The following works: Using query instead of cquery and appending the flag --keep_going to ignore errors caused by external dependencies that cannot be fetched by everybody. Then --output=graph can be used.

    Note: The result might be different from a configured cquery, but for our purposes, it doesn't matter much.