build/install performance improved
This commit is contained in:
parent
2cf9aab133
commit
6f6175e7dd
|
@ -9,6 +9,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
"errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
// The Project struct defines the informations about a project
|
// The Project struct defines the informations about a project
|
||||||
|
@ -36,7 +37,7 @@ func (p *Project) GoRun(channel chan bool, runner chan bool, wr *sync.WaitGroup)
|
||||||
}else {
|
}else {
|
||||||
run = name[len(name)-1]
|
run = name[len(name)-1]
|
||||||
}
|
}
|
||||||
build := exec.Command(os.Getenv("GOPATH") + slash("bin") + slash(run))
|
build := exec.Command(os.Getenv("GOBIN") + slash(run))
|
||||||
build.Dir = p.base
|
build.Dir = p.base
|
||||||
defer func() {
|
defer func() {
|
||||||
if err := build.Process.Kill(); err != nil {
|
if err := build.Process.Kill(); err != nil {
|
||||||
|
@ -49,9 +50,11 @@ func (p *Project) GoRun(channel chan bool, runner chan bool, wr *sync.WaitGroup)
|
||||||
stdout, err := build.StdoutPipe()
|
stdout, err := build.StdoutPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Fail(err.Error())
|
Fail(err.Error())
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
if err := build.Start(); err != nil {
|
if err := build.Start(); err != nil {
|
||||||
Fail(err.Error())
|
Fail(err.Error())
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
close(runner)
|
close(runner)
|
||||||
|
|
||||||
|
@ -86,8 +89,8 @@ func (p *Project) GoBuild() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
build := exec.Command("go", "build", p.base+p.Main)
|
build := exec.Command("go", "build")
|
||||||
build.Dir = p.base + "/bin"
|
build.Dir = p.base
|
||||||
build.Stdout = &out
|
build.Stdout = &out
|
||||||
if err := build.Run(); err != nil {
|
if err := build.Run(); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -101,6 +104,16 @@ func (p *Project) GoInstall() error {
|
||||||
base, _ := os.Getwd()
|
base, _ := os.Getwd()
|
||||||
path := base + p.Path
|
path := base + p.Path
|
||||||
|
|
||||||
|
// check gopath and set gobin
|
||||||
|
gopath := os.Getenv("GOPATH")
|
||||||
|
if gopath == ""{
|
||||||
|
return errors.New("$GOPATH not set")
|
||||||
|
}
|
||||||
|
err := os.Setenv("GOBIN",os.Getenv("GOPATH") + "bin")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
build := exec.Command("go", "install")
|
build := exec.Command("go", "install")
|
||||||
build.Dir = path
|
build.Dir = path
|
||||||
build.Stdout = &out
|
build.Stdout = &out
|
||||||
|
|
|
@ -110,7 +110,8 @@ func (p *Project) Watching() {
|
||||||
}
|
}
|
||||||
if _, err := os.Stat(event.Name); err == nil {
|
if _, err := os.Stat(event.Name); err == nil {
|
||||||
i := strings.Index(event.Name, filepath.Ext(event.Name))
|
i := strings.Index(event.Name, filepath.Ext(event.Name))
|
||||||
log.Println(bluel(p.Name+": File changed ->"), bluel(event.Name[:i]))
|
if event.Name[:i] != "" {
|
||||||
|
log.Println(bluel(p.Name + ": File changed ->"), bluel(event.Name[:i]))
|
||||||
|
|
||||||
// stop and run again
|
// stop and run again
|
||||||
close(channel)
|
close(channel)
|
||||||
|
@ -120,6 +121,7 @@ func (p *Project) Watching() {
|
||||||
p.reload = time.Now().Truncate(time.Second)
|
p.reload = time.Now().Truncate(time.Second)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
case err := <-watcher.Errors:
|
case err := <-watcher.Errors:
|
||||||
Fail(err.Error())
|
Fail(err.Error())
|
||||||
}
|
}
|
||||||
|
@ -131,7 +133,7 @@ func (p *Project) install(channel chan bool,wr *sync.WaitGroup) {
|
||||||
if p.Bin {
|
if p.Bin {
|
||||||
LogSuccess(p.Name + ": Installing..")
|
LogSuccess(p.Name + ": Installing..")
|
||||||
if err := p.GoInstall(); err != nil {
|
if err := p.GoInstall(); err != nil {
|
||||||
Fail(err.Error())
|
Fail(p.Name + ": "+err.Error())
|
||||||
wr.Done()
|
wr.Done()
|
||||||
} else {
|
} else {
|
||||||
LogSuccess(p.Name + ": Installed")
|
LogSuccess(p.Name + ": Installed")
|
||||||
|
@ -157,7 +159,7 @@ func (p *Project) build() {
|
||||||
if p.Build {
|
if p.Build {
|
||||||
LogSuccess(p.Name + ": Building..")
|
LogSuccess(p.Name + ": Building..")
|
||||||
if err := p.GoBuild(); err != nil {
|
if err := p.GoBuild(); err != nil {
|
||||||
Fail(err.Error())
|
Fail(p.Name + ": "+err.Error())
|
||||||
} else {
|
} else {
|
||||||
LogSuccess(p.Name + ": Builded")
|
LogSuccess(p.Name + ": Builded")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue