Skip to content

Commit 6f043dd

Browse files
Exclude libraries with a missing .h file from lib commands
1 parent 6ee0c24 commit 6f043dd

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Diff for: arduino/libraries/loader.go

+22
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("invalid library: no header files found"))
134+
}
129135
library := &Library{
130136
InstallDir: path.Canonical(),
131137
Location: location,
@@ -186,3 +192,19 @@ 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+
dirContent, err := d.ReadDir()
200+
if err != nil {
201+
return false, fmt.Errorf(tr("reading directory %[1]s content: %[2]w", d, err))
202+
}
203+
dirContent.FilterOutDirs()
204+
headerExtensions := []string{}
205+
for k := range globals.HeaderFilesValidExtensions {
206+
headerExtensions = append(headerExtensions, k)
207+
}
208+
dirContent.FilterSuffix(headerExtensions...)
209+
return len(dirContent) > 0, nil
210+
}

0 commit comments

Comments
 (0)