Skip to content
This repository has been archived by the owner on Mar 5, 2022. It is now read-only.

Commit

Permalink
Build programs into _tools/bin even if GOBIN is explicitly set by the…
Browse files Browse the repository at this point in the history
… caller
  • Loading branch information
spenczar committed Jun 19, 2017
1 parent 8139579 commit 8835b00
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
5 changes: 5 additions & 0 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ package main
// builds all tools in the spec file using whatever is installed in the tool directory (_tools,
// typically). Shouldn't do any network if _tools is set up correctly.
func (s spec) build() {
err := setGoEnv()
if err != nil {
fatal("unable to set GOPATH and GOBIN env variables", err)
}

m := getManifest()
for _, t := range s.Tools {
err := install(t)
Expand Down
25 changes: 24 additions & 1 deletion retool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,24 @@ func TestRetool(t *testing.T) {
}
})

t.Run("build_with_gobin_set", func(t *testing.T) {
// Set GOBIN to a directory not controlled by retool. It should still
// put built binaries in _tools/bin.
t.Parallel()
dir, cleanup := setupTempDir(t)
defer cleanup()
runRetoolCmd(t, dir, retool, "add", "github.com/twitchtv/retool", "origin/master")

cmd := makeRetoolCmd(t, dir, retool, "build")
cmd.Env = append(os.Environ(), "GOBIN="+dir)
err := cmd.Run()
if err != nil {
t.Fatalf("fatal go build err: %v", err)
}

assertBinInstalled(t, dir, "retool")
})

t.Run("dep_added", func(t *testing.T) {
t.Parallel()
dir, cleanup := setupTempDir(t)
Expand Down Expand Up @@ -190,10 +208,15 @@ func main() {}`)
})
}

func runRetoolCmd(t *testing.T, dir, retool string, args ...string) (output string) {
func makeRetoolCmd(t *testing.T, dir, retool string, args ...string) *exec.Cmd {
args = append([]string{"-base-dir", dir}, args...)
cmd := exec.Command(retool, args...)
cmd.Dir = dir
return cmd
}

func runRetoolCmd(t *testing.T, dir, retool string, args ...string) (output string) {
cmd := makeRetoolCmd(t, dir, retool, args...)
out, err := cmd.Output()
if err != nil {
if exitErr, ok := err.(*exec.ExitError); ok {
Expand Down

0 comments on commit 8835b00

Please sign in to comment.