This commit is contained in:
Alex Yatskov 2015-09-04 12:43:31 +09:00
parent c29b8b8200
commit 9bc09b72f5
2 changed files with 24 additions and 15 deletions

View File

@ -33,10 +33,9 @@ import (
)
type config struct {
Tasks map[string]task
Macros map[string]macro
Tasks map[string]*task
Macros map[string]*macro
handled map[string]bool
srcDir string
dstDir string
variant string
@ -49,7 +48,7 @@ func newConfig(filename string) (*config, error) {
return nil, err
}
conf := &config{handled: make(map[string]bool)}
conf := new(config)
switch path.Ext(filename) {
case ".json":
if err := json.Unmarshal(bytes, &conf); err != nil {

28
task.go
View File

@ -29,6 +29,8 @@ type task struct {
Links [][]string
Cmds [][]string
Envs [][]string
handled bool
}
func (t *task) process(conf *config) error {
@ -64,17 +66,25 @@ func (t *task) process(conf *config) error {
}
func processTask(taskName string, conf *config) error {
handled, ok := conf.handled[taskName]
if ok && handled {
var taskNames []string
if len(conf.variant) > 0 {
taskNames = append(taskNames, fmt.Sprint(taskName, "%", conf.variant))
}
taskNames = append(taskNames, taskName)
for _, tn := range taskNames {
t, ok := conf.Tasks[tn]
if !ok {
continue
}
if t.handled {
return nil
}
conf.handled[taskName] = true
t, ok := conf.Tasks[taskName]
if !ok {
return fmt.Errorf("task not found: %s", taskName)
}
t.handled = true
return t.process(conf)
}
return fmt.Errorf("task or variant not found: %s", taskName)
}