aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShinichiro Hamaji <shinichiro.hamaji@gmail.com>2015-04-12 03:56:00 +0900
committerShinichiro Hamaji <shinichiro.hamaji@gmail.com>2015-04-12 03:56:00 +0900
commitc4c98106620069867625123d0a4fd9fc4addfeb5 (patch)
treeb0bd5bef157d8af7e2a401ec807a7c8d38fe7bbe
parent3796d1ec378cf63889007ab32ca33a92eed1d4ff (diff)
downloadandroid_build_kati-c4c98106620069867625123d0a4fd9fc4addfeb5.tar.gz
android_build_kati-c4c98106620069867625123d0a4fd9fc4addfeb5.tar.bz2
android_build_kati-c4c98106620069867625123d0a4fd9fc4addfeb5.zip
Fix spaces between concatenated lines
-rw-r--r--parser.go4
-rw-r--r--strutil.go9
-rw-r--r--testcase/multiline_and_leading_space.mk12
3 files changed, 24 insertions, 1 deletions
diff --git a/parser.go b/parser.go
index bc03e68..09f407f 100644
--- a/parser.go
+++ b/parser.go
@@ -111,9 +111,11 @@ func (p *parser) processDefineLine(line []byte) []byte {
// TODO: Handle \\ at the end of the line?
for len(line) > 0 && line[len(line)-1] == '\\' {
line = line[:len(line)-1]
+ line = bytes.TrimRight(line, "\t ")
lineno := p.lineno
- nline := p.readLine()
+ nline := trimLeftSpaceBytes(p.readLine())
p.lineno = lineno
+ line = append(line, ' ')
line = append(line, nline...)
}
return line
diff --git a/strutil.go b/strutil.go
index f080569..03d29d0 100644
--- a/strutil.go
+++ b/strutil.go
@@ -153,3 +153,12 @@ func trimLeftSpace(s string) string {
}
return ""
}
+
+func trimLeftSpaceBytes(s []byte) []byte {
+ for i, ch := range s {
+ if ch != ' ' && ch != '\t' {
+ return s[i:]
+ }
+ }
+ return nil
+}
diff --git a/testcase/multiline_and_leading_space.mk b/testcase/multiline_and_leading_space.mk
new file mode 100644
index 0000000..71f0a5e
--- /dev/null
+++ b/testcase/multiline_and_leading_space.mk
@@ -0,0 +1,12 @@
+X:=foo \
+ bar
+
+Y:=foo \
+ \
+ bar
+
+$(info foo \
+ bar)
+
+test:
+ echo PASS $(X) $(Y)