Search code examples
gobazel

Quick way to add new Bazel github external repository if you're lazy?


I'm using Bazel and gazelle to manage my Go project's BUILD.bazel files.

I'd like to be consistent across languages and avoid Go's specific vendoring tool.

I disabled vendoring for gazelle. It generates the BUILD entries wonderfully for those repositories, but I'm stuck with writing the WORKSPACE incantations for git_repository or http_archive myself. This of course can get tedious if a project I'm using has a lot of external dependencies.

Is there a more convenient way to do it? Could gazelle support updating the WORKSPACE file?

Thanks.


Solution

  • Answering my own question: it looks like the Bazel team wants do add support for this to Gazelle but until that's done we could use the wtool:

    $ go get -u github.com/bazelbuild/rules_go/go/tools/wtool
    $ github.com/gordonklaus/portaudio
    
    This will update the WORKSPACE file accordingly. The command doesn't even have to be run from the repository root - which is nice.
    

    Here's my the diff for my WORKSPACE after running the command above:

    $ git diff WORKSPACE 
    diff --git a/WORKSPACE b/WORKSPACE
    index 3b15779..c170b60 100644
    --- a/WORKSPACE
    +++ b/WORKSPACE
    @@ -50,3 +50,8 @@ go_repository(
         importpath = "google.golang.org/api",
     )
    
    +go_repository(
    +    name = "com_github_gordonklaus_portaudio",
    +    commit = "e66c30a9c4ca11f93538cf8c004831bfb76f3838",
    +    importpath = "github.com/gordonklaus/portaudio",
    +)