Skip to content

Commit b00a0c0

Browse files
committed
Revert "Use absolute paths in #line directives generated"
1 parent 11d6b18 commit b00a0c0

15 files changed

+65
-37
lines changed

src/arduino.cc/builder/sketch_source_merger.go

Lines changed: 2 additions & 1 deletion
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+
"path/filepath"
3536
)
3637

3738
type SketchSourceMerger struct{}
@@ -51,7 +52,7 @@ func (s *SketchSourceMerger) Run(context map[string]interface{}) error {
5152
}
5253

5354
func addPreprocLine(sketch *types.SketchFile) string {
54-
source := "#line 1 \"" + sketch.Name + "\"\n"
55+
source := "#line 1 \"" + filepath.Base(sketch.Name) + "\"\n"
5556
source += sketch.Source
5657
source += "\n"
5758

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"arduino.cc/builder/constants"
3535
"arduino.cc/builder/types"
3636
"github.com/stretchr/testify/require"
37+
"io/ioutil"
3738
"os"
3839
"path/filepath"
3940
"strings"
@@ -67,7 +68,10 @@ func TestCoanRunner(t *testing.T) {
6768
NoError(t, err)
6869
}
6970

70-
expectedSource := LoadAndInterpolate(t, filepath.Join("sketch2", "SketchWithIfDef.resolved.directives.txt"), context)
71+
bytes, err1 := ioutil.ReadFile(filepath.Join("sketch2", "SketchWithIfDef.resolved.directives.txt"))
72+
NoError(t, err1)
73+
expectedSource := string(bytes)
74+
7175
require.Equal(t, expectedSource, strings.Replace(context[constants.CTX_SOURCE].(string), "\r\n", "\n", -1))
7276

7377
}

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,8 @@ import (
3838
"io/ioutil"
3939
"path/filepath"
4040
"testing"
41-
"text/template"
42-
"bytes"
4341
)
4442

45-
func LoadAndInterpolate(t *testing.T, filename string, context map[string]interface{}) string {
46-
tpl, err := template.ParseFiles(filename)
47-
NoError(t, err)
48-
49-
var buf bytes.Buffer
50-
err = tpl.Execute(&buf, context)
51-
NoError(t, err)
52-
53-
return buf.String()
54-
}
55-
5643
func Abs(t *testing.T, rel string) string {
5744
toolPath, err := filepath.Abs(rel)
5845
NoError(t, err)

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

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"arduino.cc/builder/constants"
3535
"arduino.cc/builder/types"
3636
"github.com/stretchr/testify/require"
37+
"io/ioutil"
3738
"os"
3839
"path/filepath"
3940
"strings"
@@ -116,7 +117,11 @@ func TestPrototypesAdderSketchWithIfDef(t *testing.T) {
116117
NoError(t, err)
117118
}
118119

119-
preprocessed := LoadAndInterpolate(t, filepath.Join("sketch2", "SketchWithIfDef.preprocessed.txt"), context)
120+
bytes, err := ioutil.ReadFile(filepath.Join("sketch2", "SketchWithIfDef.preprocessed.txt"))
121+
NoError(t, err)
122+
123+
preprocessed := string(bytes)
124+
120125
require.Equal(t, preprocessed, strings.Replace(context[constants.CTX_SOURCE].(string), "\r\n", "\n", -1))
121126
}
122127

@@ -156,7 +161,11 @@ func TestPrototypesAdderBaladuino(t *testing.T) {
156161
NoError(t, err)
157162
}
158163

159-
preprocessed := LoadAndInterpolate(t, filepath.Join("sketch3", "Baladuino.preprocessed.txt"), context)
164+
bytes, err := ioutil.ReadFile(filepath.Join("sketch3", "Baladuino.preprocessed.txt"))
165+
NoError(t, err)
166+
167+
preprocessed := string(bytes)
168+
160169
require.Equal(t, preprocessed, strings.Replace(context[constants.CTX_SOURCE].(string), "\r\n", "\n", -1))
161170
}
162171

@@ -196,7 +205,11 @@ func TestPrototypesAdderCharWithEscapedDoubleQuote(t *testing.T) {
196205
NoError(t, err)
197206
}
198207

199-
preprocessed := LoadAndInterpolate(t, filepath.Join("sketch4", "CharWithEscapedDoubleQuote.preprocessed.txt"), context)
208+
bytes, err := ioutil.ReadFile(filepath.Join("sketch4", "CharWithEscapedDoubleQuote.preprocessed.txt"))
209+
NoError(t, err)
210+
211+
preprocessed := string(bytes)
212+
200213
require.Equal(t, preprocessed, strings.Replace(context[constants.CTX_SOURCE].(string), "\r\n", "\n", -1))
201214
}
202215

@@ -236,7 +249,11 @@ func TestPrototypesAdderIncludeBetweenMultilineComment(t *testing.T) {
236249
NoError(t, err)
237250
}
238251

239-
preprocessed := LoadAndInterpolate(t, filepath.Join("sketch5", "IncludeBetweenMultilineComment.preprocessed.txt"), context)
252+
bytes, err := ioutil.ReadFile(filepath.Join("sketch5", "IncludeBetweenMultilineComment.preprocessed.txt"))
253+
NoError(t, err)
254+
255+
preprocessed := string(bytes)
256+
240257
require.Equal(t, preprocessed, strings.Replace(context[constants.CTX_SOURCE].(string), "\r\n", "\n", -1))
241258
}
242259

@@ -276,7 +293,11 @@ func TestPrototypesAdderLineContinuations(t *testing.T) {
276293
NoError(t, err)
277294
}
278295

279-
preprocessed := LoadAndInterpolate(t, filepath.Join("sketch6", "LineContinuations.preprocessed.txt"), context)
296+
bytes, err := ioutil.ReadFile(filepath.Join("sketch6", "LineContinuations.preprocessed.txt"))
297+
NoError(t, err)
298+
299+
preprocessed := string(bytes)
300+
280301
require.Equal(t, preprocessed, strings.Replace(context[constants.CTX_SOURCE].(string), "\r\n", "\n", -1))
281302
}
282303

@@ -316,7 +337,11 @@ func TestPrototypesAdderStringWithComment(t *testing.T) {
316337
NoError(t, err)
317338
}
318339

319-
preprocessed := LoadAndInterpolate(t, filepath.Join("sketch7", "StringWithComment.preprocessed.txt"), context)
340+
bytes, err := ioutil.ReadFile(filepath.Join("sketch7", "StringWithComment.preprocessed.txt"))
341+
NoError(t, err)
342+
343+
preprocessed := string(bytes)
344+
320345
require.Equal(t, preprocessed, strings.Replace(context[constants.CTX_SOURCE].(string), "\r\n", "\n", -1))
321346
}
322347

@@ -356,7 +381,11 @@ func TestPrototypesAdderSketchWithStruct(t *testing.T) {
356381
NoError(t, err)
357382
}
358383

359-
preprocessed := LoadAndInterpolate(t, filepath.Join("sketch8", "SketchWithStruct.preprocessed.txt"), context)
384+
bytes, err := ioutil.ReadFile(filepath.Join("sketch8", "SketchWithStruct.preprocessed.txt"))
385+
NoError(t, err)
386+
387+
preprocessed := string(bytes)
388+
360389
require.Equal(t, preprocessed, strings.Replace(context[constants.CTX_SOURCE].(string), "\r\n", "\n", -1))
361390
}
362391

@@ -399,7 +428,11 @@ func TestPrototypesAdderSketchWithConfig(t *testing.T) {
399428
require.Equal(t, "#include <Arduino.h>\n#line 1\n", context[constants.CTX_INCLUDE_SECTION].(string))
400429
require.Equal(t, "void setup();\nvoid loop();\n#line 13\n", context[constants.CTX_PROTOTYPE_SECTION].(string))
401430

402-
preprocessed := LoadAndInterpolate(t, filepath.Join("sketch_with_config", "sketch_with_config.preprocessed.txt"), context)
431+
bytes, err := ioutil.ReadFile(filepath.Join("sketch_with_config", "sketch_with_config.preprocessed.txt"))
432+
NoError(t, err)
433+
434+
preprocessed := string(bytes)
435+
403436
require.Equal(t, preprocessed, strings.Replace(context[constants.CTX_SOURCE].(string), "\r\n", "\n", -1))
404437
}
405438

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
#line 1 "{{.sketch.MainFile.Name}}"
1+
#line 1 "sketch.ino"
22
void setup() {
33

44
}
55

66
void loop() {
77

88
}
9-
#line 1 "{{(index .sketch.OtherSketchFiles 0).Name}}"
9+
#line 1 "old.pde"
1010

11-
#line 1 "{{(index .sketch.OtherSketchFiles 1).Name}}"
11+
#line 1 "other.ino"
1212
String hello() {
1313
return "world";
1414
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <Arduino.h>
22
#line 1
3-
#line 1 "{{.sketch.MainFile.Name}}"
3+
#line 1 "SketchWithIfDef.ino"
44
#define DEBUG 1
55
#define DISABLED 0
66

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#line 1 "{{.sketch.MainFile.Name}}"
1+
#line 1 "SketchWithIfDef.ino"
22
#define DEBUG 1
33
#define DISABLED 0
44

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <Arduino.h>
22
#line 1
3-
#line 1 "{{.sketch.MainFile.Name}}"
3+
#line 1 "Baladuino.ino"
44
/*
55
* The code is released under the GNU General Public License.
66
* Developed by Kristian Lauszus, TKJ Electronics 2013

src/arduino.cc/builder/test/sketch4/CharWithEscapedDoubleQuote.preprocessed.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <Arduino.h>
22
#line 1
3-
#line 1 "{{.sketch.MainFile.Name}}"
3+
#line 1 "CharWithEscapedDoubleQuote.ino"
44
#include <SoftwareSerial.h> // required to send and receive AT commands from the GPRS Shield
55
#include <Wire.h> // required for I2C communication with the RTC
66

src/arduino.cc/builder/test/sketch5/IncludeBetweenMultilineComment.preprocessed.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <Arduino.h>
22
#line 1
3-
#line 1 "{{.sketch.MainFile.Name}}"
3+
#line 1 "IncludeBetweenMultilineComment.ino"
44
#include <CapacitiveSensor.h>
55
/*
66
#include <WiFi.h>

0 commit comments

Comments
 (0)