Skip to content

Commit 1a83e6f

Browse files
committed
Factored function to determine library compatibility
1 parent 8bc10fb commit 1a83e6f

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

arduino/libraries/libraries.go

+7
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,13 @@ func (library *Library) IsArchitectureIndependent() bool {
181181
return library.IsOptimizedForArchitecture("*") || library.Architectures == nil || len(library.Architectures) == 0
182182
}
183183

184+
// IsCompatibleWith returns true if the library declares compatibility with
185+
// the given architecture. If this function returns false, the library may still
186+
// be compatible with the given architecture, but it's not explicitly declared.
187+
func (library *Library) IsCompatibleWith(arch string) bool {
188+
return library.IsArchitectureIndependent() || library.IsOptimizedForArchitecture(arch)
189+
}
190+
184191
// SourceDir represents a source dir of a library
185192
type SourceDir struct {
186193
Dir *paths.Path

commands/lib/list.go

+2-9
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func LibraryList(ctx context.Context, req *rpc.LibraryListRequest) (*rpc.Library
4949
nameFilter := strings.ToLower(req.GetName())
5050

5151
var allLibs []*installedLib
52-
if f := req.GetFqbn(); f != "" {
52+
if fqbnString := req.GetFqbn(); fqbnString != "" {
5353
allLibs = listLibraries(lm, req.GetUpdatable(), true)
5454
fqbn, err := cores.ParseFQBN(req.GetFqbn())
5555
if err != nil {
@@ -76,15 +76,8 @@ func LibraryList(ctx context.Context, req *rpc.LibraryListRequest) (*rpc.Library
7676
}
7777

7878
// Check if library is compatible with board specified by FBQN
79-
compatible := false
80-
for _, arch := range lib.Library.Architectures {
81-
compatible = (arch == fqbn.PlatformArch || arch == "*")
82-
if compatible {
83-
break
84-
}
85-
}
8679
lib.Library.CompatibleWith = map[string]bool{
87-
f: compatible,
80+
fqbnString: lib.Library.IsCompatibleWith(fqbn.PlatformArch),
8881
}
8982

9083
filteredRes[lib.Library.Name] = lib

0 commit comments

Comments
 (0)