Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Commit f16f7a8

Browse files
authored
Merge pull request #785 from jmank88/getGOPATHs
remove getGOPATHS; cleanup
2 parents 9f3d2ec + ac8ec85 commit f16f7a8

File tree

1 file changed

+7
-24
lines changed

1 file changed

+7
-24
lines changed

context.go

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -43,44 +43,27 @@ type Ctx struct {
4343
Verbose bool // Enables more verbose logging.
4444
}
4545

46-
// SetPaths sets the WorkingDir and GOPATHSs fields.
47-
//
48-
// ctx := &dep.Ctx{
49-
// Out: log.New(os.Stdout, "", 0),
50-
// Err: log.New(os.Stderr, "", 0),
51-
// }
52-
//
53-
// err := ctx.SetPaths(workingDir, filepath.SplitList(os.Getenv("GOPATH"))
54-
// if err != nil {
55-
// // Empty GOPATH
56-
// }
57-
//
46+
// SetPaths sets the WorkingDir and GOPATHs fields. If GOPATHs is empty, then
47+
// the GOPATH environment variable (or the default GOPATH) is used instead.
5848
func (c *Ctx) SetPaths(wd string, GOPATHs ...string) error {
5949
if wd == "" {
6050
return errors.New("cannot set Ctx.WorkingDir to an empty path")
6151
}
6252
c.WorkingDir = wd
6353

6454
if len(GOPATHs) == 0 {
65-
GOPATHs = getGOPATHs(os.Environ())
55+
GOPATH := os.Getenv("GOPATH")
56+
if GOPATH == "" {
57+
GOPATH = defaultGOPATH()
58+
}
59+
GOPATHs = filepath.SplitList(GOPATH)
6660
}
6761

6862
c.GOPATHs = append(c.GOPATHs, GOPATHs...)
6963

7064
return nil
7165
}
7266

73-
// getGOPATH returns the GOPATHs from the passed environment variables.
74-
// If GOPATH is not defined, fallback to defaultGOPATH().
75-
func getGOPATHs(env []string) []string {
76-
GOPATH := os.Getenv("GOPATH")
77-
if GOPATH == "" {
78-
GOPATH = defaultGOPATH()
79-
}
80-
81-
return filepath.SplitList(GOPATH)
82-
}
83-
8467
// defaultGOPATH gets the default GOPATH that was added in 1.8
8568
// copied from go/build/build.go
8669
func defaultGOPATH() string {

0 commit comments

Comments
 (0)