feat: support for loops with generates (#2151)

This commit is contained in:
Artem Sedykh
2025-04-06 01:55:43 +03:00
committed by GitHub
parent a9de239e38
commit 6f0f38b8d9
11 changed files with 113 additions and 3 deletions

View File

@@ -153,7 +153,7 @@ func (e *Executor) compiledTask(call *Call, evaluateShVars bool) (*ast.Task, err
continue
}
if cmd.For != nil {
list, keys, err := itemsFromFor(cmd.For, new.Dir, new.Sources, vars, origTask.Location, cache)
list, keys, err := itemsFromFor(cmd.For, new.Dir, new.Sources, new.Generates, vars, origTask.Location, cache)
if err != nil {
return nil, err
}
@@ -200,7 +200,7 @@ func (e *Executor) compiledTask(call *Call, evaluateShVars bool) (*ast.Task, err
continue
}
if dep.For != nil {
list, keys, err := itemsFromFor(dep.For, new.Dir, new.Sources, vars, origTask.Location, cache)
list, keys, err := itemsFromFor(dep.For, new.Dir, new.Sources, new.Generates, vars, origTask.Location, cache)
if err != nil {
return nil, err
}
@@ -270,6 +270,7 @@ func itemsFromFor(
f *ast.For,
dir string,
sources []*ast.Glob,
generates []*ast.Glob,
vars *ast.Vars,
location *ast.Location,
cache *templater.Cache,
@@ -304,6 +305,20 @@ func itemsFromFor(
}
values = asAnySlice(glist)
}
// Get the list from the task generates
if f.From == "generates" {
glist, err := fingerprint.Globs(dir, generates)
if err != nil {
return nil, nil, err
}
// Make the paths relative to the task dir
for i, v := range glist {
if glist[i], err = filepath.Rel(dir, v); err != nil {
return nil, nil, err
}
}
values = asAnySlice(glist)
}
// Get the list from a variable and split it up
if f.Var != "" {
if vars != nil {