diff --git a/requires.go b/requires.go index 2aeec430..a31b0adc 100644 --- a/requires.go +++ b/requires.go @@ -17,19 +17,13 @@ func (e *Executor) collectAllRequiredVars(calls []*Call) ([]*ast.VarsWithValidat var collect func(call *Call) error collect = func(call *Call) error { - // Avoid infinite loops - if visited[call.Task] { - return nil - } - visited[call.Task] = true - - // Compile to resolve variables (also fetches the task) + // Always compile to resolve variables (also fetches the task) compiledTask, err := e.FastCompiledTask(call) if err != nil { return err } - // Collect required vars from this task + // Always collect required vars from this task if compiledTask.Requires != nil { for _, v := range compiledTask.Requires.Vars { // Check if var is already set @@ -42,6 +36,13 @@ func (e *Executor) collectAllRequiredVars(calls []*Call) ([]*ast.VarsWithValidat } } + // Only skip recursion if already visited (to avoid infinite loops) + // We already collected the vars above, so we're good + if visited[call.Task] { + return nil + } + visited[call.Task] = true + // Recurse into deps for _, dep := range compiledTask.Deps { depCall := &Call{ diff --git a/testdata/interactive_vars/Taskfile.yml b/testdata/interactive_vars/Taskfile.yml index d26dfdc4..a269a4e2 100644 --- a/testdata/interactive_vars/Taskfile.yml +++ b/testdata/interactive_vars/Taskfile.yml @@ -1,66 +1,27 @@ version: "3" +# Test case for the visited bug: +# - build is called twice with different vars +# - First call provides TARGET, second doesn't +# - BUG: we should prompt for TARGET but we don't + tasks: main: - desc: Main task with nested deps + desc: Main task that calls build twice with different vars deps: - - dep-a - - dep-b + - task: build + - task: build cmds: - - echo "Main task done!" + - echo "Main done" - dep-a: - desc: Dependency A - deps: - - leaf-a1 - - leaf-a2 - cmds: - - echo "Dep A done" - - dep-b: - desc: Dependency B - deps: - - leaf-b1 - - leaf-b2 - cmds: - - echo "Dep B done" - - leaf-a1: - desc: Leaf A1 with enum + build: + desc: Build task requiring TARGET requires: vars: - - name: VAR_A1 + - name: TARGET enum: - - alpha - - beta - - gamma + - linux + - windows + - darwin cmds: - - echo "Leaf A1 {{.VAR_A1}}" - - leaf-a2: - desc: Leaf A2 with text - requires: - vars: - - VAR_A2 - cmds: - - echo "Leaf A2 {{.VAR_A2}}" - - leaf-b1: - desc: Leaf B1 with enum - requires: - vars: - - name: VAR_B1 - enum: - - one - - two - - three - cmds: - - echo "Leaf B1 {{.VAR_B1}}" - - leaf-b2: - desc: Leaf B2 with text - requires: - vars: - - VAR_B2 - cmds: - - echo "Leaf B2 {{.VAR_B2}}" + - echo "Building for target = {{.TARGET}} (mode={{.MODE}})"