Search code examples
bazel

Create dependency list from WORKSPACE in Bazel?


I'd like to maintain a list of dependencies and their versions per Bazel project.

How do I query for WORKSPACE rules the BUILD rules depend on? How can I access the contained attributes?

EDIT I'd like to query based on a BUILD rule. So if I have multiple rules, I only want the WORKSPACE info based on the one I asked for.


Solution

  • The way I did this was to keep the workspace deps in a separate format, iterate them, and then build a markdown document.

    See https://github.com/pubref/rules_protobuf/blob/master/DEPENDENCIES.md

    https://github.com/pubref/rules_protobuf/blob/master/protobuf/internal/proto_dependencies.bzl

    There's probably a way to do it via a genquery and native.existing_rules, but I have not tried that.

    HTH, Paul