1
0
mirror of https://github.com/go-task/task.git synced 2025-06-15 00:15:10 +02:00

More sophisticated cyclic dependency detection

This commit is contained in:
Andrey Nering
2017-03-25 16:06:49 -03:00
parent 59306cda38
commit 36614dccf8
3 changed files with 69 additions and 15 deletions

20
task.go
View File

@ -21,9 +21,6 @@ var (
// Tasks constains the tasks parsed from Taskfile
Tasks = make(map[string]*Task)
runnedTasks = make(map[string]struct{})
mu sync.Mutex
)
// Task represents a task
@ -55,6 +52,10 @@ func Run() {
log.Fatal(err)
}
if HasCyclicDep(Tasks) {
log.Fatal("Cyclic dependency detected")
}
// check if given tasks exist
for _, a := range args {
if _, ok := Tasks[a]; !ok {
@ -74,18 +75,6 @@ func Run() {
// RunTask runs a task by its name
func RunTask(name string) error {
if strings.HasPrefix(name, "^") {
name = strings.TrimPrefix(name, "^")
} else {
mu.Lock()
if _, found := runnedTasks[name]; found {
mu.Unlock()
return &cyclicDepError{name}
}
runnedTasks[name] = struct{}{}
mu.Unlock()
}
t, ok := Tasks[name]
if !ok {
return &taskNotFoundError{name}
@ -180,6 +169,7 @@ func (t *Task) runCommand(i int) error {
}
if strings.HasPrefix(c, "^") {
c = strings.TrimPrefix(c, "^")
if err = RunTask(c); err != nil {
return err
}