Skip to content

fix filter sketch source #514

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion legacy/builder/create_cmake_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ package builder

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

properties "github.com/arduino/go-properties-orderedmap"
Expand Down Expand Up @@ -129,7 +131,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 @@ -141,6 +143,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