build/install performance improved
This commit is contained in:
parent
2cf9aab133
commit
6f6175e7dd
|
@ -9,6 +9,7 @@ import (
|
|||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
"errors"
|
||||
)
|
||||
|
||||
// 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 {
|
||||
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
|
||||
defer func() {
|
||||
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()
|
||||
if err != nil {
|
||||
Fail(err.Error())
|
||||
return err
|
||||
}
|
||||
if err := build.Start(); err != nil {
|
||||
Fail(err.Error())
|
||||
return err
|
||||
}
|
||||
close(runner)
|
||||
|
||||
|
@ -86,8 +89,8 @@ func (p *Project) GoBuild() error {
|
|||
return err
|
||||
}
|
||||
}
|
||||
build := exec.Command("go", "build", p.base+p.Main)
|
||||
build.Dir = p.base + "/bin"
|
||||
build := exec.Command("go", "build")
|
||||
build.Dir = p.base
|
||||
build.Stdout = &out
|
||||
if err := build.Run(); err != nil {
|
||||
return err
|
||||
|
@ -101,6 +104,16 @@ func (p *Project) GoInstall() error {
|
|||
base, _ := os.Getwd()
|
||||
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.Dir = path
|
||||
build.Stdout = &out
|
||||
|
|
|
@ -110,6 +110,7 @@ func (p *Project) Watching() {
|
|||
}
|
||||
if _, err := os.Stat(event.Name); err == nil {
|
||||
i := strings.Index(event.Name, filepath.Ext(event.Name))
|
||||
if event.Name[:i] != "" {
|
||||
log.Println(bluel(p.Name + ": File changed ->"), bluel(event.Name[:i]))
|
||||
|
||||
// stop and run again
|
||||
|
@ -120,6 +121,7 @@ func (p *Project) Watching() {
|
|||
p.reload = time.Now().Truncate(time.Second)
|
||||
}
|
||||
}
|
||||
}
|
||||
case err := <-watcher.Errors:
|
||||
Fail(err.Error())
|
||||
}
|
||||
|
@ -131,7 +133,7 @@ func (p *Project) install(channel chan bool,wr *sync.WaitGroup) {
|
|||
if p.Bin {
|
||||
LogSuccess(p.Name + ": Installing..")
|
||||
if err := p.GoInstall(); err != nil {
|
||||
Fail(err.Error())
|
||||
Fail(p.Name + ": "+err.Error())
|
||||
wr.Done()
|
||||
} else {
|
||||
LogSuccess(p.Name + ": Installed")
|
||||
|
@ -157,7 +159,7 @@ func (p *Project) build() {
|
|||
if p.Build {
|
||||
LogSuccess(p.Name + ": Building..")
|
||||
if err := p.GoBuild(); err != nil {
|
||||
Fail(err.Error())
|
||||
Fail(p.Name + ": "+err.Error())
|
||||
} else {
|
||||
LogSuccess(p.Name + ": Builded")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue