Skip to content
Myr

Support default value of $GOPATH (#532)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Add support for go1.8 of blank $GOPATH

authored by Elliott Beach · committed by Albert Nigmatzianov · parent b787445 · Browse files · 1 file+22 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+22 added−1 removed

  • other:+22 added−1 removed

1 file+22 added−1 removed

modified:cobra/cmd/helpers.go+22 added-1 removed
16 unmodified lines
17 "bytes"18 "fmt"19 "io"20 "os"21 "os/exec"22 "path/filepath"23 "strings"24 "text/template"25)
5 unmodified lines
31 // Initialize srcPaths.32 envGoPath := os.Getenv("GOPATH")33 goPaths := filepath.SplitList(envGoPath)34 if len(goPaths) == 0 {35 // Adapted from https://github.com/Masterminds/glide/pull/798/files.36 // As of Go 1.8 the GOPATH is no longer required to be set. Instead there37 // is a default value. If there is no GOPATH check for the default value.38 // Note, checking the GOPATH first to avoid invoking the go toolchain if39 // possible.4041 goExecutable := os.Getenv("COBRA_GO_EXECUTABLE")42 if len(goExecutable) <= 0 {43 goExecutable = "go"44 }4546 out, err := exec.Command(goExecutable, "env", "GOPATH").Output()47 if err != nil {48 er(err)49 }5051 toolchainGoPath := strings.TrimSpace(string(out))52 goPaths = filepath.SplitList(toolchainGoPath)53 if len(goPaths) == 0 {34 er("$GOPATH is not set")54 er("$GOPATH is not set")55 }56 }57 srcPaths = make([]string, 0, len(goPaths))58 for _, goPath := range goPaths {59 srcPaths = append(srcPaths, filepath.Join(goPath, "src"))
112 unmodified lines