Skip to content

Commit

Permalink
Merge pull request #115 from facchinm/canonical_eol
Browse files Browse the repository at this point in the history
convert intermediate file EOLs to pure \n format
  • Loading branch information
matteosuppo committed Feb 10, 2016
2 parents 05304ac + 7ff1de1 commit 296e942
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/arduino.cc/builder/prototypes_adder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/arduino.cc/builder/test/eol_processing/sketch.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
int led = 7;void setup() { }void loop() { }
Expand Down
41 changes: 41 additions & 0 deletions src/arduino.cc/builder/test/prototypes_adder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -880,3 +880,44 @@ func TestPrototypesAdderSketchWithConst(t *testing.T) {
require.Equal(t, "#include <Arduino.h>\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
}

0 comments on commit 296e942

Please sign in to comment.