mirror of
https://github.com/go-task/task.git
synced 2025-01-20 04:59:37 +02:00
func isUpToDate should be bound to Task struct
This commit is contained in:
parent
70ef9fbcfe
commit
f54dde4f78
20
status.go
20
status.go
@ -10,20 +10,20 @@ import (
|
||||
"github.com/mattn/go-zglob"
|
||||
)
|
||||
|
||||
func (e *Executor) isTaskUpToDate(ctx context.Context, t *Task) (bool, error) {
|
||||
func (t *Task) isUpToDate(ctx context.Context) (bool, error) {
|
||||
if len(t.Status) > 0 {
|
||||
return e.isUpToDateStatus(ctx, t)
|
||||
return t.isUpToDateStatus(ctx)
|
||||
}
|
||||
return e.isUpToDateTimestamp(ctx, t)
|
||||
return t.isUpToDateTimestamp(ctx)
|
||||
}
|
||||
|
||||
func (e *Executor) isUpToDateStatus(ctx context.Context, t *Task) (bool, error) {
|
||||
func (t *Task) isUpToDateStatus(ctx context.Context) (bool, error) {
|
||||
for _, s := range t.Status {
|
||||
err := execext.RunCommand(&execext.RunCommandOptions{
|
||||
Context: ctx,
|
||||
Command: s,
|
||||
Dir: e.getTaskDir(t),
|
||||
Env: e.getEnviron(t),
|
||||
Dir: t.Dir,
|
||||
Env: t.getEnviron(),
|
||||
})
|
||||
if err != nil {
|
||||
return false, nil
|
||||
@ -32,19 +32,17 @@ func (e *Executor) isUpToDateStatus(ctx context.Context, t *Task) (bool, error)
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (e *Executor) isUpToDateTimestamp(ctx context.Context, t *Task) (bool, error) {
|
||||
func (t *Task) isUpToDateTimestamp(ctx context.Context) (bool, error) {
|
||||
if len(t.Sources) == 0 || len(t.Generates) == 0 {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
dir := e.getTaskDir(t)
|
||||
|
||||
sourcesMaxTime, err := getPatternsMaxTime(dir, t.Sources)
|
||||
sourcesMaxTime, err := getPatternsMaxTime(t.Dir, t.Sources)
|
||||
if err != nil || sourcesMaxTime.IsZero() {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
generatesMinTime, err := getPatternsMinTime(dir, t.Generates)
|
||||
generatesMinTime, err := getPatternsMinTime(t.Dir, t.Generates)
|
||||
if err != nil || generatesMinTime.IsZero() {
|
||||
return false, nil
|
||||
}
|
||||
|
20
task.go
20
task.go
@ -6,7 +6,6 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
@ -124,7 +123,7 @@ func (e *Executor) RunTask(ctx context.Context, call Call) error {
|
||||
return err
|
||||
}
|
||||
|
||||
t, err := origTask.CompiledTask(vars)
|
||||
t, err := origTask.CompiledTask(e.Dir, vars)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -140,13 +139,13 @@ func (e *Executor) RunTask(ctx context.Context, call Call) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
t, err = origTask.CompiledTask(vars)
|
||||
t, err = origTask.CompiledTask(e.Dir, vars)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !e.Force {
|
||||
upToDate, err := e.isTaskUpToDate(ctx, t)
|
||||
upToDate, err := t.isUpToDate(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -188,8 +187,8 @@ func (e *Executor) runCommand(ctx context.Context, t *Task, call Call, i int) er
|
||||
opts := &execext.RunCommandOptions{
|
||||
Context: ctx,
|
||||
Command: cmd.Cmd,
|
||||
Dir: e.getTaskDir(t),
|
||||
Env: e.getEnviron(t),
|
||||
Dir: t.Dir,
|
||||
Env: t.getEnviron(),
|
||||
Stdin: e.Stdin,
|
||||
Stderr: e.Stderr,
|
||||
}
|
||||
@ -210,14 +209,7 @@ func (e *Executor) runCommand(ctx context.Context, t *Task, call Call, i int) er
|
||||
return execext.RunCommand(opts)
|
||||
}
|
||||
|
||||
func (e *Executor) getTaskDir(t *Task) string {
|
||||
if filepath.IsAbs(t.Dir) {
|
||||
return t.Dir
|
||||
}
|
||||
return filepath.Join(e.Dir, t.Dir)
|
||||
}
|
||||
|
||||
func (e *Executor) getEnviron(t *Task) []string {
|
||||
func (t *Task) getEnviron() []string {
|
||||
if t.Env == nil {
|
||||
return nil
|
||||
}
|
||||
|
@ -228,7 +228,7 @@ func (e *Executor) handleDynamicVariableContent(v Var) (string, error) {
|
||||
|
||||
// CompiledTask returns a copy of a task, but replacing
|
||||
// variables in almost all properties using the Go template package
|
||||
func (t *Task) CompiledTask(vars Vars) (*Task, error) {
|
||||
func (t *Task) CompiledTask(dir string, vars Vars) (*Task, error) {
|
||||
r := varReplacer{vars: vars}
|
||||
|
||||
new := Task{
|
||||
@ -242,6 +242,9 @@ func (t *Task) CompiledTask(vars Vars) (*Task, error) {
|
||||
Env: r.replaceVars(t.Env),
|
||||
Silent: t.Silent,
|
||||
}
|
||||
if dir != "" && !filepath.IsAbs(new.Dir) {
|
||||
new.Dir = filepath.Join(dir, new.Dir)
|
||||
}
|
||||
|
||||
if len(t.Cmds) > 0 {
|
||||
new.Cmds = make([]*Cmd, len(t.Cmds))
|
||||
|
Loading…
x
Reference in New Issue
Block a user