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:
commit
162893daa2
|
@ -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()
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue