From e3ce6ada2b4a2416b695a61abcae2a0d9810228e Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Mon, 20 Jul 2015 14:11:49 +0900 Subject: [PATCH] Work in progress on envs and macros --- macro.go | 2 -- task.go | 31 ++++++++++++++++++++++++++----- 2 files changed, 26 insertions(+), 7 deletions(-) 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 {