Skip to content

Commit 35bc58c

Browse files
authored
Add experimental exec command (#4)
1 parent 4f73bd6 commit 35bc58c

File tree

5 files changed

+35
-1
lines changed

5 files changed

+35
-1
lines changed

BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ go_library(
3636
"//command/release:go_default_library",
3737
"//command/targets:go_default_library",
3838
"//command/use:go_default_library",
39+
"//command/exec:go_default_library",
3940
"@com_github_urfave_cli//:go_default_library",
4041
],
4142
)

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ release: install
1010
bazel release \
1111
--owner bzl-io \
1212
--repo bzl \
13-
--tag v0.1.6 \
13+
--tag v0.1.7 \
1414
--notes RELEASE.md \
1515
--commit $(HEAD) \
1616
//:bzl

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,16 @@ Print linting issues in build files (buildifier).
218218
### `$ bazel fmt`
219219

220220
Fix formatting issues in build files (buildifier).
221+
222+
### `$ bazel exec`
223+
224+
Similar to `bazel run` but without running in the sandbox, useful when you don't
225+
want to use `bazel run` and may not be able to easily predict the name of the
226+
output binary.
227+
228+
For example, the following are largely equivalent:
229+
230+
```
231+
$ bazel build //:bzl && ./bazel-bin/linux_amd64_stripped/bzl
232+
$ bazel exec //:bzl
233+
```

app.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/urfave/cli"
99

1010
"github.com/bzl-io/bzl/bazelutil"
11+
"github.com/bzl-io/bzl/command/exec"
1112
fmtcmd "github.com/bzl-io/bzl/command/fmt"
1213
"github.com/bzl-io/bzl/command/install"
1314
"github.com/bzl-io/bzl/command/release"
@@ -54,6 +55,7 @@ func NewApp() *App {
5455

5556
// Add commands
5657
app.Commands = []cli.Command{
58+
*exec.Command,
5759
*install.Command,
5860
*release.Command,
5961
*use.Command,

command/use/use.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ func execute(c *cli.Context) error {
241241
switch rule {
242242
case "http_archive":
243243
printHttpArchive(wsName, owner, repo, tag, sha256, archiveType)
244+
case "go_repository":
245+
printGoRepository(wsName, owner, repo, tag, sha256)
244246
default:
245247
return fmt.Errorf("Unknown --rule=%q", rule)
246248
}
@@ -292,3 +294,19 @@ http_archive(
292294
293295
`, wsName, owner, repo, tag, archiveType, stripPrefix, sha256)
294296
}
297+
298+
func printGoRepository(wsName, owner, repo, tag, sha256 string) {
299+
attr := "tag"
300+
if len(tag) == 40 {
301+
attr = "commit"
302+
}
303+
fmt.Printf(`
304+
go_repository(
305+
name = %q,
306+
importpath = "github.com/%s/%s",
307+
%s = %q,
308+
sha256 = %q,
309+
)
310+
311+
`, wsName, owner, repo, attr, tag, sha256)
312+
}

0 commit comments

Comments
 (0)