2017-03-25 21:06:49 +02:00
|
|
|
package task
|
|
|
|
|
2017-04-24 15:25:38 +02:00
|
|
|
// HasCyclicDep checks if a task tree has any cyclic dependency
|
2017-06-04 21:02:04 +02:00
|
|
|
func (e *Executor) HasCyclicDep() bool {
|
|
|
|
visits := make(map[string]struct{}, len(e.Tasks))
|
2017-03-25 21:06:49 +02:00
|
|
|
|
|
|
|
var checkCyclicDep func(string, *Task) bool
|
|
|
|
checkCyclicDep = func(name string, t *Task) bool {
|
|
|
|
if _, ok := visits[name]; ok {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
visits[name] = struct{}{}
|
|
|
|
defer delete(visits, name)
|
|
|
|
|
|
|
|
for _, d := range t.Deps {
|
2017-07-02 20:30:50 +02:00
|
|
|
if !checkCyclicDep(d.Task, e.Tasks[d.Task]) {
|
2017-03-25 21:06:49 +02:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2017-06-04 21:02:04 +02:00
|
|
|
for k, v := range e.Tasks {
|
2017-03-25 21:06:49 +02:00
|
|
|
if !checkCyclicDep(k, v) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|