@@ -19,6 +19,7 @@ import (
19
19
"fmt"
20
20
"strings"
21
21
22
+ "github.com/arduino/arduino-cli/arduino/globals"
22
23
"github.com/arduino/arduino-cli/arduino/sketch"
23
24
"github.com/arduino/go-paths-helper"
24
25
properties "github.com/arduino/go-properties-orderedmap"
@@ -126,6 +127,11 @@ func makeNewLibrary(libraryDir *paths.Path, location LibraryLocation) (*Library,
126
127
}
127
128
128
129
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
+ }
129
135
library := & Library {
130
136
InstallDir : path .Canonical (),
131
137
Location : location ,
@@ -186,3 +192,19 @@ func addExamplesToPathList(examplesPath *paths.Path, list *paths.PathList) error
186
192
}
187
193
return nil
188
194
}
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