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"
)
type macro []string
type macroDef struct {
Prefix []string
Suffix []string

31
task.go
View File

@ -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 {