github.com/yrj2011/jx-test-infra@v0.0.0-20190529031832-7a2065ee98eb/autogo/README.md (about) 1 # Automatically generate bazel rules for go packages 2 3 This uses [gazelle] to generate and update [bazel] rules for golang packages without 4 adding new `BUILD.bazel` files to the repository. 5 6 ## Usage 7 8 See options for [installing bazel]. 9 10 ``` 11 # Install bazel 12 brew install bazel # See https://docs.bazel.build/versions/master/install.html 13 14 # Create a bazel WORKSPACE file in your repo root 15 echo >WORKSPACE <<END 16 git_repository( 17 name = "fejta_autogo", 18 remote = "https://github.com/fejta/test-infra.git", 19 commit = "f478925cc6179f1abf6245698aaf514d873cfcc9", 20 ) 21 load("@fejta_autogo//autogo:deps.bzl", "autogo_dependencies") 22 autogo_dependencies() 23 load("@fejta_autogo//autogo:def.bzl", "autogo_generate") 24 autogo_generate( 25 name = "autogo", 26 prefix = "github.com/golang/dep", # change to your go get path 27 ) 28 END 29 30 # Create an empty BUILD.bazel file (needed by bazel) 31 touch BUILD.bazel 32 33 # Use bazel with an @autogo prefix to access the auto-generated repo 34 bazel query @autogo//... 35 bazel run @autogo//path/to/my/cmd/binary 36 ``` 37 38 39 ## Demo 40 41 Add bazel support to [dep]: 42 43 ``` 44 git clone https://github.com/fejta/dep # golang/dep + a WORKSPACE file 45 cd dep && ls WORKSPACE 46 bazel run @autogo//cmd/dep -- help 47 ``` 48 49 See the [concrete] `WORKSPACE` that enables this. 50 51 [bazel]: https://bazel.build 52 [concrete]: https://github.com/fejta/dep/blob/master/WORKSPACE 53 [dep]: http://github.com/golang/dep 54 [gazelle]: https://github.com/bazelbuild/bazel-gazelle 55 [installing bazel]: https://docs.bazel.build/versions/master/install.html