Skip to content

Commit

Permalink
Add experimental exec command (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
pcj authored Apr 30, 2019
1 parent 4f73bd6 commit 35bc58c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
2 changes: 2 additions & 0 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -54,6 +55,7 @@ func NewApp() *App {

// Add commands
app.Commands = []cli.Command{
*exec.Command,
*install.Command,
*release.Command,
*use.Command,
Expand Down
18 changes: 18 additions & 0 deletions command/use/use.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}

0 comments on commit 35bc58c

Please sign in to comment.