From 360a39c0f1a076b9644908588593282bdb6f2eb3 Mon Sep 17 00:00:00 2001 From: Dan Willemsen Date: Thu, 11 Jun 2015 14:34:50 -0700 Subject: [PATCH] androidbp: Defer local path printing This will defer printing the local path until the first module or definition. Usually, there's a copyright comment at the top of the file that will be now be printed first, then the LOCAL_PATH. Change-Id: I349f7e30eaa99dcfdc73e96248774927a13be8cb --- androidbp/cmd/androidbp.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/androidbp/cmd/androidbp.go b/androidbp/cmd/androidbp.go index 6e0bc7f75..58afe7725 100644 --- a/androidbp/cmd/androidbp.go +++ b/androidbp/cmd/androidbp.go @@ -21,6 +21,8 @@ type androidMkWriter struct { blueprint *bpparser.File path string + printedLocalPath bool + mapScope map[string][]*bpparser.Property } @@ -286,6 +288,11 @@ func (w *androidMkWriter) iter() <-chan interface{} { } func (w *androidMkWriter) handleLocalPath() error { + if w.printedLocalPath { + return nil + } + w.printedLocalPath = true + localPath, err := filepath.Abs(w.path) if err != nil { return err @@ -317,15 +324,17 @@ func (w *androidMkWriter) write(androidMk string) error { w.Writer = bufio.NewWriter(f) - if err := w.handleLocalPath(); err != nil { - return err - } - for block := range w.iter() { 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)