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
1 changed files with 13 additions and 9 deletions

View File

@ -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()