2018-02-17 14:22:18 -02:00
|
|
|
package taskfile
|
|
|
|
|
|
2019-06-10 17:40:20 +02:00
|
|
|
import "os"
|
|
|
|
|
import "sync"
|
|
|
|
|
|
2019-02-24 09:24:57 +01:00
|
|
|
// Tasks represents a group of tasks
|
2018-02-17 14:22:18 -02:00
|
|
|
type Tasks map[string]*Task
|
|
|
|
|
|
|
|
|
|
// Task represents a task
|
|
|
|
|
type Task struct {
|
2018-08-05 12:53:42 -03:00
|
|
|
Task string
|
|
|
|
|
Cmds []*Cmd
|
|
|
|
|
Deps []*Dep
|
|
|
|
|
Desc string
|
2019-02-24 15:37:02 +01:00
|
|
|
Summary string
|
2018-08-05 12:53:42 -03:00
|
|
|
Sources []string
|
|
|
|
|
Generates []string
|
|
|
|
|
Status []string
|
|
|
|
|
Dir string
|
2019-06-10 17:40:20 +02:00
|
|
|
mkdirMutex sync.Mutex
|
2018-08-05 12:53:42 -03:00
|
|
|
Vars Vars
|
|
|
|
|
Env Vars
|
|
|
|
|
Silent bool
|
|
|
|
|
Method string
|
|
|
|
|
Prefix string
|
|
|
|
|
IgnoreError bool `yaml:"ignore_error"`
|
2018-02-17 14:22:18 -02:00
|
|
|
}
|
2019-06-10 17:40:20 +02:00
|
|
|
|
|
|
|
|
// Mkdir creates the directory Task.Dir.
|
|
|
|
|
// Safe to be called concurrently.
|
|
|
|
|
func (t *Task) Mkdir() error {
|
|
|
|
|
if t.Dir == "" {
|
|
|
|
|
// No "dir:" attribute, so we do nothing.
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
t.mkdirMutex.Lock()
|
|
|
|
|
defer t.mkdirMutex.Unlock()
|
|
|
|
|
|
|
|
|
|
if _, err := os.Stat(t.Dir); os.IsNotExist(err) {
|
|
|
|
|
if err := os.MkdirAll(t.Dir, 0755); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|