workflow improved

This commit is contained in:
asoseil 2017-10-22 20:50:51 +02:00
parent d00b437295
commit d02dc91443
1 changed files with 16 additions and 17 deletions

33
exec.go
View File

@ -19,15 +19,8 @@ func (p *Project) goCompile(stop <-chan bool, method []string, args []string) (s
var out bytes.Buffer var out bytes.Buffer
var stderr bytes.Buffer var stderr bytes.Buffer
done := make(chan error) done := make(chan error)
err := os.Setenv("GOBIN", filepath.Join(getEnvPath("GOPATH"), "bin"))
if err != nil {
return "", err
}
args = append(method, args...) args = append(method, args...)
cmd := exec.Command(args[0], args[1:]...) cmd := exec.Command(args[0], args[1:]...)
if _, err := os.Stat(filepath.Join(p.base, p.path)); err == nil {
p.path = filepath.Join(p.base, p.path)
}
cmd.Dir = p.path cmd.Dir = p.path
cmd.Stdout = &out cmd.Stdout = &out
cmd.Stderr = &stderr cmd.Stderr = &stderr
@ -53,6 +46,8 @@ func (p *Project) goCompile(stop <-chan bool, method []string, args []string) (s
func (p *Project) goRun(stop <-chan bool, runner chan bool) { func (p *Project) goRun(stop <-chan bool, runner chan bool) {
var build *exec.Cmd var build *exec.Cmd
var args []string var args []string
// custom error pattern
isErrorText := func(string) bool { isErrorText := func(string) bool {
return false return false
} }
@ -67,20 +62,22 @@ func (p *Project) goRun(stop <-chan bool, runner chan bool) {
} }
} }
// add additional arguments
for _, arg := range p.Args { for _, arg := range p.Args {
a := strings.FieldsFunc(arg, func(i rune) bool { a := strings.FieldsFunc(arg, func(i rune) bool {
return i == '"' || i == '=' || i == '\'' return i == '"' || i == '=' || i == '\''
}) })
args = append(args, a...) args = append(args, a...)
} }
if _, err := os.Stat(filepath.Join(getEnvPath("GOBIN"), filepath.Base(p.base))); err == nil { gobin := os.Getenv("GOBIN")
build = exec.Command(filepath.Join(getEnvPath("GOBIN"), filepath.Base(p.base)), args...) path := filepath.Join(gobin, p.name)
} else if _, err := os.Stat(filepath.Join(getEnvPath("GOBIN"), filepath.Base(p.base)) + extWindows); err == nil { if _, err := os.Stat(path); err == nil {
build = exec.Command(filepath.Join(getEnvPath("GOBIN"), filepath.Base(p.base))+extWindows, args...) build = exec.Command(path, args...)
} else if _, err := os.Stat(path + extWindows); err == nil {
build = exec.Command(path+extWindows, args...)
} else { } else {
path := filepath.Join(p.base, filepath.Base(p.base)) path := filepath.Join(p.path, p.name)
if _, err = os.Stat(path); err == nil { if _, err = os.Stat(path); err == nil {
build = exec.Command(path, args...) build = exec.Command(path, args...)
} else if _, err = os.Stat(path + extWindows); err == nil { } else if _, err = os.Stat(path + extWindows); err == nil {
@ -100,6 +97,7 @@ func (p *Project) goRun(stop <-chan bool, runner chan bool) {
p.stamp("log", out, msg, "") p.stamp("log", out, msg, "")
}() }()
// scan project stream
stdout, err := build.StdoutPipe() stdout, err := build.StdoutPipe()
stderr, err := build.StderrPipe() stderr, err := build.StderrPipe()
if err != nil { if err != nil {
@ -149,12 +147,13 @@ func (p *Project) command(stop <-chan bool, cmd Command) (string, string) {
done := make(chan error) done := make(chan error)
args := strings.Split(strings.Replace(strings.Replace(cmd.Command, "'", "", -1), "\"", "", -1), " ") args := strings.Split(strings.Replace(strings.Replace(cmd.Command, "'", "", -1), "\"", "", -1), " ")
exec := exec.Command(args[0], args[1:]...) exec := exec.Command(args[0], args[1:]...)
exec.Dir = p.base exec.Dir = p.path
// make cmd path
if cmd.Path != "" { if cmd.Path != "" {
if strings.Contains(cmd.Path, p.base) { if strings.Contains(cmd.Path, p.path) {
exec.Dir = cmd.Path exec.Dir = cmd.Path
} else { } else {
exec.Dir = filepath.Join(p.base, cmd.Path) exec.Dir = filepath.Join(p.path, cmd.Path)
} }
} }
exec.Stdout = &stdout exec.Stdout = &stdout
@ -187,7 +186,7 @@ func (p *Project) goTool(wg *sync.WaitGroup, stop <-chan bool, result chan<- too
if strings.HasSuffix(path, ".go") || strings.HasSuffix(path, "") { if strings.HasSuffix(path, ".go") || strings.HasSuffix(path, "") {
if strings.HasSuffix(path, ".go") { if strings.HasSuffix(path, ".go") {
tool.options = append(tool.options, path) tool.options = append(tool.options, path)
path = p.base path = p.path
} }
if s := ext(path); s == "" || s == "go" { if s := ext(path); s == "" || s == "go" {
var out, stderr bytes.Buffer var out, stderr bytes.Buffer