diff --git a/BUILD.bazel b/BUILD.bazel index a75ff54..d328781 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -36,6 +36,7 @@ go_library( "//command/release:go_default_library", "//command/targets:go_default_library", "//command/use:go_default_library", + "//command/exec:go_default_library", "@com_github_urfave_cli//:go_default_library", ], ) diff --git a/Makefile b/Makefile index 31d7d45..13a832a 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ release: install bazel release \ --owner bzl-io \ --repo bzl \ - --tag v0.1.6 \ + --tag v0.1.7 \ --notes RELEASE.md \ --commit $(HEAD) \ //:bzl diff --git a/README.md b/README.md index 722633a..f52d7d0 100644 --- a/README.md +++ b/README.md @@ -218,3 +218,16 @@ Print linting issues in build files (buildifier). ### `$ bazel fmt` Fix formatting issues in build files (buildifier). + +### `$ bazel exec` + +Similar to `bazel run` but without running in the sandbox, useful when you don't +want to use `bazel run` and may not be able to easily predict the name of the +output binary. + +For example, the following are largely equivalent: + +``` +$ bazel build //:bzl && ./bazel-bin/linux_amd64_stripped/bzl +$ bazel exec //:bzl +``` diff --git a/app.go b/app.go index 4821e7d..cac1906 100644 --- a/app.go +++ b/app.go @@ -8,6 +8,7 @@ import ( "github.com/urfave/cli" "github.com/bzl-io/bzl/bazelutil" + "github.com/bzl-io/bzl/command/exec" fmtcmd "github.com/bzl-io/bzl/command/fmt" "github.com/bzl-io/bzl/command/install" "github.com/bzl-io/bzl/command/release" @@ -54,6 +55,7 @@ func NewApp() *App { // Add commands app.Commands = []cli.Command{ + *exec.Command, *install.Command, *release.Command, *use.Command, diff --git a/command/use/use.go b/command/use/use.go index cb3606b..9e95687 100644 --- a/command/use/use.go +++ b/command/use/use.go @@ -241,6 +241,8 @@ func execute(c *cli.Context) error { switch rule { case "http_archive": printHttpArchive(wsName, owner, repo, tag, sha256, archiveType) + case "go_repository": + printGoRepository(wsName, owner, repo, tag, sha256) default: return fmt.Errorf("Unknown --rule=%q", rule) } @@ -292,3 +294,19 @@ http_archive( `, wsName, owner, repo, tag, archiveType, stripPrefix, sha256) } + +func printGoRepository(wsName, owner, repo, tag, sha256 string) { + attr := "tag" + if len(tag) == 40 { + attr = "commit" + } + fmt.Printf(` +go_repository( + name = %q, + importpath = "github.com/%s/%s", + %s = %q, + sha256 = %q, +) + +`, wsName, owner, repo, attr, tag, sha256) +}