Skip to content

Commit

Permalink
If GOBIN is set when installing, prefer that over GOPATH (magefile#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
justinclift authored and natefinch committed Apr 5, 2019
1 parent 8dce728 commit 5bc3a8a
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,20 @@ func Install() error {
}

gocmd := mg.GoCmd()
gopath, err := sh.Output(gocmd, "env", "GOPATH")
// use GOBIN if set in the environment, otherwise fall back to first path
// in GOPATH environment string
bin, err := sh.Output(gocmd, "env", "GOBIN")
if err != nil {
return fmt.Errorf("can't determine GOPATH: %v", err)
return fmt.Errorf("can't determine GOBIN: %v", err)
}
if bin == "" {
gopath, err := sh.Output(gocmd, "env", "GOPATH")
if err != nil {
return fmt.Errorf("can't determine GOPATH: %v", err)
}
paths := strings.Split(gopath, string([]rune{os.PathListSeparator}))
bin = filepath.Join(paths[0], "bin")
}
paths := strings.Split(gopath, string([]rune{os.PathListSeparator}))
bin := filepath.Join(paths[0], "bin")
// specifically don't mkdirall, if you have an invalid gopath in the first
// place, that's not on us to fix.
if err := os.Mkdir(bin, 0700); err != nil && !os.IsExist(err) {
Expand Down

0 comments on commit 5bc3a8a

Please sign in to comment.