1
0
mirror of https://github.com/go-task/task.git synced 2025-02-07 13:41:53 +02:00

Allow interpolation on "generates" and "sources" attributes

Closes #26
This commit is contained in:
Andrey Nering 2017-04-30 19:32:28 -03:00
parent 8b76911675
commit b269c6e162
2 changed files with 38 additions and 10 deletions

35
task.go
View File

@ -95,9 +95,15 @@ func RunTask(ctx context.Context, name string) error {
return err
}
if !Force && t.isUpToDate() {
log.Printf(`task: Task "%s" is up to date`, name)
return nil
if !Force {
upToDate, err := t.isUpToDate()
if err != nil {
return err
}
if upToDate {
log.Printf(`task: Task "%s" is up to date`, name)
return nil
}
}
for i := range t.Cmds {
@ -133,22 +139,31 @@ func (t *Task) runDeps(ctx context.Context) error {
return nil
}
func (t *Task) isUpToDate() bool {
func (t *Task) isUpToDate() (bool, error) {
if len(t.Sources) == 0 || len(t.Generates) == 0 {
return false
return false, nil
}
sourcesMaxTime, err := getPatternsMaxTime(t.Sources)
sources, err := t.ReplaceSliceVariables(t.Sources)
if err != nil {
return false, err
}
generates, err := t.ReplaceSliceVariables(t.Generates)
if err != nil {
return false, err
}
sourcesMaxTime, err := getPatternsMaxTime(sources)
if err != nil || sourcesMaxTime.IsZero() {
return false
return false, nil
}
generatesMinTime, err := getPatternsMinTime(t.Generates)
generatesMinTime, err := getPatternsMinTime(generates)
if err != nil || generatesMinTime.IsZero() {
return false
return false, nil
}
return generatesMinTime.After(sourcesMaxTime)
return generatesMinTime.After(sourcesMaxTime), nil
}
func (t *Task) runCommand(ctx context.Context, i int) error {

View File

@ -99,6 +99,19 @@ func init() {
}
}
// ReplaceSliceVariables writes vars into initial string slice
func (t *Task) ReplaceSliceVariables(initials []string) ([]string, error) {
result := make([]string, len(initials))
for i, s := range initials {
var err error
result[i], err = t.ReplaceVariables(s)
if err != nil {
return nil, err
}
}
return result, nil
}
// ReplaceVariables writes vars into initial string
func (t *Task) ReplaceVariables(initial string) (string, error) {
vars, err := t.getVariables()