From ea2e86e3983046d824c2a4c6b72ebee42502cc2a Mon Sep 17 00:00:00 2001 From: Sascha Andres Date: Thu, 2 Mar 2017 09:38:23 +0100 Subject: [PATCH 1/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} From 67e5c1eaf386073571f234ffec966b4305a7ba9d Mon Sep 17 00:00:00 2001 From: Sascha Andres Date: Thu, 2 Mar 2017 19:54:45 +0100 Subject: [PATCH 2/2] Added explantation to README --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index 9f78723e..fde5858a 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,19 @@ css: - npm run buildcss ``` +Each task can only be run once. If it is included from another dependend task causing +a cyclomatic dependency, execution will be stopped. + +```yml +task1: + deps: [task2] + +task2: + deps: [task1] +``` + +Will stop at the moment the dependencies of `task2` are executed. + ### Prevent task from running when not necessary If a task generates something, you can inform Task the source and generated