Skip to content

Commit 5bc3a8a

Browse files
justincliftnatefinch
authored andcommitted
If GOBIN is set when installing, prefer that over GOPATH (#232)
1 parent 8dce728 commit 5bc3a8a

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

magefile.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,20 @@ func Install() error {
2727
}
2828

2929
gocmd := mg.GoCmd()
30-
gopath, err := sh.Output(gocmd, "env", "GOPATH")
30+
// use GOBIN if set in the environment, otherwise fall back to first path
31+
// in GOPATH environment string
32+
bin, err := sh.Output(gocmd, "env", "GOBIN")
3133
if err != nil {
32-
return fmt.Errorf("can't determine GOPATH: %v", err)
34+
return fmt.Errorf("can't determine GOBIN: %v", err)
35+
}
36+
if bin == "" {
37+
gopath, err := sh.Output(gocmd, "env", "GOPATH")
38+
if err != nil {
39+
return fmt.Errorf("can't determine GOPATH: %v", err)
40+
}
41+
paths := strings.Split(gopath, string([]rune{os.PathListSeparator}))
42+
bin = filepath.Join(paths[0], "bin")
3343
}
34-
paths := strings.Split(gopath, string([]rune{os.PathListSeparator}))
35-
bin := filepath.Join(paths[0], "bin")
3644
// specifically don't mkdirall, if you have an invalid gopath in the first
3745
// place, that's not on us to fix.
3846
if err := os.Mkdir(bin, 0700); err != nil && !os.IsExist(err) {

0 commit comments

Comments
 (0)