Skip to content

Commit 1b08e46

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

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

arduino/libraries/loader.go

Lines changed: 7 additions & 12 deletions
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,20 +175,11 @@ 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
}
183-
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-
}
192-
}
182+
list.AddAll(files)
193183
return nil
194184
}
195185

@@ -208,3 +198,8 @@ func containsHeaderFile(d *paths.Path) (bool, error) {
208198
dirContent.FilterSuffix(headerExtensions...)
209199
return len(dirContent) > 0, nil
210200
}
201+
202+
// filterExamplesDirs filters out any directory that does not contain a ".ino" or ".pde" file
203+
func filterExamplesDirs(dir *paths.Path) bool {
204+
return dir.Join(dir.Base()+".ino").Exist() || dir.Join(dir.Base()+".pde").Exist()
205+
}

0 commit comments

Comments
 (0)