Skip to content

Commit edbf386

Browse files
committed
Merge branch 'filename-quoting' of https://github.com/matthijskooijman/arduino-builder
Signed-off-by: Cristian Maglie <c.maglie@arduino.cc>
2 parents baa901e + e418963 commit edbf386

20 files changed

+233
-133
lines changed

src/arduino.cc/builder/collect_ctags_from_sketch_files.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ package builder
3232
import (
3333
"arduino.cc/builder/types"
3434
"arduino.cc/builder/utils"
35-
"strings"
3635
)
3736

3837
type CollectCTagsFromSketchFiles struct{}
@@ -43,7 +42,7 @@ func (s *CollectCTagsFromSketchFiles) Run(ctx *types.Context) error {
4342
allCtags := ctx.CTagsOfPreprocessedSource
4443
ctagsOfSketch := []*types.CTag{}
4544
for _, ctag := range allCtags {
46-
if utils.SliceContains(sketchFileNames, strings.Replace(ctag.Filename, "\\\\", "\\", -1)) {
45+
if utils.SliceContains(sketchFileNames, ctag.Filename) {
4746
ctagsOfSketch = append(ctagsOfSketch, ctag)
4847
}
4948
}

src/arduino.cc/builder/ctags/ctags_parser.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,14 @@ func parseTag(row string) *types.CTag {
229229
parts := strings.Split(row, "\t")
230230

231231
tag.FunctionName = parts[0]
232-
tag.Filename = parts[1]
232+
// This unescapes any backslashes in the filename. These
233+
// filenames that ctags outputs originate from the line markers
234+
// in the source, as generated by gcc. gcc escapes both
235+
// backslashes and double quotes, but ctags ignores any escaping
236+
// and just cuts off the filename at the first double quote it
237+
// sees. This means any backslashes are still escaped, and need
238+
// to be unescape, and any quotes will just break the build.
239+
tag.Filename = strings.Replace(parts[1], "\\\\", "\\", -1)
233240

234241
parts = parts[2:]
235242

src/arduino.cc/builder/prototypes_adder.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ package builder
3232
import (
3333
"arduino.cc/builder/constants"
3434
"arduino.cc/builder/types"
35+
"arduino.cc/builder/utils"
3536
"fmt"
3637
"strconv"
3738
"strings"
@@ -87,7 +88,7 @@ func composePrototypeSection(line int, prototypes []*types.Prototype) string {
8788
str := joinPrototypes(prototypes)
8889
str += "\n#line "
8990
str += strconv.Itoa(line)
90-
str += " \"" + prototypes[0].File + "\""
91+
str += " " + utils.QuoteCppString(prototypes[0].File)
9192
str += "\n"
9293

9394
return str
@@ -99,7 +100,7 @@ func joinPrototypes(prototypes []*types.Prototype) string {
99100
if signatureContainsaDefaultArg(proto) {
100101
continue
101102
}
102-
prototypesSlice = append(prototypesSlice, "#line "+strconv.Itoa(proto.Line)+" \""+proto.File+"\"")
103+
prototypesSlice = append(prototypesSlice, "#line "+strconv.Itoa(proto.Line)+" "+utils.QuoteCppString(proto.File))
103104
prototypeParts := []string{}
104105
if proto.Modifiers != "" {
105106
prototypeParts = append(prototypeParts, proto.Modifiers)

src/arduino.cc/builder/sketch_source_merger.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ package builder
3232

3333
import (
3434
"arduino.cc/builder/types"
35+
"arduino.cc/builder/utils"
3536
"regexp"
36-
"strings"
3737
)
3838

3939
type SketchSourceMerger struct{}
@@ -47,7 +47,7 @@ func (s *SketchSourceMerger) Run(ctx *types.Context) error {
4747
includeSection += "#include <Arduino.h>\n"
4848
lineOffset++
4949
}
50-
includeSection += "#line 1 \"" + strings.Replace((&sketch.MainFile).Name, "\\", "\\\\", -1) + "\"\n"
50+
includeSection += "#line 1 " + utils.QuoteCppString(sketch.MainFile.Name) + "\n"
5151
lineOffset++
5252
ctx.IncludeSection = includeSection
5353

@@ -73,7 +73,7 @@ func sketchIncludesArduinoH(sketch *types.SketchFile) bool {
7373
}
7474

7575
func addSourceWrappedWithLineDirective(sketch *types.SketchFile) string {
76-
source := "#line 1 \"" + strings.Replace(sketch.Name, "\\", "\\\\", -1) + "\"\n"
76+
source := "#line 1 " + utils.QuoteCppString(sketch.Name) + "\n"
7777
source += sketch.Source
7878
source += "\n"
7979

src/arduino.cc/builder/test/helper.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,20 @@ package test
3333
import (
3434
"arduino.cc/builder/constants"
3535
"arduino.cc/builder/types"
36+
"arduino.cc/builder/utils"
3637
"bytes"
3738
"fmt"
3839
"github.com/go-errors/errors"
3940
"github.com/stretchr/testify/assert"
4041
"io/ioutil"
4142
"path/filepath"
42-
"strings"
4343
"testing"
4444
"text/template"
4545
)
4646

4747
func LoadAndInterpolate(t *testing.T, filename string, ctx *types.Context) string {
4848
funcsMap := template.FuncMap{
49-
"EscapeBackSlashes": func(s string) string {
50-
return strings.Replace(s, "\\", "\\\\", -1)
51-
},
49+
"QuoteCppString": utils.QuoteCppString,
5250
}
5351

5452
tpl, err := template.New(filepath.Base(filename)).Funcs(funcsMap).ParseFiles(filename)

src/arduino.cc/builder/test/prototypes_adder_test.go

Lines changed: 37 additions & 36 deletions
Large diffs are not rendered by default.
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
#include <Arduino.h>
2-
#line 1 "{{EscapeBackSlashes .sketch.MainFile.Name}}"
3-
#line 1 "{{EscapeBackSlashes .sketch.MainFile.Name}}"
2+
#line 1 {{QuoteCppString .sketch.MainFile.Name}}
3+
#line 1 {{QuoteCppString .sketch.MainFile.Name}}
44
void setup() {
55

66
}
77

88
void loop() {
99

1010
}
11-
#line 1 "{{EscapeBackSlashes (index .sketch.OtherSketchFiles 0).Name}}"
11+
#line 1 {{QuoteCppString (index .sketch.OtherSketchFiles 0).Name}}
1212

13-
#line 1 "{{EscapeBackSlashes (index .sketch.OtherSketchFiles 1).Name}}"
13+
#line 1 {{QuoteCppString (index .sketch.OtherSketchFiles 1).Name}}
1414
String hello() {
1515
return "world";
1616
}

src/arduino.cc/builder/test/sketch2/SketchWithIfDef.preprocessed.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <Arduino.h>
2-
#line 1 "{{EscapeBackSlashes .sketch.MainFile.Name}}"
3-
#line 1 "{{EscapeBackSlashes .sketch.MainFile.Name}}"
2+
#line 1 {{QuoteCppString .sketch.MainFile.Name}}
3+
#line 1 {{QuoteCppString .sketch.MainFile.Name}}
44
#define DEBUG 1
55
#define DISABLED 0
66

@@ -16,17 +16,17 @@ typedef int MyType;
1616

1717
#include "empty_2.h"
1818

19-
#line 16 "{{EscapeBackSlashes .sketch.MainFile.Name}}"
19+
#line 16 {{QuoteCppString .sketch.MainFile.Name}}
2020
void setup();
21-
#line 21 "{{EscapeBackSlashes .sketch.MainFile.Name}}"
21+
#line 21 {{QuoteCppString .sketch.MainFile.Name}}
2222
void loop();
23-
#line 33 "{{EscapeBackSlashes .sketch.MainFile.Name}}"
23+
#line 33 {{QuoteCppString .sketch.MainFile.Name}}
2424
void debug();
25-
#line 44 "{{EscapeBackSlashes .sketch.MainFile.Name}}"
25+
#line 44 {{QuoteCppString .sketch.MainFile.Name}}
2626
void disabledIsDefined();
27-
#line 48 "{{EscapeBackSlashes .sketch.MainFile.Name}}"
27+
#line 48 {{QuoteCppString .sketch.MainFile.Name}}
2828
int useMyType(MyType type);
29-
#line 16 "{{EscapeBackSlashes .sketch.MainFile.Name}}"
29+
#line 16 {{QuoteCppString .sketch.MainFile.Name}}
3030
void setup() {
3131
// put your setup code here, to run once:
3232

src/arduino.cc/builder/test/sketch2/SketchWithIfDef.resolved.directives.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <Arduino.h>
2-
#line 1 "{{EscapeBackSlashes .sketch.MainFile.Name}}"
3-
#line 1 "{{EscapeBackSlashes .sketch.MainFile.Name}}"
2+
#line 1 {{QuoteCppString .sketch.MainFile.Name}}
3+
#line 1 {{QuoteCppString .sketch.MainFile.Name}}
44
#define DEBUG 1
55
#define DISABLED 0
66

src/arduino.cc/builder/test/sketch3/Baladuino.preprocessed.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <Arduino.h>
2-
#line 1 "{{EscapeBackSlashes .sketch.MainFile.Name}}"
3-
#line 1 "{{EscapeBackSlashes .sketch.MainFile.Name}}"
2+
#line 1 {{QuoteCppString .sketch.MainFile.Name}}
3+
#line 1 {{QuoteCppString .sketch.MainFile.Name}}
44
/*
55
* The code is released under the GNU General Public License.
66
* Developed by Kristian Lauszus, TKJ Electronics 2013
@@ -88,11 +88,11 @@ WII Wii(&Btd); // The Wii library can communicate with Wiimotes and the Nunchuck
8888
// This can also be done using the Android or Processing application
8989
#endif
9090

91-
#line 88 "{{EscapeBackSlashes .sketch.MainFile.Name}}"
91+
#line 88 {{QuoteCppString .sketch.MainFile.Name}}
9292
void setup();
93-
#line 204 "{{EscapeBackSlashes .sketch.MainFile.Name}}"
93+
#line 204 {{QuoteCppString .sketch.MainFile.Name}}
9494
void loop();
95-
#line 88 "{{EscapeBackSlashes .sketch.MainFile.Name}}"
95+
#line 88 {{QuoteCppString .sketch.MainFile.Name}}
9696
void setup() {
9797
/* Initialize UART */
9898
Serial.begin(115200);

0 commit comments

Comments
 (0)