From 7890211d588aa14b08a01df76d8f42897c05dfa6 Mon Sep 17 00:00:00 2001 From: Sasha Smundak Date: Thu, 19 Nov 2020 02:20:40 -0800 Subject: [PATCH] Fix comments with continuation Backgound: aog/919954 tried to handle ``` second line ``` but did it incorrectly. The parser works correctly (so this change reverts aog/919954), it returns multiline comment, but the serializer converting the internal representation to Blueprint was not emitting '//' on the lines after the first. Test: treehugger Bug: 127521510 Change-Id: I0257a8b3cc4ffcaa6bea44113ceba66bb99d7e43 --- androidmk/androidmk/androidmk.go | 9 ++++++++- androidmk/androidmk/androidmk_test.go | 4 ++-- androidmk/parser/parser.go | 6 ------ 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/androidmk/androidmk/androidmk.go b/androidmk/androidmk/androidmk.go index 03cf74d83..f4e5fa066 100644 --- a/androidmk/androidmk/androidmk.go +++ b/androidmk/androidmk/androidmk.go @@ -137,7 +137,14 @@ func ConvertFile(filename string, buffer *bytes.Buffer) (string, []error) { switch x := node.(type) { case *mkparser.Comment: - file.insertComment("//" + x.Comment) + // Split the comment on escaped newlines and then + // add each chunk separately. + chunks := strings.Split(x.Comment, "\\\n") + file.insertComment("//" + chunks[0]) + for i := 1; i < len(chunks); i++ { + file.bpPos.Line++ + file.insertComment("//" + chunks[i]) + } case *mkparser.Assignment: handleAssignment(file, x, assignmentCond) case *mkparser.Directive: diff --git a/androidmk/androidmk/androidmk_test.go b/androidmk/androidmk/androidmk_test.go index 16cb138c9..f32ff2acb 100644 --- a/androidmk/androidmk/androidmk_test.go +++ b/androidmk/androidmk/androidmk_test.go @@ -1260,10 +1260,10 @@ prebuilt_firmware { desc: "comment with ESC", in: ` # Comment line 1 \ -# Comment line 2 + Comment line 2 `, expected: ` -// Comment line 1 \ +// Comment line 1 // Comment line 2 `, }, diff --git a/androidmk/parser/parser.go b/androidmk/parser/parser.go index e61241b2d..c14910a4f 100644 --- a/androidmk/parser/parser.go +++ b/androidmk/parser/parser.go @@ -497,12 +497,6 @@ loop: switch p.tok { case '\\': p.parseEscape() - if p.tok == '\n' { - // Special case: '\' does not "escape" newline in comment (b/127521510) - comment += "\\" - p.accept(p.tok) - break loop - } comment += "\\" + p.scanner.TokenText() p.accept(p.tok) case '\n':