mirror of
https://github.com/go-task/task.git
synced 2024-12-12 10:45:49 +02:00
f98bf6c4b1
Maybe eventually help on #17
30 lines
587 B
Go
30 lines
587 B
Go
package task
|
|
|
|
// HasCyclicDep checks if a task tree has any cyclic dependency
|
|
func (e *Executor) HasCyclicDep() bool {
|
|
visits := make(map[string]struct{}, len(e.Tasks))
|
|
|
|
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 {
|
|
if !checkCyclicDep(d, e.Tasks[d]) {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
|
|
for k, v := range e.Tasks {
|
|
if !checkCyclicDep(k, v) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|