From 26cdf135ffbf445777942c0dd821bd6ac57095d4 Mon Sep 17 00:00:00 2001 From: Chris Parsons Date: Mon, 8 Jun 2020 18:17:26 -0400 Subject: [PATCH] When bpfix fails in androidmk, output the tree anyway This can help with debugging cases where the resulting blueprint file is invalid. Test: Manual run of androidmk Change-Id: I39605afa851aa6cdd8b49cc56386a8fc7347115c --- androidmk/androidmk/androidmk.go | 16 ++++++++++------ androidmk/cmd/androidmk.go | 5 +++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/androidmk/androidmk/androidmk.go b/androidmk/androidmk/androidmk.go index 9d0c3ac9f..4aadbe862 100644 --- a/androidmk/androidmk/androidmk.go +++ b/androidmk/androidmk/androidmk.go @@ -124,6 +124,7 @@ func ConvertFile(filename string, buffer *bytes.Buffer) (string, []error) { var conds []*conditional var assignmentCond *conditional + var tree *bpparser.File for _, node := range nodes { file.setMkPos(p.Unpack(node.Pos()), p.Unpack(node.End())) @@ -200,24 +201,27 @@ func ConvertFile(filename string, buffer *bytes.Buffer) (string, []error) { } } - tree := &bpparser.File{ + tree = &bpparser.File{ Defs: file.defs, Comments: file.comments, } // check for common supported but undesirable structures and clean them up fixer := bpfix.NewFixer(tree) - tree, err := fixer.Fix(bpfix.NewFixRequest().AddAll()) - if err != nil { - return "", []error{err} + fixedTree, fixerErr := fixer.Fix(bpfix.NewFixRequest().AddAll()) + if fixerErr != nil { + errs = append(errs, fixerErr) + } else { + tree = fixedTree } out, err := bpparser.Print(tree) if err != nil { - return "", []error{err} + errs = append(errs, err) + return "", errs } - return string(out), nil + return string(out), errs } func handleAssignment(file *bpFile, assignment *mkparser.Assignment, c *conditional) { diff --git a/androidmk/cmd/androidmk.go b/androidmk/cmd/androidmk.go index 00488eb9f..d2f4324e5 100644 --- a/androidmk/cmd/androidmk.go +++ b/androidmk/cmd/androidmk.go @@ -45,12 +45,13 @@ func main() { } output, errs := androidmk.ConvertFile(os.Args[1], bytes.NewBuffer(b)) + if len(output) > 0 { + fmt.Print(output) + } if len(errs) > 0 { for _, err := range errs { fmt.Fprintln(os.Stderr, "ERROR: ", err) } os.Exit(1) } - - fmt.Print(output) }