Skip to content

Libraries compatibility is now shown when calling lib list with fqbn #978

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions arduino/libraries/libraries.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ type Library struct {
Examples paths.PathList
declaredHeaders []string
sourceHeaders []string
CompatibleWith map[string]bool
}

func (library *Library) String() string {
Expand Down
12 changes: 10 additions & 2 deletions cli/lib/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,16 @@ func runListCommand(cmd *cobra.Command, args []string) {
os.Exit(errorcodes.ErrGeneric)
}

libs := res.GetInstalledLibrary()
libs := []*rpc.InstalledLibrary{}
if listFlags.fqbn == "" {
libs = res.GetInstalledLibrary()
} else {
for _, lib := range res.GetInstalledLibrary() {
if lib.Library.CompatibleWith[listFlags.fqbn] {
libs = append(libs, lib)
}
}
}

// To uniform the output to other commands, when there are no result
// print out an empty slice.
Expand Down Expand Up @@ -139,7 +148,6 @@ func (ir installedResult) String() string {
} else if len(sentence) > 40 {
sentence = sentence[:37] + "..."
}

t.AddRow(name, lib.Version, available, location, sentence)
}
}
Expand Down
91 changes: 51 additions & 40 deletions commands/lib/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,57 +50,67 @@ func LibraryList(ctx context.Context, req *rpc.LibraryListReq) (*rpc.LibraryList

instaledLib := []*rpc.InstalledLibrary{}
res := listLibraries(lm, req.GetUpdatable(), req.GetAll())
if len(res) > 0 {
if f := req.GetFqbn(); f != "" {
fqbn, err := cores.ParseFQBN(req.GetFqbn())
if err != nil {
return nil, fmt.Errorf("parsing fqbn: %s", err)
}
_, boardPlatform, _, _, refBoardPlatform, err := pm.ResolveFQBN(fqbn)
if err != nil {
return nil, fmt.Errorf("loading board data: %s", err)
}
if f := req.GetFqbn(); f != "" {
fqbn, err := cores.ParseFQBN(req.GetFqbn())
if err != nil {
return nil, fmt.Errorf("parsing fqbn: %s", err)
}
_, boardPlatform, _, _, refBoardPlatform, err := pm.ResolveFQBN(fqbn)
if err != nil {
return nil, fmt.Errorf("loading board data: %s", err)
}

filteredRes := map[string]*installedLib{}
for _, lib := range res {
if cp := lib.Library.ContainerPlatform; cp != nil {
if cp != boardPlatform && cp != refBoardPlatform {
// Filter all libraries from extraneous platforms
continue
}
filteredRes := map[string]*installedLib{}
for _, lib := range res {
if cp := lib.Library.ContainerPlatform; cp != nil {
if cp != boardPlatform && cp != refBoardPlatform {
// Filter all libraries from extraneous platforms
continue
}
if latest, has := filteredRes[lib.Library.Name]; has {
if latest.Library.LocationPriorityFor(boardPlatform, refBoardPlatform) >= lib.Library.LocationPriorityFor(boardPlatform, refBoardPlatform) {
continue
}
}
if latest, has := filteredRes[lib.Library.Name]; has {
if latest.Library.LocationPriorityFor(boardPlatform, refBoardPlatform) >= lib.Library.LocationPriorityFor(boardPlatform, refBoardPlatform) {
continue
}
filteredRes[lib.Library.Name] = lib
}

res = []*installedLib{}
for _, lib := range filteredRes {
res = append(res, lib)
// Check if library is compatible with board specified by FBQN
compatible := false
for _, arch := range lib.Library.Architectures {
compatible = (arch == fqbn.PlatformArch || arch == "*")
if compatible {
break
}
}
lib.Library.CompatibleWith = map[string]bool{
f: compatible,
}

filteredRes[lib.Library.Name] = lib
}

for _, lib := range res {
if nameFilter != "" && strings.ToLower(lib.Library.Name) != nameFilter {
continue
}
libtmp, err := GetOutputLibrary(lib.Library)
if err != nil {
return nil, err
}
release := GetOutputRelease(lib.Available)
instaledLib = append(instaledLib, &rpc.InstalledLibrary{
Library: libtmp,
Release: release,
})
res = []*installedLib{}
for _, lib := range filteredRes {
res = append(res, lib)
}
}

return &rpc.LibraryListResp{InstalledLibrary: instaledLib}, nil
for _, lib := range res {
if nameFilter != "" && strings.ToLower(lib.Library.Name) != nameFilter {
continue
}
libtmp, err := GetOutputLibrary(lib.Library)
if err != nil {
return nil, err
}
release := GetOutputRelease(lib.Available)
instaledLib = append(instaledLib, &rpc.InstalledLibrary{
Library: libtmp,
Release: release,
})
}
return &rpc.LibraryListResp{}, nil

return &rpc.LibraryListResp{InstalledLibrary: instaledLib}, nil
}

// listLibraries returns the list of installed libraries. If updatable is true it
Expand Down Expand Up @@ -171,6 +181,7 @@ func GetOutputLibrary(lib *libraries.Library) (*rpc.Library, error) {
License: lib.License,
Examples: lib.Examples.AsStrings(),
ProvidesIncludes: lib.DeclaredHeaders(),
CompatibleWith: lib.CompatibleWith,
}, nil
}

Expand Down
115 changes: 68 additions & 47 deletions rpc/commands/lib.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion rpc/commands/lib.proto
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ message Library {
// Value of the `includes` field in library.properties or, if missing, the list of
// include files available on the library source root directory.
repeated string provides_includes = 27;
// Map of FQBNs that specifies if library is compatible with this library
map<string, bool> compatible_with = 28;
}

enum LibraryLayout {
Expand All @@ -287,7 +289,7 @@ enum LibraryLocation {
user = 1;
// In the `libraries` subdirectory of a platform.
platform_builtin = 2;
// When `LibraryLocation` is used in a context where a board is specified,
// When `LibraryLocation` is used in a context where a board is specified,
// this indicates the library is in the `libraries` subdirectory of a
// platform referenced by the board's platform.
referenced_platform_builtin = 3;
Expand Down
Loading