Break out of infinite config loops
This commit is contained in:
parent
cccb9b3903
commit
51513b24a2
@ -25,14 +25,17 @@ package main
|
|||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
type config struct {
|
type config struct {
|
||||||
Tasks map[string]task
|
Tasks map[string]task
|
||||||
|
tasksHandled map[string]bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *config) process(srcDir, dstDir, taskName string, flags int) error {
|
func (this *config) process(srcDir, dstDir, taskName string, flags int) error {
|
||||||
|
this.tasksHandled = make(map[string]bool)
|
||||||
|
|
||||||
task, ok := this.Tasks[taskName]
|
task, ok := this.Tasks[taskName]
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("task not found %s", taskName)
|
return fmt.Errorf("task not found %s", taskName)
|
||||||
}
|
}
|
||||||
|
|
||||||
return task.process(srcDir, dstDir, this, flags)
|
return task.process(taskName, srcDir, dstDir, this, flags)
|
||||||
}
|
}
|
||||||
|
11
task.go
11
task.go
@ -30,14 +30,21 @@ type task struct {
|
|||||||
Cmds []command
|
Cmds []command
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *task) process(srcDir, dstDir string, conf *config, flags int) error {
|
func (this *task) process(taskName, srcDir, dstDir string, conf *config, flags int) error {
|
||||||
|
handled, ok := conf.tasksHandled[taskName]
|
||||||
|
if ok && handled {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
conf.tasksHandled[taskName] = true
|
||||||
|
|
||||||
for _, depName := range this.Deps {
|
for _, depName := range this.Deps {
|
||||||
depTask, ok := conf.Tasks[depName]
|
depTask, ok := conf.Tasks[depName]
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("task dependency not found %s", depName)
|
return fmt.Errorf("task dependency not found %s", depName)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := depTask.process(srcDir, dstDir, conf, flags); err != nil {
|
if err := depTask.process(depName, srcDir, dstDir, conf, flags); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user