Adding support for deps on macros
This commit is contained in:
parent
67a97669ca
commit
f8baa2051f
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +0,0 @@
|
||||
homemaker
|
53
command.go
53
command.go
@ -31,15 +31,40 @@ import (
|
||||
)
|
||||
|
||||
type macro struct {
|
||||
Deps []string
|
||||
Prefix []string
|
||||
Suffix []string
|
||||
}
|
||||
|
||||
func findCmdMacro(macroName string, conf *config) (*macro, string) {
|
||||
if strings.HasPrefix(macroName, "@") {
|
||||
mn := strings.TrimPrefix(macroName, "@")
|
||||
for _, mn := range makeVariantNames(mn, conf.variant) {
|
||||
if m, ok := conf.Macros[mn]; ok {
|
||||
return &m, mn
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil, ""
|
||||
}
|
||||
|
||||
func findCmdDeps(params []string, conf *config) []string {
|
||||
if len(params) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if m, _ := findCmdMacro(params[0], conf); m != nil {
|
||||
return m.Deps
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func processCmdMacro(macroName string, args []string, conf *config) error {
|
||||
for _, mn := range makeVariantNames(macroName, conf.variant) {
|
||||
m, ok := conf.Macros[mn]
|
||||
if !ok {
|
||||
continue
|
||||
m, mn := findCmdMacro(macroName, conf)
|
||||
if m == nil {
|
||||
return fmt.Errorf("macro or variant not found: %s", macroName)
|
||||
}
|
||||
|
||||
margs := appendExpEnv(nil, m.Prefix)
|
||||
@ -51,9 +76,6 @@ func processCmdMacro(macroName string, args []string, conf *config) error {
|
||||
}
|
||||
|
||||
return processCmd(margs, conf)
|
||||
}
|
||||
|
||||
return fmt.Errorf("macro or variant not found: %s", macroName)
|
||||
}
|
||||
|
||||
func processCmd(params []string, conf *config) error {
|
||||
@ -63,24 +85,15 @@ func processCmd(params []string, conf *config) error {
|
||||
}
|
||||
|
||||
cmdName := args[0]
|
||||
if strings.HasPrefix(cmdName, "@") {
|
||||
var (
|
||||
macroName = strings.TrimPrefix(cmdName, "@")
|
||||
macroArgs []string
|
||||
)
|
||||
|
||||
if len(args) > 1 {
|
||||
macroArgs = args[1:]
|
||||
}
|
||||
|
||||
return processCmdMacro(macroName, macroArgs, conf)
|
||||
}
|
||||
|
||||
var cmdArgs []string
|
||||
if len(args) > 1 {
|
||||
cmdArgs = args[1:]
|
||||
}
|
||||
|
||||
if strings.HasPrefix(cmdName, "@") {
|
||||
return processCmdMacro(cmdName, cmdArgs, conf)
|
||||
}
|
||||
|
||||
if conf.flags&flagVerbose != 0 {
|
||||
log.Printf("executing command: %s %s", cmdName, strings.Join(cmdArgs, " "))
|
||||
}
|
||||
|
14
task.go
14
task.go
@ -34,8 +34,20 @@ type task struct {
|
||||
Envs [][]string
|
||||
}
|
||||
|
||||
func (t *task) deps(conf *config) []string {
|
||||
deps := t.Deps
|
||||
|
||||
if conf.flags&flagNoCmds == 0 {
|
||||
for _, currCmd := range t.Cmds {
|
||||
deps = append(deps, findCmdDeps(currCmd, conf)...)
|
||||
}
|
||||
}
|
||||
|
||||
return deps
|
||||
}
|
||||
|
||||
func (t *task) process(conf *config) error {
|
||||
for _, currTask := range t.Deps {
|
||||
for _, currTask := range t.deps(conf) {
|
||||
if err := processTask(currTask, conf); err != nil {
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user