Skip to content

Commit

Permalink
Add use subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
pcj committed Apr 18, 2019
1 parent cec1237 commit c941338
Show file tree
Hide file tree
Showing 9 changed files with 331 additions and 194 deletions.
1 change: 1 addition & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ go_library(
"//command/install:go_default_library",
"//command/release:go_default_library",
"//command/targets:go_default_library",
"//command/use:go_default_library",
"@com_github_urfave_cli//:go_default_library",
],
)
Expand Down
79 changes: 65 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@
versions of bazel. You can install different versions and easily switch between
them.

## Install bzl

`bzl` ships as a single executable go binary. Download the file directly from
the [Github Releases Page](https://github.com/bzl-io/bzl/releases) for the
precompiled platform of your choice (or build from source).
`bzl` is a drop-in replacement for `bazel`. Any commands not recognized by `bzl`
are passed through as-is to `bazel`.

## How is `bzl` pronounced?

Expand All @@ -19,32 +16,86 @@ it's function (a wrapper around bazel).
> add functions to a watch without complicating the movement, and so the
> external watch bezel was born.
## Install bzl

`bzl` ships as a single executable go binary. Download the file directly from
the [Github Releases Page](https://github.com/bzl-io/bzl/releases) for the
precompiled platform of your choice (or build from source).

Once downloaded `chmod +x` and `mv bzl ~/bin/bazel` and type `bazel install` to
list the available versions.

Specify the version of bazel to use either via an environment variable or
command line flag (example: `BAZEL_VERSION=0.24.1`; `--bazel=0.19.2`).

## `bzl` commands

### `$ bzl --help`
### `$ bazel --help`

Show help.

### `$ bzl install`
### `$ bazel install`

List or install available bazel installs.

Examples:

| Command | Description |
| --- | --- |
| `$ bzl install` | List all available releases |
| `$ bzl install 0.8.0` | Install bazel release 0.8.0 |
| `$ bzl install --list 0.8.0` | Show the assets bundled in install 0.8.0 |
| `$ bazel install` | List all available releases |
| `$ bazel install 0.8.0` | Install bazel release 0.8.0 |
| `$ bazel install --list 0.8.0` | Show the assets bundled in install 0.8.0 |

### `$ bazel use`

Print a repository rule for a github bazel repository.

### `$ bzl target`
Without a release tag, list available releases:

```
$ bazel use grpc-ecosystem/grpc-gateway
v1.8.5 Fri Mar 15 2019
v1.8.4 Wed Mar 13 2019
v1.8.3 Mon Mar 11 2019
v1.8.2 Thu Mar 07 2019
v1.8.1 Sat Mar 02 2019
```

With a release tag, output an `http_archive` rule:

```
$ bazel use grpc-ecosystem/grpc-gateway v1.8.5
http_archive(
name = "grpc_ecosystem_grpc_gateway",
urls = ["https://github.com/grpc-ecosystem/grpc-gateway/archive/v1.8.5.tar.gz"],
strip_prefix = "grpc-gateway-1.8.5",
sha256 = "9d7cf2ce799002024f215d3ff2df4882c347563478093a4671b13154ba37982c",
)
```

The `bazelbuild` organization is assumed if you leave out the organization name:

```
$ bazel use rules_go
0.18.3 Fri Apr 12 2019
0.17.4 Fri Apr 12 2019
0.16.10 Fri Apr 12 2019
0.18.2 Sat Apr 06 2019
...
```

### `$ bazel target`

Pretty-print available targets in the current workspace.

Example:

```
$ bzl targets
$ bazel targets
go_library rule //proto/bes:go_default_library
go_library rule //:go_default_library
go_library rule //command:go_default_library
Expand All @@ -67,7 +118,7 @@ go_library rule //command/use:go_default_library
_buildifier rule //:buildifier
```

### `$ bzl release`
### `$ bazel release`

Publish a release for a `go_binary` target.

Expand All @@ -92,7 +143,7 @@ rules_go. Here's what the command does:
Example:

```
$ bzl release \
$ bazel release \
--owner=bzl-io \
--repo=bzl \
--commit=91801a92ea21cd73471e5a83ad2519d1a3f257f0 \
Expand Down
21 changes: 11 additions & 10 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
workspace(name = "io_bzl_bzl")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file")

local_repository(
name = "build_stack_rules_proto",
path = "/home/pcj/go/src/github.com/stackb/rules_proto",
)

load("@build_stack_rules_proto//:deps.bzl", "bazel_gazelle", "com_github_bazelbuild_buildtools", "io_bazel_rules_go")
load(
"@build_stack_rules_proto//:deps.bzl",
"bazel_gazelle",
"com_github_bazelbuild_buildtools",
"io_bazel_rules_go",
)

io_bazel_rules_go()

Expand Down Expand Up @@ -93,12 +100,6 @@ go_repository(
importpath = "github.com/pkg/errors",
)

# go_repository(
# name = "com_github_mattn_go_runewidth",
# importpath = "github.com/mattn/go-runewidth",
# commit = "97311d9f7767e3d6f422ea06661bc2c7a19e8a5d",
# )

go_repository(
name = "org_golang_x_tools",
commit = "9b61fcc4c548d69663d915801fc4b42a43b6cd9c",
Expand All @@ -123,9 +124,9 @@ go_repository(
importpath = "github.com/mitchellh/go-homedir",
)

# There exist multiple options for terminal-based progress bars, but
# this is the only one I could find that cross-compiles cleanly with
# current version of rules_go. Not super fancy though.
# There exist multiple options for terminal-based progress bars, but this is the
# only one I could find that cross-compiles cleanly with current version of
# rules_go. Not super fancy though.
go_repository(
name = "com_github_mitchellh_ioprogress",
commit = "8163955264568045f462ae7e2d6d07b2001fc997",
Expand Down
3 changes: 3 additions & 0 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/bzl-io/bzl/command/install"
"github.com/bzl-io/bzl/command/release"
"github.com/bzl-io/bzl/command/targets"
"github.com/bzl-io/bzl/command/use"
)

// Will be replaced at link time to `git rev-parse HEAD`
Expand Down Expand Up @@ -39,6 +40,7 @@ func NewApp() *App {
app.EnableBashCompletion = true
app.Usage = "Wrapper for the Bazel build tool"
app.Version = fmt.Sprintf("https://github.com/bzl-io/bzl/tree/%s (%s)", BuildScmRevision, BuildScmDate)
app.HideHelp = true

// Global flags for bzl app
app.Flags = []cli.Flag{
Expand All @@ -54,6 +56,7 @@ func NewApp() *App {
*install.Command,
*targets.Command,
*release.Command,
*use.Command,
}

instance := &App{
Expand Down
8 changes: 4 additions & 4 deletions command/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ func downloadAsset(baseDir string, asset *github.ReleaseAsset) (string, error) {
err = downloadUrl(redirect, out, int64(*asset.Size), *asset.Name)
} else {
defer rc.Close()
err = dl(rc, out, int64(*asset.Size), *asset.Name)
err = Download(rc, out, int64(*asset.Size), *asset.Name)
}

return filename, nil
Expand All @@ -285,7 +285,7 @@ func downloadUrl(url string, out io.Writer, size int64, title string) error {
return err
}

return dl(resp.Body, out, size, title)
return Download(resp.Body, out, size, title)
}

func downloadUrl2(url string, out io.Writer, size int64, title string) error {
Expand All @@ -295,12 +295,12 @@ func downloadUrl2(url string, out io.Writer, size int64, title string) error {
}
defer f.Close()

return dl(f, out, size, title)
return Download(f, out, size, title)
}

// download accepts a reader, writer, and expected asset size, copies
// the bytes through and displays progress to the console.
func dl(reader io.Reader, writer io.Writer, size int64, title string) error {
func Download(reader io.Reader, writer io.Writer, size int64, title string) error {
// Attempt 1:
// bar := pb.New(size).SetUnits(pb.U_BYTES)
// bar.Prefix(title)
Expand Down
4 changes: 3 additions & 1 deletion command/targets/targets.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ func execute(c *cli.Context) error {
pattern = "//..."
}

fmt.Printf("args: %+v", c.Command)

query, err := bazelutil.New().Query(pattern)
if err != nil {
return err
}

//fmt.Println("Targets:", len(query.GetTarget()))
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', 0)

Expand All @@ -49,7 +52,6 @@ func execute(c *cli.Context) error {
}

func printRule(w io.Writer, rule *build.Rule) {
//fmt.Fprintln(w, "rule\t", *rule.Name, "\t", *rule.RuleClass)
fmt.Fprintln(w, *rule.RuleClass, "\trule\t", *rule.Name)
}

Expand Down
9 changes: 7 additions & 2 deletions command/use/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "go_default_library",
srcs = ["install.go"],
srcs = ["use.go"],
importpath = "github.com/bzl-io/bzl/command/use",
visibility = ["//visibility:public"],
deps = ["@com_github_urfave_cli//:go_default_library"],
deps = [
"//command/install:go_default_library",
"//gh:go_default_library",
"@com_github_google_go_github//github:go_default_library",
"@com_github_urfave_cli//:go_default_library",
],
)
Loading

0 comments on commit c941338

Please sign in to comment.