From 3fe03979a23fa6597d84d22270273ae4de2a1e5c Mon Sep 17 00:00:00 2001 From: Jordan Krage Date: Thu, 22 Jun 2017 07:51:47 -0500 Subject: [PATCH 1/2] remove getGOPATHS; cleanup --- context.go | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/context.go b/context.go index 0d6c8fe826..cededc6532 100644 --- a/context.go +++ b/context.go @@ -43,18 +43,8 @@ type Ctx struct { Verbose bool // Enables more verbose logging. } -// SetPaths sets the WorkingDir and GOPATHSs fields. -// -// ctx := &dep.Ctx{ -// Out: log.New(os.Stdout, "", 0), -// Err: log.New(os.Stderr, "", 0), -// } -// -// err := ctx.SetPaths(workingDir, filepath.SplitList(os.Getenv("GOPATH")) -// if err != nil { -// // Empty GOPATH -// } -// +// SetPaths sets the WorkingDir and GOPATHs fields. If GOPATHs are omitted, then +// the $GOPATH environment variable, and the default GOPATH are checked - in that order. func (c *Ctx) SetPaths(wd string, GOPATHs ...string) error { if wd == "" { return errors.New("cannot set Ctx.WorkingDir to an empty path") @@ -62,7 +52,11 @@ func (c *Ctx) SetPaths(wd string, GOPATHs ...string) error { c.WorkingDir = wd if len(GOPATHs) == 0 { - GOPATHs = getGOPATHs(os.Environ()) + GOPATH := os.Getenv("GOPATH") + if GOPATH == "" { + GOPATH = defaultGOPATH() + } + GOPATHs = filepath.SplitList(GOPATH) } for _, gp := range GOPATHs { c.GOPATHs = append(c.GOPATHs, filepath.ToSlash(gp)) @@ -71,17 +65,6 @@ func (c *Ctx) SetPaths(wd string, GOPATHs ...string) error { return nil } -// getGOPATH returns the GOPATHs from the passed environment variables. -// If GOPATH is not defined, fallback to defaultGOPATH(). -func getGOPATHs(env []string) []string { - GOPATH := os.Getenv("GOPATH") - if GOPATH == "" { - GOPATH = defaultGOPATH() - } - - return filepath.SplitList(GOPATH) -} - // defaultGOPATH gets the default GOPATH that was added in 1.8 // copied from go/build/build.go func defaultGOPATH() string { From ac8ec854a9190353e925041a4a807668889ee7d5 Mon Sep 17 00:00:00 2001 From: Jordan Krage Date: Sun, 25 Jun 2017 12:21:35 -0500 Subject: [PATCH 2/2] update SetPaths doc --- context.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/context.go b/context.go index cededc6532..0f55e316c7 100644 --- a/context.go +++ b/context.go @@ -43,8 +43,8 @@ type Ctx struct { Verbose bool // Enables more verbose logging. } -// SetPaths sets the WorkingDir and GOPATHs fields. If GOPATHs are omitted, then -// the $GOPATH environment variable, and the default GOPATH are checked - in that order. +// SetPaths sets the WorkingDir and GOPATHs fields. If GOPATHs is empty, then +// the GOPATH environment variable (or the default GOPATH) is used instead. func (c *Ctx) SetPaths(wd string, GOPATHs ...string) error { if wd == "" { return errors.New("cannot set Ctx.WorkingDir to an empty path")