#16 could be supported
This commit is contained in:
parent
929738d303
commit
43653ad810
24
exec.go
24
exec.go
|
@ -15,7 +15,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// GoCompile is used for compile a project
|
// GoCompile is used for compile a project
|
||||||
func (p *Project) goCompile(stop <-chan bool, args []string) (string, error) {
|
func (p *Project) goCompile(stop <-chan bool, method []string, args []string) (string, error) {
|
||||||
var out bytes.Buffer
|
var out bytes.Buffer
|
||||||
var stderr bytes.Buffer
|
var stderr bytes.Buffer
|
||||||
done := make(chan error)
|
done := make(chan error)
|
||||||
|
@ -23,8 +23,12 @@ func (p *Project) goCompile(stop <-chan bool, args []string) (string, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
cmd := exec.Command("go", args...)
|
args = append(method, args...)
|
||||||
cmd.Dir = p.base
|
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.Stdout = &out
|
cmd.Stdout = &out
|
||||||
cmd.Stderr = &stderr
|
cmd.Stderr = &stderr
|
||||||
// Start command
|
// Start command
|
||||||
|
@ -62,9 +66,13 @@ func (p *Project) goRun(stop <-chan bool, runner chan bool) {
|
||||||
return errRegexp.MatchString(t)
|
return errRegexp.MatchString(t)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, arg := range p.Args {
|
for _, arg := range p.Args {
|
||||||
arr := strings.Fields(arg)
|
a := strings.FieldsFunc(arg, func(i rune) bool {
|
||||||
args = append(args, arr...)
|
return i == '"' || i == '=' || i == '\''
|
||||||
|
})
|
||||||
|
args = append(args, a...)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := os.Stat(filepath.Join(p.base, p.path)); err == nil {
|
if _, err := os.Stat(filepath.Join(p.base, p.path)); err == nil {
|
||||||
|
@ -174,15 +182,15 @@ func (p *Project) command(stop <-chan bool, cmd Command) (string, string) {
|
||||||
func (p *Project) goTool(wg *sync.WaitGroup, stop <-chan bool, result chan<- tool, path string, tool tool) {
|
func (p *Project) goTool(wg *sync.WaitGroup, stop <-chan bool, result chan<- tool, path string, tool tool) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
if tool.status {
|
if tool.status {
|
||||||
|
if tool.dir {
|
||||||
|
path = filepath.Dir(path)
|
||||||
|
}
|
||||||
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.base
|
||||||
}
|
}
|
||||||
if s := ext(path); s == "" || s == "go" {
|
if s := ext(path); s == "" || s == "go" {
|
||||||
if tool.dir {
|
|
||||||
path = filepath.Dir(path)
|
|
||||||
}
|
|
||||||
var out, stderr bytes.Buffer
|
var out, stderr bytes.Buffer
|
||||||
done := make(chan error)
|
done := make(chan error)
|
||||||
cmd := exec.Command(tool.cmd, tool.options...)
|
cmd := exec.Command(tool.cmd, tool.options...)
|
||||||
|
|
|
@ -9,12 +9,12 @@ func TestProject_GoCompile(t *testing.T) {
|
||||||
p := Project{}
|
p := Project{}
|
||||||
stop := make(chan bool)
|
stop := make(chan bool)
|
||||||
response := make(chan string)
|
response := make(chan string)
|
||||||
result, err := p.goCompile(stop, []string{"echo", "test"})
|
result, err := p.goCompile(stop, []string{"echo"}, []string{"test"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("Unexpected", err)
|
t.Error("Unexpected", err)
|
||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
result, err = p.goCompile(stop, []string{"sleep", "20s"})
|
result, err = p.goCompile(stop, []string{"sleep"}, []string{"20s"})
|
||||||
response <- result
|
response <- result
|
||||||
}()
|
}()
|
||||||
close(stop)
|
close(stop)
|
||||||
|
|
Loading…
Reference in New Issue