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
This commit is contained in:
Chris Parsons 2020-06-08 18:17:26 -04:00
parent 4f3dc39a47
commit 26cdf135ff
2 changed files with 13 additions and 8 deletions

View File

@ -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) {

View File

@ -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)
}