How to query http_archive/git_repository rules?

931 views
Skip to first unread message

ash...@gmail.com

unread,
Nov 25, 2017, 6:25:01 AM11/25/17
to bazel-discuss
Hi all,

It has became really difficult to manage all the bazel external dependencies. One option I have now is to write a small script to check all the rules in the WORKSPACE to find outdated external dependencies. But this won't work for the dependencies introduced by other rules, eg. rules_go.

Is there a way to find such dependencies programmatically?

Also as the rules_go requires all the transitive external dependencies to be declared in the workspace. In case some of them are no longer needed after updating, is there a way to discover those unneeded external dependencies in WORKSPACE file?

Thanks!

Jay Conrod

unread,
Nov 27, 2017, 11:10:17 AM11/27/17
to ash...@gmail.com, bazel-discuss
As far as I know, there is no way to list repository rules on the command line.

You could call native.existing_rules() from a macro called at the end of WORKSPACE.

If everything listed textually in WORKSPACE, it may be sufficient to parse it with github.com/bazelbuild/buildtools/build and read the syntax tree. This won't catch anything declared inside a macro though.


--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/0dba3092-7f22-463a-81ec-328b82876921%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

rodr...@google.com

unread,
Nov 27, 2017, 12:12:29 PM11/27/17
to bazel-discuss
This could be very useful, especially once nested workspaces arrive. Since you can do:

> bazel query '"@com_google_protobuf//:*"' --output package
@com_google_protobuf//

Maybe `bazel query` should support repo wildcards:

> bazel query '"@*//:*"' --output package
@com_google_protobuf//
<etc for all other repos>

Currently you get:

ERROR: invalid repository name '@*': workspace names may contain only A-Z, a-z, 0-9, '-', '_' and '.'

On Monday, November 27, 2017 at 5:10:17 PM UTC+1, Jay Conrod wrote:
> As far as I know, there is no way to list repository rules on the command line.
>
>
> You could call native.existing_rules() from a macro called at the end of WORKSPACE.
>
>
> If everything listed textually in WORKSPACE, it may be sufficient to parse it with github.com/bazelbuild/buildtools/build and read the syntax tree. This won't catch anything declared inside a macro though.
>
>
> On Sat, Nov 25, 2017 at 6:25 AM, <ash...@gmail.com> wrote:
> Hi all,
>
>
>
> It has became really difficult to manage all the bazel external dependencies.  One option I have now is to write a small script to check all the rules in the WORKSPACE to find outdated external dependencies.  But this won't work for the dependencies introduced by other rules, eg. rules_go.
>
>
>
> Is there a way to find such dependencies programmatically?
>
>
>
> Also as the rules_go requires all the transitive external dependencies to be declared in the workspace.  In case some of them are no longer needed after updating, is there a way to discover those unneeded external dependencies in WORKSPACE file?
>
>
>
> Thanks!
>
>
>
> --
>
> You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
>
> To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.

Brian Silverman

unread,
Nov 27, 2017, 4:28:31 PM11/27/17
to rodr...@google.com, bazel-discuss
I opened #1034 a while ago requesting that feature. It would indeed be handy.

Xiaoyi Shi

unread,
Nov 27, 2017, 10:07:21 PM11/27/17
to bazel-discuss
SGTM. native.existing_rules() works perfectly.

Thanks!


On Tuesday, November 28, 2017 at 12:10:17 AM UTC+8, Jay Conrod wrote:
As far as I know, there is no way to list repository rules on the command line.

You could call native.existing_rules() from a macro called at the end of WORKSPACE.

If everything listed textually in WORKSPACE, it may be sufficient to parse it with github.com/bazelbuild/buildtools/build and read the syntax tree. This won't catch anything declared inside a macro though.
On Sat, Nov 25, 2017 at 6:25 AM, <ash...@gmail.com> wrote:
Hi all,

It has became really difficult to manage all the bazel external dependencies.  One option I have now is to write a small script to check all the rules in the WORKSPACE to find outdated external dependencies.  But this won't work for the dependencies introduced by other rules, eg. rules_go.

Is there a way to find such dependencies programmatically?

Also as the rules_go requires all the transitive external dependencies to be declared in the workspace.  In case some of them are no longer needed after updating, is there a way to discover those unneeded external dependencies in WORKSPACE file?

Thanks!

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages