Skip to content

Commit 296e942

Browse files
committed
Merge pull request #115 from facchinm/canonical_eol
convert intermediate file EOLs to pure \n format
2 parents 05304ac + 7ff1de1 commit 296e942

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

Diff for: src/arduino.cc/builder/prototypes_adder.go

+4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ type PrototypesAdder struct{}
4343
func (s *PrototypesAdder) Run(context map[string]interface{}) error {
4444
debugOutput := context[constants.CTX_DEBUG_PREPROCESSOR] != nil
4545
source := context[constants.CTX_SOURCE].(string)
46+
47+
source = strings.Replace(source, "\r\n", "\n", -1)
48+
source = strings.Replace(source, "\r", "\n", -1)
49+
4650
sourceRows := strings.Split(source, "\n")
4751

4852
if !utils.MapHas(context, constants.CTX_LINE_WHERE_TO_INSERT_PROTOTYPES) {

Diff for: src/arduino.cc/builder/test/eol_processing/sketch.ino

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
int led = 7;void setup() { }void loop() { }

Diff for: src/arduino.cc/builder/test/prototypes_adder_test.go

+41
Original file line numberDiff line numberDiff line change
@@ -880,3 +880,44 @@ func TestPrototypesAdderSketchWithConst(t *testing.T) {
880880
require.Equal(t, "#include <Arduino.h>\n#line 1\n", context[constants.CTX_INCLUDE_SECTION].(string))
881881
require.Equal(t, "#line 1 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 2 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 4 \""+absoluteSketchLocation+"\"\nconst __FlashStringHelper* test();\n#line 6 \""+absoluteSketchLocation+"\"\nconst int test3();\n#line 8 \""+absoluteSketchLocation+"\"\nvolatile __FlashStringHelper* test2();\n#line 10 \""+absoluteSketchLocation+"\"\nvolatile int test4();\n#line 1\n", context[constants.CTX_PROTOTYPE_SECTION].(string))
882882
}
883+
884+
func TestPrototypesAdderSketchWithDosEol(t *testing.T) {
885+
DownloadCoresAndToolsAndLibraries(t)
886+
887+
context := make(map[string]interface{})
888+
889+
buildPath := SetupBuildPath(t, context)
890+
defer os.RemoveAll(buildPath)
891+
892+
sketchLocation := filepath.Join("eol_processing", "sketch.ino")
893+
894+
context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}
895+
context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"}
896+
context[constants.CTX_FQBN] = "arduino:avr:uno"
897+
context[constants.CTX_SKETCH_LOCATION] = sketchLocation
898+
context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600"
899+
context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"}
900+
context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"}
901+
context[constants.CTX_VERBOSE] = true
902+
903+
commands := []types.Command{
904+
&builder.SetupHumanLoggerIfMissing{},
905+
906+
&builder.ContainerSetupHardwareToolsLibsSketchAndProps{},
907+
908+
&builder.ContainerMergeCopySketchFiles{},
909+
910+
&builder.ContainerFindIncludes{},
911+
912+
&builder.PrintUsedLibrariesIfVerbose{},
913+
&builder.WarnAboutArchIncompatibleLibraries{},
914+
915+
&builder.ContainerAddPrototypes{},
916+
}
917+
918+
for _, command := range commands {
919+
err := command.Run(context)
920+
NoError(t, err)
921+
}
922+
// only requires no error as result
923+
}

0 commit comments

Comments
 (0)