From e10952b4424418d26b732f5c96e5ed676fd7de2a Mon Sep 17 00:00:00 2001 From: Sasha Smundak Date: Tue, 5 Mar 2019 17:34:32 -0800 Subject: [PATCH] Do not "escape" newline if comment ends with ESC character. Fixes: 127521510 Test: manual Change-Id: I88a8eb2ca94b8aa06e2682d2c14f9e74f5ada286 --- androidmk/cmd/androidmk/androidmk_test.go | 11 +++++++++++ androidmk/parser/parser.go | 8 +++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/androidmk/cmd/androidmk/androidmk_test.go b/androidmk/cmd/androidmk/androidmk_test.go index 2cbfd0123..98d4506a1 100644 --- a/androidmk/cmd/androidmk/androidmk_test.go +++ b/androidmk/cmd/androidmk/androidmk_test.go @@ -1062,6 +1062,17 @@ include test/vts/tools/build/Android.host_config.mk vts_config { name: "vtsconf", } +`, + }, + { + desc: "comment with ESC", + in: ` +# Comment line 1 \ +# Comment line 2 +`, + expected: ` +// Comment line 1 \ +// Comment line 2 `, }, } diff --git a/androidmk/parser/parser.go b/androidmk/parser/parser.go index 89c1af904..86dabf975 100644 --- a/androidmk/parser/parser.go +++ b/androidmk/parser/parser.go @@ -485,10 +485,12 @@ loop: case '\\': p.parseEscape() if p.tok == '\n' { - comment += "\n" - } else { - comment += "\\" + p.scanner.TokenText() + // 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': p.accept('\n')