From 1576943702a14d63e4c33665d40c8d6aae2c262c Mon Sep 17 00:00:00 2001 From: Sascha Andres Date: Wed, 1 Mar 2017 14:33:10 +0100 Subject: [PATCH 1/2] Changed minor code style --- task.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/task.go b/task.go index 7a58de37..ceb70e5f 100644 --- a/task.go +++ b/task.go @@ -40,7 +40,7 @@ type Task struct { Deps []string Sources []string Generates []string - Chdir string + Dir string } type taskNotFoundError struct { @@ -101,7 +101,7 @@ func RunTask(name string) error { } for _, c := range t.Cmds { - if err := runCommand(c, t.Chdir); err != nil { + if err := runCommand(c, t.Dir); err != nil { return &taskRunError{name, err} } } @@ -133,7 +133,7 @@ func runCommand(c, path string) error { } else { cmd = exec.Command("cmd", "/C", c) } - if "" != path { + if path != "" { cmd.Dir = path } cmd.Stdout = os.Stdout From ea2e86e3983046d824c2a4c6b72ebee42502cc2a Mon Sep 17 00:00:00 2001 From: Sascha Andres Date: Thu, 2 Mar 2017 09:38:23 +0100 Subject: [PATCH 2/2] Simple cyclic dependency detection --- task.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/task.go b/task.go index ceb70e5f..e0eab8db 100644 --- a/task.go +++ b/task.go @@ -23,6 +23,8 @@ var ( // Tasks constains the tasks parsed from Taskfile Tasks = make(map[string]*Task) + + runTasks = make(map[string]bool) ) func init() { @@ -84,6 +86,11 @@ func Run() { // RunTask runs a task by its name func RunTask(name string) error { + if _, found := runTasks[name]; found { + return &taskRunError{taskName: name, err: fmt.Errorf("Cyclic dependency detected")} + } + runTasks[name] = true + t, ok := Tasks[name] if !ok { return &taskNotFoundError{name}