From 4d20d6d38bfcff05e417911e7067004dff99e0f3 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Tue, 9 Feb 2016 11:56:33 +0100 Subject: [PATCH 1/2] add test for sketch with malformed EOL --- .../builder/test/eol_processing/sketch.ino | 1 + .../builder/test/prototypes_adder_test.go | 41 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 src/arduino.cc/builder/test/eol_processing/sketch.ino diff --git a/src/arduino.cc/builder/test/eol_processing/sketch.ino b/src/arduino.cc/builder/test/eol_processing/sketch.ino new file mode 100644 index 00000000..9037a7fa --- /dev/null +++ b/src/arduino.cc/builder/test/eol_processing/sketch.ino @@ -0,0 +1 @@ +int led = 7; void setup() { } void loop() { } \ No newline at end of file diff --git a/src/arduino.cc/builder/test/prototypes_adder_test.go b/src/arduino.cc/builder/test/prototypes_adder_test.go index 0771ebaa..b3d95a9c 100644 --- a/src/arduino.cc/builder/test/prototypes_adder_test.go +++ b/src/arduino.cc/builder/test/prototypes_adder_test.go @@ -880,3 +880,44 @@ func TestPrototypesAdderSketchWithConst(t *testing.T) { require.Equal(t, "#include \n#line 1\n", context[constants.CTX_INCLUDE_SECTION].(string)) 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)) } + +func TestPrototypesAdderSketchWithDosEol(t *testing.T) { + DownloadCoresAndToolsAndLibraries(t) + + context := make(map[string]interface{}) + + buildPath := SetupBuildPath(t, context) + defer os.RemoveAll(buildPath) + + sketchLocation := filepath.Join("eol_processing", "sketch.ino") + + context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} + context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} + context[constants.CTX_FQBN] = "arduino:avr:uno" + context[constants.CTX_SKETCH_LOCATION] = sketchLocation + context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" + context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} + context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} + context[constants.CTX_VERBOSE] = true + + commands := []types.Command{ + &builder.SetupHumanLoggerIfMissing{}, + + &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, + + &builder.ContainerMergeCopySketchFiles{}, + + &builder.ContainerFindIncludes{}, + + &builder.PrintUsedLibrariesIfVerbose{}, + &builder.WarnAboutArchIncompatibleLibraries{}, + + &builder.ContainerAddPrototypes{}, + } + + for _, command := range commands { + err := command.Run(context) + NoError(t, err) + } + // only requires no error as result +} From 7ff1de12b9e073867e4fd42ddf24604466774a2c Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 8 Feb 2016 17:46:07 +0100 Subject: [PATCH 2/2] convert intermediate file EOLs to pure \n format otherwise all processing on ino file will likely fail solves #114 --- src/arduino.cc/builder/prototypes_adder.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/arduino.cc/builder/prototypes_adder.go b/src/arduino.cc/builder/prototypes_adder.go index ef2be7c2..fb1d392c 100644 --- a/src/arduino.cc/builder/prototypes_adder.go +++ b/src/arduino.cc/builder/prototypes_adder.go @@ -43,6 +43,10 @@ type PrototypesAdder struct{} func (s *PrototypesAdder) Run(context map[string]interface{}) error { debugOutput := context[constants.CTX_DEBUG_PREPROCESSOR] != nil source := context[constants.CTX_SOURCE].(string) + + source = strings.Replace(source, "\r\n", "\n", -1) + source = strings.Replace(source, "\r", "\n", -1) + sourceRows := strings.Split(source, "\n") if !utils.MapHas(context, constants.CTX_LINE_WHERE_TO_INSERT_PROTOTYPES) {