Merge remote-tracking branch 'refs/remotes/origin/master' into 1.5.3-dev

This commit is contained in:
Liang Ding 2017-03-27 21:08:40 +08:00
commit ec3c3b52f4
9 changed files with 72 additions and 20 deletions

View File

@ -24,7 +24,7 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"time" "time"
"regexp"
"github.com/b3log/wide/util" "github.com/b3log/wide/util"
) )
@ -59,7 +59,9 @@ 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 GoBuildArgsforLinux string
GoBuildArgsforWindows string
GoBuildArgsforDarwin string
FontFamily string FontFamily string
FontSize string FontSize string
Theme string Theme string
@ -92,7 +94,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", GoBuildArgs: "-i", FontFamily: "Helvetica", FontSize: "13px", Theme: "default", Locale: Wide.Locale, GoFormat: "gofmt", GoBuildArgsforLinux: "-i", GoBuildArgsforWindows: "-i", GoBuildArgsforDarwin: "-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",
@ -155,3 +157,23 @@ func Salt(password, salt string) string {
return hex.EncodeToString(sha1hash.Sum(nil)) return hex.EncodeToString(sha1hash.Sum(nil))
} }
func (u *User) GetBuildArgs(os string) []string {
var tmp string
if os == "windows" {
tmp = u.GoBuildArgsforWindows
}
if os == "linux" {
tmp = u.GoBuildArgsforLinux
}
if os == "darwin" {
tmp = u.GoBuildArgsforDarwin
}
exp := regexp.MustCompile(`[^\s"']+|"([^"]*)"|'([^']*)'`)
words := exp.FindAllString(tmp, -1)
for idx := range words {
words[idx] = strings.Replace(words[idx], "\"", "", -1)
}
return words
}

View File

@ -138,8 +138,14 @@ func initUsers() {
} }
// Compatibility upgrade (1.5.3): https://github.com/b3log/wide/issues/308 // Compatibility upgrade (1.5.3): https://github.com/b3log/wide/issues/308
if "" == user.GoBuildArgs { if "" == user.GoBuildArgsforLinux {
user.GoBuildArgs = "-i" user.GoBuildArgsforLinux = "-i"
}
if "" == user.GoBuildArgsforWindows {
user.GoBuildArgsforWindows = "-i"
}
if "" == user.GoBuildArgsforDarwin {
user.GoBuildArgsforDarwin = "-i"
} }
Users = append(Users, user) Users = append(Users, user)

View File

@ -17,6 +17,7 @@ package output
import ( import (
"bufio" "bufio"
"encoding/json" "encoding/json"
"fmt"
"io" "io"
"net/http" "net/http"
"os" "os"
@ -24,6 +25,7 @@ import (
"path/filepath" "path/filepath"
"strconv" "strconv"
"strings" "strings"
"runtime"
"github.com/b3log/wide/conf" "github.com/b3log/wide/conf"
"github.com/b3log/wide/i18n" "github.com/b3log/wide/i18n"
@ -94,7 +96,7 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
goBuildArgs := []string{} goBuildArgs := []string{}
goBuildArgs = append(goBuildArgs, "build") goBuildArgs = append(goBuildArgs, "build")
goBuildArgs = append(goBuildArgs, strings.Split(user.GoBuildArgs, " ")...) goBuildArgs = append(goBuildArgs, user.GetBuildArgs(runtime.GOOS)...)
cmd := exec.Command("go", goBuildArgs...) cmd := exec.Command("go", goBuildArgs...)
cmd.Dir = curDir cmd.Dir = curDir
@ -130,7 +132,7 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
// display "START [go build]" in front-end browser // display "START [go build]" in front-end browser
msg := i18n.Get(locale, "start-build").(string) msg := i18n.Get(locale, "start-build").(string)
msg = strings.Replace(msg, "build]", "build "+user.GoBuildArgs+"]", 1) msg = strings.Replace(msg, "build]", "build "+fmt.Sprint(user.GetBuildArgs(runtime.GOOS))+"]", 1)
channelRet["output"] = "<span class='start-build'>" + msg + "</span>\n" channelRet["output"] = "<span class='start-build'>" + msg + "</span>\n"
channelRet["cmd"] = "start-build" channelRet["cmd"] = "start-build"

View File

@ -25,7 +25,6 @@ import (
"path/filepath" "path/filepath"
"strconv" "strconv"
"strings" "strings"
"github.com/b3log/wide/conf" "github.com/b3log/wide/conf"
"github.com/b3log/wide/i18n" "github.com/b3log/wide/i18n"
"github.com/b3log/wide/session" "github.com/b3log/wide/session"
@ -75,7 +74,12 @@ func CrossCompilationHandler(w http.ResponseWriter, r *http.Request) {
suffix = ".exe" suffix = ".exe"
} }
cmd := exec.Command("go", "build") user := conf.GetUser(username)
goBuildArgs := []string{}
goBuildArgs = append(goBuildArgs, "build")
goBuildArgs = append(goBuildArgs, user.GetBuildArgs(goos)...)
cmd := exec.Command("go", goBuildArgs...)
cmd.Dir = curDir cmd.Dir = curDir
setCmdEnv(cmd, username) setCmdEnv(cmd, username)

View File

@ -95,7 +95,9 @@ func PreferenceHandler(w http.ResponseWriter, r *http.Request) {
FontFamily string FontFamily string
FontSize string FontSize string
GoFmt string GoFmt string
GoBuildArgs string GoBuildArgsforLinux string
GoBuildArgsforWindows string
GoBuildArgsforDarwin string
Keymap string Keymap string
Workspace string Workspace string
Username string Username string
@ -120,7 +122,9 @@ 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.GoBuildArgsforLinux = args.GoBuildArgsforLinux
user.GoBuildArgsforWindows = args.GoBuildArgsforWindows
user.GoBuildArgsforDarwin = args.GoBuildArgsforDarwin
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

@ -425,7 +425,9 @@ 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]"), $GoBuildArgsforLinux = $dialogPreference.find("input[name=GoBuildArgsforLinux]"),
$GoBuildArgsforWindows = $dialogPreference.find("input[name=GoBuildArgsforWindows]"),
$GoBuildArgsforDarwin = $dialogPreference.find("input[name=GoBuildArgsforDarwin]"),
$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]"),
@ -442,7 +444,9 @@ var menu = {
"fontFamily": $fontFamily.val(), "fontFamily": $fontFamily.val(),
"fontSize": $fontSize.val(), "fontSize": $fontSize.val(),
"goFmt": $goFmt.val(), "goFmt": $goFmt.val(),
"goBuildArgs": $goBuildArgs.val(), "GoBuildArgsforLinux": $GoBuildArgsforLinux.val(),
"GoBuildArgsforWindows": $GoBuildArgsforWindows.val(),
"GoBuildArgsforDarwin": $GoBuildArgsforDarwin.val(),
"workspace": $workspace.val(), "workspace": $workspace.val(),
"password": $password.val(), "password": $password.val(),
"email": $email.val(), "email": $email.val(),
@ -472,7 +476,9 @@ 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()); $goBuildArgs.data("value", $GoBuildArgsforLinux.val());
$goBuildArgs.data("value", $GoBuildArgsforWindows.val());
$goBuildArgs.data("value", $GoBuildArgsforDarwin.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());

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -71,8 +71,16 @@
</select> </select>
</label> </label>
<label> <label>
Go Build Args{{.i18n.colon}} Go Build Args Linux{{.i18n.colon}}
<input data-value="{{.user.GoBuildArgs}}" value="{{.user.GoBuildArgs}}" name="goBuildArgs"/> <input data-value="{{.user.GoBuildArgsforLinux}}" value="{{.user.GoBuildArgsforLinux}}" name="GoBuildArgsforLinux"/>
</label>
<label>
Go Build Args Windows{{.i18n.colon}}
<input data-value="{{.user.GoBuildArgsforWindows}}" value="{{.user.GoBuildArgsforWindows}}" name="GoBuildArgsforWindows"/>
</label>
<label>
Go Build Args Darwin{{.i18n.colon}}
<input data-value="{{.user.GoBuildArgsforDarwin}}" value="{{.user.GoBuildArgsforDarwin}}" name="GoBuildArgsforDarwin"/>
</label> </label>
</div> </div>
<div class="fn-none" data-index="keymap"> <div class="fn-none" data-index="keymap">