Skip to content

Commit f29e7ad

Browse files
committed
Added implementation for LibraryResolveDependency grpc call
1 parent 25ebf0c commit f29e7ad

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

Diff for: commands/lib/resolve_deps.go

+33-1
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,43 @@ package lib
1919

2020
import (
2121
"context"
22+
"fmt"
2223

24+
"github.com/arduino/arduino-cli/arduino/libraries"
25+
"github.com/arduino/arduino-cli/commands"
2326
rpc "github.com/arduino/arduino-cli/rpc/commands"
2427
)
2528

2629
// LibraryResolveDependencies FIXMEDOC
2730
func LibraryResolveDependencies(ctx context.Context, req *rpc.LibraryResolveDependenciesReq) (*rpc.LibraryResolveDependenciesResp, error) {
28-
return &rpc.LibraryResolveDependenciesResp{}, nil
31+
lm := commands.GetLibraryManager(req.GetInstance().GetId())
32+
33+
// Search the requested lib
34+
reqLibRelease, err := findLibraryIndexRelease(lm, req)
35+
if err != nil {
36+
return nil, fmt.Errorf("looking for library: %s", err)
37+
}
38+
39+
// Extract all installed libraries
40+
installedLibs := map[string]*libraries.Library{}
41+
for _, lib := range listLibraries(lm, false, false) {
42+
installedLibs[lib.Library.Name] = lib.Library
43+
}
44+
45+
// Resolve all dependencies...
46+
deps := lm.Index.ResolveDependencies(reqLibRelease)
47+
res := []*rpc.LibraryDependencyStatus{}
48+
for _, dep := range deps {
49+
// ...and add information on currently installed versions of the libraries
50+
installed := ""
51+
if installedLib, has := installedLibs[dep.GetName()]; has {
52+
installed = installedLib.Version.String()
53+
}
54+
res = append(res, &rpc.LibraryDependencyStatus{
55+
Name: dep.GetName(),
56+
VersionRequired: dep.GetVersion().String(),
57+
VersionInstalled: installed,
58+
})
59+
}
60+
return &rpc.LibraryResolveDependenciesResp{Dependencies: res}, nil
2961
}

0 commit comments

Comments
 (0)