Skip to content

Commit

Permalink
Fix filter sketch source for "Export cmake" output (#514)
Browse files Browse the repository at this point in the history
* fix filter sketch source

* removed lines generated from preprocessor

* remove file added by mistake

* remove lines generated by preprocessor in c_make file

* introduce again ContainerAddPrototypes
  • Loading branch information
umbynos authored and rsora committed Feb 14, 2020
1 parent f04fe92 commit 64c501d
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion legacy/builder/create_cmake_rule.go
Expand Up @@ -17,8 +17,10 @@ package builder

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"regexp"
"strings"

properties "github.com/arduino/go-properties-orderedmap"
Expand Down Expand Up @@ -115,7 +117,7 @@ func (s *ExportProjectCMake) Run(ctx *types.Context) error {
commands := []types.Command{
//&ContainerMergeCopySketchFiles{},
&ContainerAddPrototypes{},
//&FilterSketchSource{Source: &ctx.Source, RemoveLineMarkers: true},
&FilterSketchSource{Source: &ctx.Source, RemoveLineMarkers: true},
}

for _, command := range commands {
Expand All @@ -127,6 +129,31 @@ func (s *ExportProjectCMake) Run(ctx *types.Context) error {
fmt.Println(err)
}

// remove "#line 1 ..." from exported c_make folder sketch
var sketchFiles []string
utils.FindFilesInFolder(&sketchFiles, cmakeFolder.Join("sketch").String(), extensions, false)

for _, file := range sketchFiles {
input, err := ioutil.ReadFile(file)
if err != nil {
fmt.Println(err)
continue
}

lines := strings.Split(string(input), "\n")

for i, line := range lines {
if lineToRemove, _ := regexp.MatchString(`^#line\s\d+\s"`, line); lineToRemove == true {
lines[i] = ""
}
}
output := strings.Join(lines, "\n")
err = ioutil.WriteFile(file, []byte(output), 0644)
if err != nil {
fmt.Println(err)
}
}

// Extract CFLAGS, CPPFLAGS and LDFLAGS
var defines []string
var linkerflags []string
Expand Down

0 comments on commit 64c501d

Please sign in to comment.