Support multiple values in GOPATH/GOBIN

realize generates wrong GOBIN path in case one has multiple paths in
GOPATH (like "/go/foo:/go").
This commit is contained in:
Janis Meybohm 2017-06-19 11:29:30 +02:00
parent df9c72155c
commit 979cb3da36
2 changed files with 17 additions and 5 deletions

View File

@ -34,10 +34,10 @@ func (p *Project) goRun(channel chan bool, runner chan bool, wr *sync.WaitGroup)
if path != "" {
build = exec.Command(path, params...)
} else {
if _, err := os.Stat(filepath.Join(os.Getenv("GOBIN"), filepath.Base(p.path))); err == nil {
build = exec.Command(filepath.Join(os.Getenv("GOBIN"), filepath.Base(p.path)), params...)
} else if _, err := os.Stat(filepath.Join(os.Getenv("GOBIN"), filepath.Base(p.path)) + ".exe"); err == nil {
build = exec.Command(filepath.Join(os.Getenv("GOBIN"), filepath.Base(p.path))+".exe", params...)
if _, err := os.Stat(filepath.Join(getEnvPath("GOBIN"), filepath.Base(p.path))); err == nil {
build = exec.Command(filepath.Join(getEnvPath("GOBIN"), filepath.Base(p.path)), params...)
} else if _, err := os.Stat(filepath.Join(getEnvPath("GOBIN"), filepath.Base(p.path)) + ".exe"); err == nil {
build = exec.Command(filepath.Join(getEnvPath("GOBIN"), filepath.Base(p.path))+".exe", params...)
} else {
p.Buffer.StdLog = append(p.Buffer.StdLog, BufferOut{Time: time.Now(), Text: "Can't run a not compiled project"})
p.Fatal(err, "Can't run a not compiled project", ":")
@ -116,7 +116,7 @@ func (p *Project) goBuild() (string, error) {
func (p *Project) goInstall() (string, error) {
var out bytes.Buffer
var stderr bytes.Buffer
err := os.Setenv("GOBIN", filepath.Join(os.Getenv("GOPATH"), "bin"))
err := os.Setenv("GOBIN", filepath.Join(getEnvPath("GOPATH"), "bin"))
if err != nil {
return "", err
}

View File

@ -3,6 +3,8 @@ package watcher
import (
"errors"
"fmt"
"os"
"path/filepath"
"time"
"github.com/tockins/realize/style"
@ -46,3 +48,13 @@ func inArray(str string, list []string) bool {
func (w logWriter) Write(bytes []byte) (int, error) {
return fmt.Print(style.Yellow.Regular("[") + time.Now().Format("15:04:05") + style.Yellow.Regular("]") + string(bytes))
}
// getEnvPath returns the first path found in env or empty string
func getEnvPath(env string) string {
path := filepath.SplitList(os.Getenv(env))
if len(path) == 0 {
return ""
} else {
return path[0]
}
}