From 73d1b31466c16d0a13a220e5fad7cd8ef6d984d1 Mon Sep 17 00:00:00 2001 From: Daniel Jones Date: Tue, 24 Mar 2015 17:47:02 -0700 Subject: [PATCH] Add a '-q' option to not print recipes before executing. --- graph.go | 4 ++-- mk.go | 24 ++++++++++++++++++++---- recipe.go | 4 +--- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/graph.go b/graph.go index 44dbb34..9d0977c 100644 --- a/graph.go +++ b/graph.go @@ -322,11 +322,11 @@ func (g *graph) ambiguous(u *node) { } else { if !le.r.equivRecipe(e.r) { if le.r.ismeta && !e.r.ismeta { - mkPrintRecipe(u.name, le.r.recipe) + mkPrintRecipe(u.name, le.r.recipe, false) le.togo = true le = e } else if !le.r.ismeta && e.r.ismeta { - mkPrintRecipe(u.name, e.r.recipe) + mkPrintRecipe(u.name, e.r.recipe, false) e.togo = true continue } diff --git a/mk.go b/mk.go index b042967..915429a 100644 --- a/mk.go +++ b/mk.go @@ -273,7 +273,7 @@ func mkPrintMessage(msg string) { mkMsgMutex.Unlock() } -func mkPrintRecipe(target string, recipe string) { +func mkPrintRecipe(target string, recipe string, quiet bool) { mkMsgMutex.Lock() if nocolor { fmt.Printf("%s: ", target) @@ -282,9 +282,17 @@ func mkPrintRecipe(target string, recipe string) { ansiTermBlue+ansiTermBright+ansiTermUnderline, target, ansiTermDefault, ansiTermBlue) } - printIndented(os.Stdout, recipe, len(target)+3) - if len(recipe) == 0 { - os.Stdout.WriteString("\n") + if quiet { + if nocolor { + fmt.Println("...") + } else { + fmt.Println("…") + } + } else { + printIndented(os.Stdout, recipe, len(target)+3) + if len(recipe) == 0 { + os.Stdout.WriteString("\n") + } } if !nocolor { os.Stdout.WriteString(ansiTermDefault) @@ -297,6 +305,7 @@ func main() { var interactive bool var dryrun bool var shallowrebuild bool + var quiet bool flag.StringVar(&mkfilepath, "f", "mkfile", "use the given file as mkfile") flag.BoolVar(&dryrun, "n", false, "print commands without actually executing") @@ -304,6 +313,7 @@ func main() { flag.BoolVar(&rebuildall, "a", false, "force building of all dependencies") flag.IntVar(&subprocsAllowed, "p", 4, "maximum number of jobs to execute in parallel") flag.BoolVar(&interactive, "i", false, "prompt before executing rules") + flag.BoolVar(&quiet, "q", false, "don't print recipes before executing them") flag.Parse() mkfile, err := os.Open(mkfilepath) @@ -319,6 +329,12 @@ func main() { } rs := parse(string(input), mkfilepath, abspath) + if quiet { + for i := range rs.rules { + rs.rules[i].attributes.quiet = true + } + } + targets := flag.Args() // build the first non-meta rule in the makefile, if none are given explicitly diff --git a/recipe.go b/recipe.go index c4da3a0..27d9a31 100644 --- a/recipe.go +++ b/recipe.go @@ -97,9 +97,7 @@ func dorecipe(target string, u *node, e *edge, dryrun bool) bool { args = e.r.shell[1:] } - if !e.r.attributes.quiet { - mkPrintRecipe(target, input) - } + mkPrintRecipe(target, input, e.r.attributes.quiet) if dryrun { return true