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
diff --git a/androidbp/cmd/androidbp.go b/androidbp/cmd/androidbp.go
index a8f4580..19a9328 100644
--- a/androidbp/cmd/androidbp.go
+++ b/androidbp/cmd/androidbp.go
@@ -233,12 +233,6 @@
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) 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 @@
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)
}
}