From c0c9ef996497250493bbe0f45b3ab71b831d071c Mon Sep 17 00:00:00 2001 From: Sasha Smundak Date: Wed, 23 Jan 2019 09:52:57 -0800 Subject: [PATCH] Provide an option to reduce build's verbosity. If ANDROID_QUIET_BUILD environment variable is set to '1', do not show 20 lines of the environment variables. In addition, for the failing step show only the step name and output, omitting the command proper (the verbose log as well as error.log still contains it). If build succeeds, the output of the build itself consists of a single line: ``` > m androidmk [100% NN/NN] ``` When it fails, the output does not contain sometimes very long command line: ``` > m androidmk [ 97% NN/MM] test androidmk FAILED: --- FAIL: TestEndToEnd (0.01s) androidmk_test.go:1025: failed testcase 'prebuilt_etc_TARGET_OUT_ETC' input: include $(CLEAR_VARS) LOCAL_MODULE := etc.test1 LOCAL_MODULE_CLASS := ETC LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)/foo/bar include $(BUILD_PREBUILT) expected: prebuilt_etc { name: "etc.test1", filename: "foo/bar", } got: prebuilt_etc { name: "etc.test1", filename: "foo/bar", } FAIL 17:50:53 ninja failed with: exit status 1 ``` [The related change in build/make/envsetup.sh suppresses timing display when the same variable is set.] Change-Id: I4d3c72457de031ff58a324c2fe98f4c1d10f8239 Test: treehugger --- cmd/multiproduct_kati/main.go | 6 ++++-- cmd/soong_ui/main.go | 3 ++- ui/build/dumpvars.go | 6 ++++-- ui/terminal/status.go | 15 ++++++++------- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/cmd/multiproduct_kati/main.go b/cmd/multiproduct_kati/main.go index 6a3d579bd..330c5dd27 100644 --- a/cmd/multiproduct_kati/main.go +++ b/cmd/multiproduct_kati/main.go @@ -172,7 +172,8 @@ func main() { stat := &status.Status{} defer stat.Finish() - stat.AddOutput(terminal.NewStatusOutput(writer, "")) + stat.AddOutput(terminal.NewStatusOutput(writer, "", + build.OsEnvironment().IsEnvTrue("ANDROID_QUIET_BUILD"))) var failures failureCount stat.AddOutput(&failures) @@ -389,7 +390,8 @@ func buildProduct(mpctx *mpContext, product string) { Thread: mpctx.Tracer.NewThread(product), Status: &status.Status{}, }} - ctx.Status.AddOutput(terminal.NewStatusOutput(ctx.Writer, "")) + ctx.Status.AddOutput(terminal.NewStatusOutput(ctx.Writer, "", + build.OsEnvironment().IsEnvTrue("ANDROID_QUIET_BUILD"))) config := build.NewConfig(ctx, flag.Args()...) config.Environment().Set("OUT_DIR", outDir) diff --git a/cmd/soong_ui/main.go b/cmd/soong_ui/main.go index 03803689e..d6999c570 100644 --- a/cmd/soong_ui/main.go +++ b/cmd/soong_ui/main.go @@ -78,7 +78,8 @@ func main() { stat := &status.Status{} defer stat.Finish() - stat.AddOutput(terminal.NewStatusOutput(writer, os.Getenv("NINJA_STATUS"))) + stat.AddOutput(terminal.NewStatusOutput(writer, os.Getenv("NINJA_STATUS"), + build.OsEnvironment().IsEnvTrue("ANDROID_QUIET_BUILD"))) stat.AddOutput(trace.StatusTracer()) build.SetupSignals(log, cancel, func() { diff --git a/ui/build/dumpvars.go b/ui/build/dumpvars.go index 98bb1c56d..d644f5ff7 100644 --- a/ui/build/dumpvars.go +++ b/ui/build/dumpvars.go @@ -214,11 +214,13 @@ func runMakeProductConfig(ctx Context, config Config) { ctx.Fatalln("Error dumping make vars:", err) } + env := config.Environment() // Print the banner like make does - ctx.Writer.Print(Banner(make_vars)) + if !env.IsEnvTrue("ANDROID_QUIET_BUILD") { + ctx.Writer.Print(Banner(make_vars)) + } // Populate the environment - env := config.Environment() for _, name := range exportEnvVars { if make_vars[name] == "" { env.Unset(name) diff --git a/ui/terminal/status.go b/ui/terminal/status.go index c8eb382fc..2445c5b2c 100644 --- a/ui/terminal/status.go +++ b/ui/terminal/status.go @@ -27,6 +27,7 @@ type statusOutput struct { format string start time.Time + quiet bool } // NewStatusOutput returns a StatusOutput that represents the @@ -35,12 +36,13 @@ type statusOutput struct { // // statusFormat takes nearly all the same options as NINJA_STATUS. // %c is currently unsupported. -func NewStatusOutput(w Writer, statusFormat string) status.StatusOutput { +func NewStatusOutput(w Writer, statusFormat string, quietBuild bool) status.StatusOutput { return &statusOutput{ writer: w, format: statusFormat, start: time.Now(), + quiet: quietBuild, } } @@ -76,13 +78,12 @@ func (s *statusOutput) FinishAction(result status.ActionResult, counts status.Co progress := s.progress(counts) + str if result.Error != nil { - hasCommand := "" - if result.Command != "" { - hasCommand = "\n" + targets := strings.Join(result.Outputs, " ") + if s.quiet || result.Command == "" { + s.writer.StatusAndMessage(progress, fmt.Sprintf("FAILED: %s\n%s", targets, result.Output)) + } else { + s.writer.StatusAndMessage(progress, fmt.Sprintf("FAILED: %s\n%s\n%s", targets, result.Command, result.Output)) } - - s.writer.StatusAndMessage(progress, fmt.Sprintf("FAILED: %s\n%s%s%s", - strings.Join(result.Outputs, " "), result.Command, hasCommand, result.Output)) } else if result.Output != "" { s.writer.StatusAndMessage(progress, result.Output) } else {