Parcourir la source

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
Chris Parsons il y a 4 ans
Parent
commit
26cdf135ff
2 fichiers modifiés avec 13 ajouts et 8 suppressions
  1. 10 6
      androidmk/androidmk/androidmk.go
  2. 3 2
      androidmk/cmd/androidmk.go

+ 10 - 6
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) {

+ 3 - 2
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)
 }