From 36b5e31f62fdc992af52cf5769b52a964f636cc6 Mon Sep 17 00:00:00 2001 From: Patrice Arruda Date: Wed, 11 Mar 2020 12:41:47 -0700 Subject: [PATCH] Do not write build_error proto file if there are no build errors. For successful builds, a blank build_error proto file is created. This slows down the data processing part where it reads the build_error file and there are no errors to be processed. Bug: 142277430 Test: Did a successful build and checked if the build_error file was not available. Changed a source file to make the build failed and checked if the build_error file was available. Change-Id: I300dffe32fb7f8bf984fa20ae368bdd02bf12992 --- ui/status/log.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ui/status/log.go b/ui/status/log.go index d40724809..1ded9ca46 100644 --- a/ui/status/log.go +++ b/ui/status/log.go @@ -20,6 +20,7 @@ import ( "fmt" "io" "io/ioutil" + "os" "strings" "github.com/golang/protobuf/proto" @@ -154,6 +155,7 @@ type errorProtoLog struct { } func NewProtoErrorLog(log logger.Logger, filename string) StatusOutput { + os.Remove(filename) return &errorProtoLog{ errorProto: soong_build_error_proto.BuildError{}, filename: filename, @@ -178,11 +180,17 @@ func (e *errorProtoLog) FinishAction(result ActionResult, counts Counts) { } func (e *errorProtoLog) Flush() { + // Don't create the build error proto file if there is action errors. + if len(e.errorProto.ActionErrors) == 0 { + return + } + data, err := proto.Marshal(&e.errorProto) if err != nil { e.log.Printf("Failed to marshal build status proto: %v\n", err) return } + err = ioutil.WriteFile(e.filename, []byte(data), 0644) if err != nil { e.log.Printf("Failed to write file %s: %v\n", e.filename, err)