Skip to content

Commit cf017d4

Browse files
Improve library examples loading process by filtering out unneeded directories
1 parent 0b77c0a commit cf017d4

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

arduino/libraries/loader.go

+7-10
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"strings"
2121

2222
"github.com/arduino/arduino-cli/arduino/globals"
23-
"github.com/arduino/arduino-cli/arduino/sketch"
2423
"github.com/arduino/go-paths-helper"
2524
properties "github.com/arduino/go-properties-orderedmap"
2625
"github.com/pkg/errors"
@@ -176,19 +175,12 @@ func addExamples(lib *Library) error {
176175
}
177176

178177
func addExamplesToPathList(examplesPath *paths.Path, list *paths.PathList) error {
179-
files, err := examplesPath.ReadDir()
178+
files, err := examplesPath.ReadDirRecursiveFiltered(nil, filterExamplesDirs)
180179
if err != nil {
181180
return err
182181
}
183182
for _, file := range files {
184-
_, err := sketch.New(file)
185-
if err == nil {
186-
list.Add(file)
187-
} else if file.IsDir() {
188-
if err := addExamplesToPathList(file, list); err != nil {
189-
return err
190-
}
191-
}
183+
list.Add(file)
192184
}
193185
return nil
194186
}
@@ -208,3 +200,8 @@ func containsHeaderFile(d *paths.Path) (bool, error) {
208200
dirContent.FilterSuffix(headerExtensions...)
209201
return len(dirContent) > 0, nil
210202
}
203+
204+
// filterExamplesDirs filters out any directory that does not contain a ".ino" or ".pde" file
205+
func filterExamplesDirs(dir *paths.Path) bool {
206+
return dir.Join(dir.Base()+".ino").Exist() || dir.Join(dir.Base()+".pde").Exist()
207+
}

0 commit comments

Comments
 (0)