用户可以在 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) Workspace string // the GOPATH of this user (maybe contain several paths splitted by os.PathListSeparator)
Locale string Locale string
GoFormat string GoFormat string
GoBuildArgs string
FontFamily string FontFamily string
FontSize string FontSize string
Theme string Theme string
@ -91,7 +92,7 @@ func NewUser(username, password, email, workspace string) *User {
now := time.Now().UnixNano() now := time.Now().UnixNano()
return &User{Name: username, Password: password, Salt: salt, Email: email, Gravatar: gravatar, Workspace: workspace, 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", Keymap: "wide",
Created: now, Updated: now, Lived: now, Created: now, Updated: now, Lived: now,
Editor: &editor{FontFamily: "Consolas, 'Courier New', monospace", FontSize: "inherit", LineHeight: "17px", Editor: &editor{FontFamily: "Consolas, 'Courier New', monospace", FontSize: "inherit", LineHeight: "17px",

View File

@ -137,6 +137,11 @@ func initUsers() {
user.Keymap = "wide" 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) Users = append(Users, user)
} }

View File

@ -45,7 +45,8 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
username := httpSession.Values["username"].(string) username := httpSession.Values["username"].(string)
locale := conf.GetUser(username).Locale user := conf.GetUser(username)
locale := user.Locale
var args map[string]interface{} var args map[string]interface{}
@ -93,7 +94,11 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
suffix = ".exe" 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 cmd.Dir = curDir
setCmdEnv(cmd, username) setCmdEnv(cmd, username)
@ -126,7 +131,10 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
if nil != session.OutputWS[sid] { if nil != session.OutputWS[sid] {
// display "START [go build]" in front-end browser // 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" channelRet["cmd"] = "start-build"
wsChannel := session.OutputWS[sid] wsChannel := session.OutputWS[sid]
@ -162,6 +170,8 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
channelRet["cmd"] = "build" channelRet["cmd"] = "build"
channelRet["executable"] = executable channelRet["executable"] = executable
// FIXME: Daniel, build output process, should check stdout/stderr rather than length of output
if 0 == len(buf) { // build success if 0 == len(buf) { // build success
channelRet["nextCmd"] = args["nextCmd"] channelRet["nextCmd"] = args["nextCmd"]
channelRet["output"] = "<span class='build-succ'>" + i18n.Get(locale, "build-succ").(string) + "</span>\n" 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 FontFamily string
FontSize string FontSize string
GoFmt string GoFmt string
GoBuildArgs string
Keymap string Keymap string
Workspace string Workspace string
Username string Username string
@ -119,6 +120,7 @@ func PreferenceHandler(w http.ResponseWriter, r *http.Request) {
user.FontFamily = args.FontFamily user.FontFamily = args.FontFamily
user.FontSize = args.FontSize user.FontSize = args.FontSize
user.GoFormat = args.GoFmt user.GoFormat = args.GoFmt
user.GoBuildArgs = args.GoBuildArgs
user.Keymap = args.Keymap user.Keymap = args.Keymap
// XXX: disallow change workspace at present // XXX: disallow change workspace at present
// user.Workspace = args.Workspace // user.Workspace = args.Workspace

View File

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

View File

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