Browse Source

build: Extract setGoPath

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3117
Lars K.W. Gohlke 9 years ago
parent
commit
77e47066ed
1 changed files with 13 additions and 9 deletions
  1. 13 9
      build.go

+ 13 - 9
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()