diff --git a/macro.go b/macro.go index b27e441..10911d4 100644 --- a/macro.go +++ b/macro.go @@ -21,8 +21,6 @@ import ( "strings" ) -type macro []string - type macroDef struct { Prefix []string Suffix []string diff --git a/task.go b/task.go index 18c5c71..077ac3e 100644 --- a/task.go +++ b/task.go @@ -22,15 +22,23 @@ package main -import "fmt" +import ( + "fmt" + "os" + "strings" +) type taskDef struct { Deps []string Links []link Cmds []command Macros []macro + Envs []env } +type macro []string +type env []string + func (t *taskDef) process(taskName, srcDir, dstDir string, conf *config, flags int) error { handled, ok := conf.tasksHandled[taskName] 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 { - for _, macro := range t.Macros { - if len(macro) == 0 { + for _, macroItems := range t.Macros { + if len(macroItems) == 0 { continue } - macroName := macro[0] - macroParams := macro[1:] + macroName := macroItems[0] + macroParams := macroItems[1:] depMacro, ok := conf.Macros[macroName] if !ok {