Skip to content

Commit a2fdfd6

Browse files
Exclude libraries with a missing .h file from lib commands
1 parent 2900744 commit a2fdfd6

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Diff for: arduino/libraries/loader.go

+26
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"fmt"
2020
"strings"
2121

22+
"github.com/arduino/arduino-cli/arduino/globals"
2223
"github.com/arduino/arduino-cli/arduino/sketch"
2324
"github.com/arduino/go-paths-helper"
2425
properties "github.com/arduino/go-properties-orderedmap"
@@ -126,6 +127,11 @@ func makeNewLibrary(libraryDir *paths.Path, location LibraryLocation) (*Library,
126127
}
127128

128129
func makeLegacyLibrary(path *paths.Path, location LibraryLocation) (*Library, error) {
130+
if foundHeader, err := containsHeaderFile(path); err != nil {
131+
return nil, err
132+
} else if !foundHeader {
133+
return nil, errors.Errorf(tr("library not valid"))
134+
}
129135
library := &Library{
130136
InstallDir: path.Canonical(),
131137
Location: location,
@@ -186,3 +192,23 @@ func addExamplesToPathList(examplesPath *paths.Path, list *paths.PathList) error
186192
}
187193
return nil
188194
}
195+
196+
// containsHeaderFile returns true if the directory contains a ".h" file.
197+
// Returns false otherwise
198+
func containsHeaderFile(d *paths.Path) (bool, error) {
199+
if d.NotExist() {
200+
// A directory that doesn't exist can't obviously contain any header file
201+
return false, nil
202+
}
203+
dirContent, err := d.ReadDir()
204+
if err != nil {
205+
return false, fmt.Errorf(tr("reading directory %s content: %w", d, err))
206+
}
207+
dirContent.FilterOutDirs()
208+
headerExtensions := []string{}
209+
for k := range globals.HeaderFilesValidExtensions {
210+
headerExtensions = append(headerExtensions, k)
211+
}
212+
dirContent.FilterSuffix(headerExtensions...)
213+
return len(dirContent) > 0, nil
214+
}

0 commit comments

Comments
 (0)