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 4 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
39 changes: 28 additions & 11 deletions 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 @@ -125,22 +127,36 @@ func (s *ExportProjectCMake) Run(ctx *types.Context) error {
fmt.Println(err)
}

// Use old ctags method to generate export file
commands := []types.Command{
//&ContainerMergeCopySketchFiles{},
&ContainerAddPrototypes{},
//&FilterSketchSource{Source: &ctx.Source, RemoveLineMarkers: true},
}

for _, command := range commands {
command.Run(ctx)
}

err = utils.CopyDir(ctx.SketchBuildPath.String(), cmakeFolder.Join("sketch").String(), extensions)
if err != nil {
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 Expand Up @@ -263,3 +279,4 @@ func findUniqueFoldersRelative(slice []string, base string) string {
}
return strings.Join(out, " ")
}