Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[breaking] daemon: Fix concurrency and streamline access to PackageManager #1828

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 17 commits into from
Aug 26, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Added gRPC LibraryUpgrade call and fixed 'lib upgrade' command
  • Loading branch information
cmaglie committed Aug 23, 2022
commit e8ef962b9e770733a13e0a643d2d097662884b3d
27 changes: 18 additions & 9 deletions 27 cli/lib/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package lib

import (
"context"
"os"

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

var upgradeErr error
if len(args) == 0 {
err := lib.LibraryUpgradeAll(&rpc.LibraryUpgradeAllRequest{Instance: instance}, output.ProgressBar(), output.TaskProgress())
if err != nil {
feedback.Errorf(tr("Error upgrading libraries: %v"), err)
os.Exit(errorcodes.ErrGeneric)
}
req := &rpc.LibraryUpgradeAllRequest{Instance: instance}
upgradeErr = lib.LibraryUpgradeAll(req, output.ProgressBar(), output.TaskProgress())
} else {
err := lib.LibraryUpgrade(instance.Id, args, output.ProgressBar(), output.TaskProgress())
if err != nil {
feedback.Errorf(tr("Error upgrading libraries: %v"), err)
os.Exit(errorcodes.ErrGeneric)
for _, libName := range args {
req := &rpc.LibraryUpgradeRequest{
Instance: instance,
Name: libName,
}
upgradeErr = lib.LibraryUpgrade(context.Background(), req, output.ProgressBar(), output.TaskProgress())
if upgradeErr != nil {
break
}
}
}

if upgradeErr != nil {
feedback.Errorf("%s: %v", tr("Error upgrading libraries"), upgradeErr)
os.Exit(errorcodes.ErrGeneric)
}

logrus.Info("Done")
}
13 changes: 13 additions & 0 deletions 13 commands/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,19 @@ func (s *ArduinoCoreServerImpl) LibraryInstall(req *rpc.LibraryInstallRequest, s
return stream.Send(&rpc.LibraryInstallResponse{})
}

// LibraryUpgrade FIXMEDOC
func (s *ArduinoCoreServerImpl) LibraryUpgrade(req *rpc.LibraryUpgradeRequest, stream rpc.ArduinoCoreService_LibraryUpgradeServer) error {
err := lib.LibraryUpgrade(
stream.Context(), req,
func(p *rpc.DownloadProgress) { stream.Send(&rpc.LibraryUpgradeResponse{Progress: p}) },
func(p *rpc.TaskProgress) { stream.Send(&rpc.LibraryUpgradeResponse{TaskProgress: p}) },
)
if err != nil {
return convertErrorToRPCStatus(err)
}
return stream.Send(&rpc.LibraryUpgradeResponse{})
}

// LibraryUninstall FIXMEDOC
func (s *ArduinoCoreServerImpl) LibraryUninstall(req *rpc.LibraryUninstallRequest, stream rpc.ArduinoCoreService_LibraryUninstallServer) error {
err := lib.LibraryUninstall(stream.Context(), req,
Expand Down
27 changes: 11 additions & 16 deletions 27 commands/lib/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package lib

import (
"context"
"errors"

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

func LibraryUpgrade(lm *librariesmanager.LibrariesManager, libraryNames []string, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) error {
// LibraryUpgrade upgrades a library
func LibraryUpgrade(ctx context.Context, req *rpc.LibraryUpgradeRequest, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) error {
lm := commands.GetLibraryManager(req)

// get the libs to upgrade
libs := filterByName(listLibraries(lm, true, true), libraryNames)
lib := filterByName(listLibraries(lm, true, true), req.GetName())

// do it
return upgrade(lm, libs, downloadCB, taskCB)
return upgrade(lm, []*installedLib{lib}, downloadCB, taskCB)
}

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

func filterByName(libs []*installedLib, names []string) []*installedLib {
// put the names in a map to ease lookup
queryMap := make(map[string]struct{})
for _, name := range names {
queryMap[name] = struct{}{}
}

ret := []*installedLib{}
func filterByName(libs []*installedLib, name string) *installedLib {
for _, lib := range libs {
// skip if library name wasn't in the query
if _, found := queryMap[lib.Library.RealName]; found {
ret = append(ret, lib)
if lib.Library.RealName == name {
return lib
}
}

return ret
return nil
}
337 changes: 174 additions & 163 deletions 337 rpc/cc/arduino/cli/commands/v1/commands.pb.go

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions 4 rpc/cc/arduino/cli/commands/v1/commands.proto
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ service ArduinoCoreService {
rpc LibraryInstall(LibraryInstallRequest)
returns (stream LibraryInstallResponse);

// Upgrade a library to the newest version available.
rpc LibraryUpgrade(LibraryUpgradeRequest)
returns (stream LibraryUpgradeResponse);

// Install a library from a Zip File
rpc ZipLibraryInstall(ZipLibraryInstallRequest)
returns (stream ZipLibraryInstallResponse);
Expand Down
75 changes: 70 additions & 5 deletions 75 rpc/cc/arduino/cli/commands/v1/commands_grpc.pb.go

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

Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.