diff --git a/build.go b/build.go index 1acb1baf0..955455b82 100644 --- a/build.go +++ b/build.go @@ -117,16 +117,8 @@ func main() { log.SetOutput(os.Stdout) log.SetFlags(0) - // If GOPATH isn't set, set it correctly with the assumption that we are - // in $GOPATH/src/github.com/syncthing/syncthing. if os.Getenv("GOPATH") == "" { - cwd, err := os.Getwd() - if err != nil { - log.Fatal(err) - } - gopath := filepath.Clean(filepath.Join(cwd, "../../../../")) - log.Println("GOPATH is", gopath) - os.Setenv("GOPATH", gopath) + setGoPath() } // We use Go 1.5+ vendoring. @@ -241,6 +233,18 @@ func main() { } } +// setGoPath sets GOPATH correctly with the assumption that we are +// in $GOPATH/src/github.com/syncthing/syncthing. +func setGoPath() { + cwd, err := os.Getwd() + if err != nil { + log.Fatal(err) + } + gopath := filepath.Clean(filepath.Join(cwd, "../../../../")) + log.Println("GOPATH is", gopath) + os.Setenv("GOPATH", gopath) +} + func checkRequiredGoVersion() (float64, bool) { re := regexp.MustCompile(`go(\d+\.\d+)`) ver := runtime.Version()