build: Extract setGoPath

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3117
This commit is contained in:
Lars K.W. Gohlke 2016-05-19 21:01:23 +00:00 committed by Audrius Butkevicius
parent 852759f904
commit 77e47066ed

View File

@ -117,16 +117,8 @@ func main() {
log.SetOutput(os.Stdout) log.SetOutput(os.Stdout)
log.SetFlags(0) 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") == "" { if os.Getenv("GOPATH") == "" {
cwd, err := os.Getwd() setGoPath()
if err != nil {
log.Fatal(err)
}
gopath := filepath.Clean(filepath.Join(cwd, "../../../../"))
log.Println("GOPATH is", gopath)
os.Setenv("GOPATH", gopath)
} }
// We use Go 1.5+ vendoring. // 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) { func checkRequiredGoVersion() (float64, bool) {
re := regexp.MustCompile(`go(\d+\.\d+)`) re := regexp.MustCompile(`go(\d+\.\d+)`)
ver := runtime.Version() ver := runtime.Version()