autogo

command
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2018 License: Apache-2.0 Imports: 5 Imported by: 0

README

Automatically generate bazel rules for go packages

This uses gazelle to generate and update bazel rules for golang packages without adding new BUILD.bazel files to the repository.

Usage

See options for installing bazel.

# Install bazel
brew install bazel # See https://docs.bazel.build/versions/master/install.html

# Create a bazel WORKSPACE file in your repo root
echo >WORKSPACE <<END
git_repository(
  name = "fejta_autogo",
  remote = "https://github.com/fejta/test-infra.git",
  commit = "f478925cc6179f1abf6245698aaf514d873cfcc9",
)
load("@fejta_autogo//autogo:deps.bzl", "autogo_dependencies")
autogo_dependencies()
load("@fejta_autogo//autogo:def.bzl", "autogo_generate")
autogo_generate(
    name = "autogo",
    prefix = "github.com/golang/dep", # change to your go get path
)
END

# Create an empty BUILD.bazel file (needed by bazel)
touch BUILD.bazel

# Use bazel with an @autogo prefix to access the auto-generated repo
bazel query @autogo//...
bazel run @autogo//path/to/my/cmd/binary

Demo

Add bazel support to dep:

git clone https://github.com/fejta/dep  # golang/dep + a WORKSPACE file
cd dep && ls WORKSPACE
bazel run @autogo//cmd/dep -- help

See the concrete WORKSPACE that enables this.

Documentation

Overview

autogo creates a shadow copy of the go packages at origin in a destination.

In other words this program will walk the directory tree at origin and for each: * directory - create a directory with the same name in destination * go-related-file - link the file into the matching destination directory

The effect is similar to:

rsync -zarv --include="*/" --include="*.sh" --exclude="*" "$from" "$to"

TODO(fejta): investigate just using rsync?

The intended use case of this program is with the autogo_generate in //autogo:def.bzl. This rule will clone your primary workspace into an autogo workspace, and then run gazelle to generate rules for go packages.

Usage:

autogo -- <ORIGIN_DIR> <DEST_DIR>

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL