From 26478b7fc5ef6d0d0c6ceca6f6c71f100a1fdc72 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Mon, 29 Jun 2015 13:46:00 -0700 Subject: [PATCH] Remove comments from translated Android.mk files A bad recommendation from me lead to structuring the androidbp code in a way that can't handle comments interspersed with module definitions. Since the translated Android.mk files don't really need to be human readable, just strip all the comments. Change-Id: I23e3f1860730bcb43b5e00a305267aa426ed80aa --- androidbp/cmd/androidbp.go | 61 ++++---------------------------------- 1 file changed, 5 insertions(+), 56 deletions(-) diff --git a/androidbp/cmd/androidbp.go b/androidbp/cmd/androidbp.go index a8f4580c3..19a9328e4 100644 --- a/androidbp/cmd/androidbp.go +++ b/androidbp/cmd/androidbp.go @@ -233,12 +233,6 @@ func (w *androidMkWriter) lookupMap(parent bpparser.Value) (mapValue []*bpparser return } -func (w *androidMkWriter) handleComment(comment *bpparser.Comment) { - for _, c := range comment.Comment { - fmt.Fprintf(w, "#%s\n", c) - } -} - func (w *androidMkWriter) writeModule(moduleRule string, props []string, disabledBuilds map[string]bool, isHostRule bool) { disabledConditionals := disabledTargetConditionals @@ -345,47 +339,6 @@ func (w *androidMkWriter) handleAssignment(assignment *bpparser.Assignment) { } } -func (w *androidMkWriter) iter() <-chan interface{} { - ch := make(chan interface{}, len(w.blueprint.Comments)+len(w.blueprint.Defs)) - go func() { - commIdx := 0 - defsIdx := 0 - for defsIdx < len(w.blueprint.Defs) || commIdx < len(w.blueprint.Comments) { - if defsIdx == len(w.blueprint.Defs) { - ch <- w.blueprint.Comments[commIdx] - commIdx++ - } else if commIdx == len(w.blueprint.Comments) { - ch <- w.blueprint.Defs[defsIdx] - defsIdx++ - } else { - commentsPos := 0 - defsPos := 0 - - def := w.blueprint.Defs[defsIdx] - switch def := def.(type) { - case *bpparser.Module: - defsPos = def.LbracePos.Line - case *bpparser.Assignment: - defsPos = def.Pos.Line - } - - comment := w.blueprint.Comments[commIdx] - commentsPos = comment.Pos.Line - - if commentsPos < defsPos { - commIdx++ - ch <- comment - } else { - defsIdx++ - ch <- def - } - } - } - close(ch) - }() - return ch -} - func (w *androidMkWriter) handleLocalPath() error { if w.printedLocalPath { return nil @@ -424,20 +377,16 @@ func (w *androidMkWriter) write(androidMk string) error { w.Writer = bufio.NewWriter(f) - for block := range w.iter() { + if err := w.handleLocalPath(); err != nil { + return err + } + + for _, block := range w.blueprint.Defs { switch block := block.(type) { case *bpparser.Module: - if err := w.handleLocalPath(); err != nil { - return err - } w.handleModule(block) case *bpparser.Assignment: - if err := w.handleLocalPath(); err != nil { - return err - } w.handleAssignment(block) - case bpparser.Comment: - w.handleComment(&block) } }