Skip to content

Commit 71ef562

Browse files
committed
Added gRPC LibraryUpgrade call and fixed 'lib upgrade' command
1 parent 22111d9 commit 71ef562

File tree

8 files changed

+918
-632
lines changed

8 files changed

+918
-632
lines changed

Diff for: cli/lib/upgrade.go

+18-9
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package lib
1717

1818
import (
19+
"context"
1920
"os"
2021

2122
"github.com/arduino/arduino-cli/cli/errorcodes"
@@ -46,19 +47,27 @@ func runUpgradeCommand(cmd *cobra.Command, args []string) {
4647
instance := instance.CreateAndInit()
4748
logrus.Info("Executing `arduino-cli lib upgrade`")
4849

50+
var upgradeErr error
4951
if len(args) == 0 {
50-
err := lib.LibraryUpgradeAll(&rpc.LibraryUpgradeAllRequest{Instance: instance}, output.ProgressBar(), output.TaskProgress())
51-
if err != nil {
52-
feedback.Errorf(tr("Error upgrading libraries: %v"), err)
53-
os.Exit(errorcodes.ErrGeneric)
54-
}
52+
req := &rpc.LibraryUpgradeAllRequest{Instance: instance}
53+
upgradeErr = lib.LibraryUpgradeAll(req, output.ProgressBar(), output.TaskProgress())
5554
} else {
56-
err := lib.LibraryUpgrade(instance.Id, args, output.ProgressBar(), output.TaskProgress())
57-
if err != nil {
58-
feedback.Errorf(tr("Error upgrading libraries: %v"), err)
59-
os.Exit(errorcodes.ErrGeneric)
55+
for _, libName := range args {
56+
req := &rpc.LibraryUpgradeRequest{
57+
Instance: instance,
58+
Name: libName,
59+
}
60+
upgradeErr = lib.LibraryUpgrade(context.Background(), req, output.ProgressBar(), output.TaskProgress())
61+
if upgradeErr != nil {
62+
break
63+
}
6064
}
6165
}
6266

67+
if upgradeErr != nil {
68+
feedback.Errorf("%s: %v", tr("Error upgrading libraries"), upgradeErr)
69+
os.Exit(errorcodes.ErrGeneric)
70+
}
71+
6372
logrus.Info("Done")
6473
}

Diff for: commands/daemon/daemon.go

+13
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,19 @@ func (s *ArduinoCoreServerImpl) LibraryInstall(req *rpc.LibraryInstallRequest, s
423423
return stream.Send(&rpc.LibraryInstallResponse{})
424424
}
425425

426+
// LibraryUpgrade FIXMEDOC
427+
func (s *ArduinoCoreServerImpl) LibraryUpgrade(req *rpc.LibraryUpgradeRequest, stream rpc.ArduinoCoreService_LibraryUpgradeServer) error {
428+
err := lib.LibraryUpgrade(
429+
stream.Context(), req,
430+
func(p *rpc.DownloadProgress) { stream.Send(&rpc.LibraryUpgradeResponse{Progress: p}) },
431+
func(p *rpc.TaskProgress) { stream.Send(&rpc.LibraryUpgradeResponse{TaskProgress: p}) },
432+
)
433+
if err != nil {
434+
return convertErrorToRPCStatus(err)
435+
}
436+
return stream.Send(&rpc.LibraryUpgradeResponse{})
437+
}
438+
426439
// LibraryUninstall FIXMEDOC
427440
func (s *ArduinoCoreServerImpl) LibraryUninstall(req *rpc.LibraryUninstallRequest, stream rpc.ArduinoCoreService_LibraryUninstallServer) error {
428441
err := lib.LibraryUninstall(stream.Context(), req,

Diff for: commands/lib/upgrade.go

+11-16
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package lib
1717

1818
import (
19+
"context"
1920
"errors"
2021

2122
"github.com/arduino/arduino-cli/arduino"
@@ -42,12 +43,15 @@ func LibraryUpgradeAll(req *rpc.LibraryUpgradeAllRequest, downloadCB rpc.Downloa
4243
return nil
4344
}
4445

45-
func LibraryUpgrade(lm *librariesmanager.LibrariesManager, libraryNames []string, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) error {
46+
// LibraryUpgrade upgrades a library
47+
func LibraryUpgrade(ctx context.Context, req *rpc.LibraryUpgradeRequest, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) error {
48+
lm := commands.GetLibraryManager(req)
49+
4650
// get the libs to upgrade
47-
libs := filterByName(listLibraries(lm, true, true), libraryNames)
51+
lib := filterByName(listLibraries(lm, true, true), req.GetName())
4852

4953
// do it
50-
return upgrade(lm, libs, downloadCB, taskCB)
54+
return upgrade(lm, []*installedLib{lib}, downloadCB, taskCB)
5155
}
5256

5357
func upgrade(lm *librariesmanager.LibrariesManager, libs []*installedLib, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) error {
@@ -70,20 +74,11 @@ func upgrade(lm *librariesmanager.LibrariesManager, libs []*installedLib, downlo
7074
return nil
7175
}
7276

73-
func filterByName(libs []*installedLib, names []string) []*installedLib {
74-
// put the names in a map to ease lookup
75-
queryMap := make(map[string]struct{})
76-
for _, name := range names {
77-
queryMap[name] = struct{}{}
78-
}
79-
80-
ret := []*installedLib{}
77+
func filterByName(libs []*installedLib, name string) *installedLib {
8178
for _, lib := range libs {
82-
// skip if library name wasn't in the query
83-
if _, found := queryMap[lib.Library.RealName]; found {
84-
ret = append(ret, lib)
79+
if lib.Library.RealName == name {
80+
return lib
8581
}
8682
}
87-
88-
return ret
83+
return nil
8984
}

Diff for: rpc/cc/arduino/cli/commands/v1/commands.pb.go

+174-163
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: rpc/cc/arduino/cli/commands/v1/commands.proto

+4
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ service ArduinoCoreService {
153153
rpc LibraryInstall(LibraryInstallRequest)
154154
returns (stream LibraryInstallResponse);
155155

156+
// Upgrade a library to the newest version available.
157+
rpc LibraryUpgrade(LibraryUpgradeRequest)
158+
returns (stream LibraryUpgradeResponse);
159+
156160
// Install a library from a Zip File
157161
rpc ZipLibraryInstall(ZipLibraryInstallRequest)
158162
returns (stream ZipLibraryInstallResponse);

Diff for: rpc/cc/arduino/cli/commands/v1/commands_grpc.pb.go

+70-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)