go fmt
This commit is contained in:
parent
ee70f46012
commit
8a218f35c0
6 changed files with 586 additions and 623 deletions
132
recipe.go
132
recipe.go
|
|
@ -1,19 +1,17 @@
|
|||
|
||||
// Various function for dealing with recipes.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"bufio"
|
||||
"fmt"
|
||||
"strings"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
||||
// Try to unindent a recipe, so that it begins an column 0. (This is mainly for
|
||||
// recipes in python, or other indentation-significant languages.)
|
||||
//func stripIndentation(s string) string {
|
||||
|
|
@ -22,78 +20,76 @@ import (
|
|||
|
||||
// Indent each line of a recipe.
|
||||
func printIndented(out io.Writer, s string) {
|
||||
reader := bufio.NewReader(strings.NewReader(s))
|
||||
for {
|
||||
line, err := reader.ReadString('\n')
|
||||
if len(line) > 0 {
|
||||
io.WriteString(out, " ")
|
||||
io.WriteString(out, line)
|
||||
}
|
||||
reader := bufio.NewReader(strings.NewReader(s))
|
||||
for {
|
||||
line, err := reader.ReadString('\n')
|
||||
if len(line) > 0 {
|
||||
io.WriteString(out, " ")
|
||||
io.WriteString(out, line)
|
||||
}
|
||||
|
||||
if (err != nil) {
|
||||
break
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Execute a recipe.
|
||||
func dorecipe(target string, u *node, e *edge) bool {
|
||||
vars := make(map[string][]string)
|
||||
vars["target"] = []string{target}
|
||||
if e.r.ismeta {
|
||||
if e.r.attributes.regex {
|
||||
for i := range e.matches {
|
||||
vars[fmt.Sprintf("stem%d", i)] = e.matches[i:i+1]
|
||||
}
|
||||
} else {
|
||||
vars["stem"] = []string{e.stem}
|
||||
}
|
||||
}
|
||||
vars := make(map[string][]string)
|
||||
vars["target"] = []string{target}
|
||||
if e.r.ismeta {
|
||||
if e.r.attributes.regex {
|
||||
for i := range e.matches {
|
||||
vars[fmt.Sprintf("stem%d", i)] = e.matches[i : i+1]
|
||||
}
|
||||
} else {
|
||||
vars["stem"] = []string{e.stem}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: other variables to set
|
||||
// alltargets
|
||||
// newprereq
|
||||
// TODO: other variables to set
|
||||
// alltargets
|
||||
// newprereq
|
||||
|
||||
prereqs := make([]string, 0)
|
||||
for i := range u.prereqs {
|
||||
if u.prereqs[i].r == e.r && u.prereqs[i].v != nil {
|
||||
prereqs = append(prereqs, u.prereqs[i].v.name)
|
||||
}
|
||||
}
|
||||
vars["prereqs"] = prereqs
|
||||
prereqs := make([]string, 0)
|
||||
for i := range u.prereqs {
|
||||
if u.prereqs[i].r == e.r && u.prereqs[i].v != nil {
|
||||
prereqs = append(prereqs, u.prereqs[i].v.name)
|
||||
}
|
||||
}
|
||||
vars["prereqs"] = prereqs
|
||||
|
||||
input := expandRecipeSigils(e.r.recipe, vars)
|
||||
sh := "sh"
|
||||
args := []string{}
|
||||
input := expandRecipeSigils(e.r.recipe, vars)
|
||||
sh := "sh"
|
||||
args := []string{}
|
||||
|
||||
if len(e.r.shell) > 0 {
|
||||
sh = e.r.shell[0]
|
||||
args = e.r.shell[1:]
|
||||
}
|
||||
if len(e.r.shell) > 0 {
|
||||
sh = e.r.shell[0]
|
||||
args = e.r.shell[1:]
|
||||
}
|
||||
|
||||
if !e.r.attributes.quiet {
|
||||
mkPrintRecipe(input)
|
||||
}
|
||||
if !e.r.attributes.quiet {
|
||||
mkPrintRecipe(input)
|
||||
}
|
||||
|
||||
if dryrun {
|
||||
return true
|
||||
}
|
||||
if dryrun {
|
||||
return true
|
||||
}
|
||||
|
||||
_, success := subprocess(
|
||||
sh,
|
||||
args,
|
||||
input,
|
||||
true,
|
||||
true,
|
||||
false)
|
||||
_, success := subprocess(
|
||||
sh,
|
||||
args,
|
||||
input,
|
||||
true,
|
||||
true,
|
||||
false)
|
||||
|
||||
// TODO: update the timestamps of each target
|
||||
|
||||
// TODO: update the timestamps of each target
|
||||
|
||||
return success
|
||||
return success
|
||||
}
|
||||
|
||||
|
||||
// A monolithic function for executing subprocesses
|
||||
func subprocess(program string,
|
||||
args []string,
|
||||
|
|
@ -136,15 +132,15 @@ func subprocess(program string,
|
|||
} else {
|
||||
err = cmd.Run()
|
||||
}
|
||||
success := true
|
||||
success := true
|
||||
|
||||
if err != nil {
|
||||
exiterr, ok := err.(*exec.ExitError)
|
||||
if ok {
|
||||
success = exiterr.ProcessState.Success()
|
||||
} else {
|
||||
log.Fatal(err)
|
||||
}
|
||||
exiterr, ok := err.(*exec.ExitError)
|
||||
if ok {
|
||||
success = exiterr.ProcessState.Success()
|
||||
} else {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
return output, success
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue