diff --git a/task.go b/task.go index 19caa2e7..2fe29bec 100644 --- a/task.go +++ b/task.go @@ -8,6 +8,7 @@ import ( "os" "path/filepath" "strings" + "sync" "github.com/go-task/task/execext" @@ -33,6 +34,9 @@ type Executor struct { taskvars Vars watchingFiles map[string]struct{} + + dynamicCache Vars + muDynamicCache sync.Mutex } // Vars is a string[string] variables map @@ -71,6 +75,10 @@ func (e *Executor) Run(args ...string) error { e.Stderr = os.Stderr } + if e.dynamicCache == nil { + e.dynamicCache = make(Vars, 10) + } + // check if given tasks exist for _, a := range args { if _, ok := e.Tasks[a]; !ok { diff --git a/variable_handling.go b/variable_handling.go index 8d18e671..493390b1 100644 --- a/variable_handling.go +++ b/variable_handling.go @@ -26,6 +26,12 @@ func (e *Executor) handleDynamicVariableContent(value string) (string, error) { return value, nil } + e.muDynamicCache.Lock() + defer e.muDynamicCache.Unlock() + if result, ok := e.dynamicCache[value]; ok { + return result, nil + } + buff := bytes.NewBuffer(nil) opts := &execext.RunCommandOptions{ @@ -46,6 +52,7 @@ func (e *Executor) handleDynamicVariableContent(value string) (string, error) { result = strings.TrimSpace(result) e.verbosePrintfln(`task: dynamic variable: "%s", result: "%s"`, value, result) + e.dynamicCache[value] = result return result, nil }