用户可以在 Preference->Go Tool 中设置构建参数。

需要重写 build 输出处理,目前是按照是否有输出来判断构建成败,应该改为按输出流/错误流判断
This commit is contained in:
Liang Ding 2017-03-15 00:21:13 +08:00
parent 130006608f
commit bfbc47c3c4
6 changed files with 29 additions and 4 deletions

View File

@ -59,6 +59,7 @@ type User struct {
Workspace string // the GOPATH of this user (maybe contain several paths splitted by os.PathListSeparator)
Locale string
GoFormat string
GoBuildArgs string
FontFamily string
FontSize string
Theme string
@ -91,7 +92,7 @@ func NewUser(username, password, email, workspace string) *User {
now := time.Now().UnixNano()
return &User{Name: username, Password: password, Salt: salt, Email: email, Gravatar: gravatar, Workspace: workspace,
Locale: Wide.Locale, GoFormat: "gofmt", FontFamily: "Helvetica", FontSize: "13px", Theme: "default",
Locale: Wide.Locale, GoFormat: "gofmt", GoBuildArgs: "-i", FontFamily: "Helvetica", FontSize: "13px", Theme: "default",
Keymap: "wide",
Created: now, Updated: now, Lived: now,
Editor: &editor{FontFamily: "Consolas, 'Courier New', monospace", FontSize: "inherit", LineHeight: "17px",

View File

@ -137,6 +137,11 @@ func initUsers() {
user.Keymap = "wide"
}
// Compatibility upgrade (1.5.3): https://github.com/b3log/wide/issues/308
if "" == user.GoBuildArgs {
user.GoBuildArgs = "-i"
}
Users = append(Users, user)
}

View File

@ -45,7 +45,8 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
return
}
username := httpSession.Values["username"].(string)
locale := conf.GetUser(username).Locale
user := conf.GetUser(username)
locale := user.Locale
var args map[string]interface{}
@ -93,7 +94,11 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
suffix = ".exe"
}
cmd := exec.Command("go", "build")
goBuildArgs := []string{}
goBuildArgs = append(goBuildArgs, "build")
goBuildArgs = append(goBuildArgs, strings.Split(user.GoBuildArgs, " ")...)
cmd := exec.Command("go", goBuildArgs...)
cmd.Dir = curDir
setCmdEnv(cmd, username)
@ -126,7 +131,10 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
if nil != session.OutputWS[sid] {
// display "START [go build]" in front-end browser
channelRet["output"] = "<span class='start-build'>" + i18n.Get(locale, "start-build").(string) + "</span>\n"
msg := i18n.Get(locale, "start-build").(string)
msg = strings.Replace(msg, "build]", "build "+user.GoBuildArgs+"]", 1)
channelRet["output"] = "<span class='start-build'>" + msg + "</span>\n"
channelRet["cmd"] = "start-build"
wsChannel := session.OutputWS[sid]
@ -162,6 +170,8 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
channelRet["cmd"] = "build"
channelRet["executable"] = executable
// FIXME: Daniel, build output process, should check stdout/stderr rather than length of output
if 0 == len(buf) { // build success
channelRet["nextCmd"] = args["nextCmd"]
channelRet["output"] = "<span class='build-succ'>" + i18n.Get(locale, "build-succ").(string) + "</span>\n"

View File

@ -95,6 +95,7 @@ func PreferenceHandler(w http.ResponseWriter, r *http.Request) {
FontFamily string
FontSize string
GoFmt string
GoBuildArgs string
Keymap string
Workspace string
Username string
@ -119,6 +120,7 @@ func PreferenceHandler(w http.ResponseWriter, r *http.Request) {
user.FontFamily = args.FontFamily
user.FontSize = args.FontSize
user.GoFormat = args.GoFmt
user.GoBuildArgs = args.GoBuildArgs
user.Keymap = args.Keymap
// XXX: disallow change workspace at present
// user.Workspace = args.Workspace

View File

@ -424,6 +424,7 @@ var menu = {
$fontFamily = $dialogPreference.find("input[name=fontFamily]"),
$fontSize = $dialogPreference.find("input[name=fontSize]"),
$goFmt = $dialogPreference.find("select[name=goFmt]"),
$goBuildArgs = $dialogPreference.find("input[name=goBuildArgs]"),
$workspace = $dialogPreference.find("input[name=workspace]"),
$password = $dialogPreference.find("input[name=password]"),
$email = $dialogPreference.find("input[name=email]"),
@ -440,6 +441,7 @@ var menu = {
"fontFamily": $fontFamily.val(),
"fontSize": $fontSize.val(),
"goFmt": $goFmt.val(),
"goBuildArgs": $goBuildArgs.val(),
"workspace": $workspace.val(),
"password": $password.val(),
"email": $email.val(),
@ -469,6 +471,7 @@ var menu = {
$fontFamily.data("value", $fontFamily.val());
$fontSize.data("value", $fontSize.val());
$goFmt.data("value", $goFmt.val());
$goBuildArgs.data("value", $goBuildArgs.val());
$workspace.data("value", $workspace.val());
$password.data("value", $password.val());
$email.data("value", $email.val());

View File

@ -70,6 +70,10 @@
{{end}}
</select>
</label>
<label>
Go Build Args{{.i18n.colon}}
<input data-value="{{.user.GoBuildArgs}}" value="{{.user.GoBuildArgs}}" name="goBuildArgs"/>
</label>
</div>
<div class="fn-none" data-index="keymap">
<label>