构建时切换 GOPATH

This commit is contained in:
Liang Ding 2014-08-28 10:19:00 +08:00
parent ed8cd5b5e9
commit befb16c2b8
1 changed files with 8 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package output
import (
"encoding/json"
"github.com/b3log/wide/conf"
"github.com/b3log/wide/session"
"github.com/golang/glog"
"github.com/gorilla/websocket"
@ -151,6 +152,9 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
cmd := exec.Command("go", argv...)
cmd.Dir = curDir
// 设置环境变量(设置当前用户的 GOPATH 等)
setCmdEnv(cmd)
glog.Infof("go build -o %s %s", executable, filePath)
executable = curDir + string(os.PathSeparator) + executable
@ -208,3 +212,7 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.Write(ret)
}
func setCmdEnv(cmd *exec.Cmd) {
cmd.Env = append(cmd.Env, "GOPATH="+conf.Wide.GOPATH, "GOROOT="+os.Getenv("GOROOT"))
}