From df04879771917bbe93632a1522f7f0f751ef2d52 Mon Sep 17 00:00:00 2001 From: Valentin Maerten Date: Sun, 9 Feb 2025 20:03:36 +0100 Subject: [PATCH] refactor: VeryFastCompile for Task list --- task.go | 2 +- variables.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/task.go b/task.go index c86391976a..ac337599c8 100644 --- a/task.go +++ b/task.go @@ -527,7 +527,7 @@ func (e *Executor) GetTaskList(filters ...FilterFunc) ([]*ast.Task, error) { // Compile the list of tasks for i := range tasks { g.Go(func() error { - compiledTask, err := e.FastCompiledTask(&ast.Call{Task: tasks[i].Task}) + compiledTask, err := e.CompiledTaskForTaskList(&ast.Call{Task: tasks[i].Task}) if err != nil { return err } diff --git a/variables.go b/variables.go index e515aea6e0..e142ac665f 100644 --- a/variables.go +++ b/variables.go @@ -27,6 +27,51 @@ func (e *Executor) FastCompiledTask(call *ast.Call) (*ast.Task, error) { return e.compiledTask(call, false) } +func (e *Executor) CompiledTaskForTaskList(call *ast.Call) (*ast.Task, error) { + origTask, err := e.GetTask(call) + if err != nil { + return nil, err + } + + vars, err := e.Compiler.FastGetVariables(origTask, call) + if err != nil { + return nil, err + } + + cache := &templater.Cache{Vars: vars} + + return &ast.Task{ + Task: origTask.Task, + Label: templater.Replace(origTask.Label, cache), + Desc: templater.Replace(origTask.Desc, cache), + Prompt: templater.Replace(origTask.Prompt, cache), + Summary: templater.Replace(origTask.Summary, cache), + Aliases: origTask.Aliases, + Sources: origTask.Sources, + Generates: origTask.Generates, + Dir: origTask.Dir, + Set: origTask.Set, + Shopt: origTask.Shopt, + Vars: vars, + Env: nil, + Dotenv: origTask.Dotenv, + Silent: origTask.Silent, + Interactive: origTask.Interactive, + Internal: origTask.Internal, + Method: origTask.Method, + Prefix: origTask.Prefix, + IgnoreError: origTask.IgnoreError, + Run: origTask.Run, + IncludeVars: origTask.IncludeVars, + IncludedTaskfileVars: origTask.IncludedTaskfileVars, + Platforms: origTask.Platforms, + Location: origTask.Location, + Requires: origTask.Requires, + Watch: origTask.Watch, + Namespace: origTask.Namespace, + }, nil +} + func (e *Executor) compiledTask(call *ast.Call, evaluateShVars bool) (*ast.Task, error) { origTask, err := e.GetTask(call) if err != nil {