Merge pull request #203 from tapocol/multiple_projects_same_env

Allow multiple projects to have different values for same env var
This commit is contained in:
Alessio Pracchia 2018-08-23 11:38:39 +02:00 committed by GitHub
commit 162893daa2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 18 deletions

View File

@ -116,12 +116,6 @@ func (p *Project) Before() {
}
// setup go tools
p.Tools.Setup()
// set env const
for key, item := range p.Env {
if err := os.Setenv(key, item); err != nil {
p.Buffer.StdErr = append(p.Buffer.StdErr, BufferOut{Time: time.Now(), Text: err.Error(), Type: "Env error", Stream: ""})
}
}
// global commands before
p.cmd(p.stop, "before", true)
// indexing files and dirs
@ -563,6 +557,13 @@ func (p *Project) stamp(t string, o BufferOut, msg string, stream string) {
}()
}
func (p Project) buildEnvs() (envs []string) {
for k, v := range p.Env {
envs = append(envs, fmt.Sprintf("%s=%s", strings.Replace(k, "=", "", -1), v))
}
return
}
// Run a project
func (p *Project) run(path string, stream chan Response, stop <-chan bool) (err error) {
var args []string
@ -625,6 +626,10 @@ func (p *Project) run(path string, stream chan Response, stop <-chan bool) (err
return errors.New("project not found")
}
}
appendEnvs := p.buildEnvs()
if len(appendEnvs) > 0 {
build.Env = append(build.Env, appendEnvs...)
}
// scan project stream
stdout, err := build.StdoutPipe()
stderr, err := build.StderrPipe()

View File

@ -44,18 +44,6 @@ func TestProject_Before(t *testing.T) {
if !strings.Contains(buf.String(), input) {
t.Error("Unexpected error")
}
r = Realize{}
r.Projects = append(r.Projects, Project{
parent: &r,
Env: map[string]string{
input: input,
},
})
r.Projects[0].Before()
if os.Getenv(input) != input {
t.Error("Unexpected error expected", input, "instead", os.Getenv(input))
}
}
func TestProject_Err(t *testing.T) {