Work in progress on envs and macros

This commit is contained in:
Alex Yatskov 2015-07-20 14:11:49 +09:00
parent f35909340b
commit e3ce6ada2b
2 changed files with 26 additions and 7 deletions

View File

@ -21,8 +21,6 @@ import (
"strings" "strings"
) )
type macro []string
type macroDef struct { type macroDef struct {
Prefix []string Prefix []string
Suffix []string Suffix []string

31
task.go
View File

@ -22,15 +22,23 @@
package main package main
import "fmt" import (
"fmt"
"os"
"strings"
)
type taskDef struct { type taskDef struct {
Deps []string Deps []string
Links []link Links []link
Cmds []command Cmds []command
Macros []macro Macros []macro
Envs []env
} }
type macro []string
type env []string
func (t *taskDef) process(taskName, srcDir, dstDir string, conf *config, flags int) error { func (t *taskDef) process(taskName, srcDir, dstDir string, conf *config, flags int) error {
handled, ok := conf.tasksHandled[taskName] handled, ok := conf.tasksHandled[taskName]
if ok && handled { if ok && handled {
@ -50,14 +58,27 @@ func (t *taskDef) process(taskName, srcDir, dstDir string, conf *config, flags i
} }
} }
for _, envItems := range t.Envs {
switch {
case len(envItems) == 0:
continue
case len(envItems) == 1:
os.Unsetenv(envItems[0])
case len(envItems) == 2:
os.Setenv(envItems[0], envItems[1])
default:
os.Setenv(envItems[0], strings.Join(envItems[1:], ","))
}
}
if flags&flagNoMacro == 0 { if flags&flagNoMacro == 0 {
for _, macro := range t.Macros { for _, macroItems := range t.Macros {
if len(macro) == 0 { if len(macroItems) == 0 {
continue continue
} }
macroName := macro[0] macroName := macroItems[0]
macroParams := macro[1:] macroParams := macroItems[1:]
depMacro, ok := conf.Macros[macroName] depMacro, ok := conf.Macros[macroName]
if !ok { if !ok {