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

26
task.go
View File

@ -29,6 +29,8 @@ type task struct {
Links [][]string Links [][]string
Cmds [][]string Cmds [][]string
Envs [][]string Envs [][]string
handled bool
} }
func (t *task) process(conf *config) error { 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 { func processTask(taskName string, conf *config) error {
handled, ok := conf.handled[taskName] var taskNames []string
if ok && handled { 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 return nil
} }
conf.handled[taskName] = true t.handled = true
return t.process(conf)
t, ok := conf.Tasks[taskName]
if !ok {
return fmt.Errorf("task not found: %s", taskName)
} }
return t.process(conf) return fmt.Errorf("task or variant not found: %s", taskName)
} }