@@ -43,44 +43,27 @@ type Ctx struct {
43
43
Verbose bool // Enables more verbose logging.
44
44
}
45
45
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.
58
48
func (c * Ctx ) SetPaths (wd string , GOPATHs ... string ) error {
59
49
if wd == "" {
60
50
return errors .New ("cannot set Ctx.WorkingDir to an empty path" )
61
51
}
62
52
c .WorkingDir = wd
63
53
64
54
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 )
66
60
}
67
61
68
62
c .GOPATHs = append (c .GOPATHs , GOPATHs ... )
69
63
70
64
return nil
71
65
}
72
66
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
-
84
67
// defaultGOPATH gets the default GOPATH that was added in 1.8
85
68
// copied from go/build/build.go
86
69
func defaultGOPATH () string {
0 commit comments