8000 [BREAKING] gRPC / golang Configuration API refactoring by cmaglie · Pull Request #2565 · arduino/arduino-cli · GitHub
[go: up one dir, main page]

Skip to content

[BREAKING] gRPC / golang Configuration API refactoring #2565

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 56 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
8c07823
Moved a batch of function from commands/* subpackage to commands
cmaglie Mar 13, 2024
3d8f50a
Moved a batch of function from commands/* subpackage to commands (par…
cmaglie Mar 13, 2024
3ff8e09
Moved a batch of function from commands/* subpackage to commands (par…
cmaglie Mar 13, 2024
8615985
Moved a batch of function from commands/* subpackage to commands (par…
cmaglie Mar 13, 2024
61e5c46
Moved a batch of function from commands/* subpackage to commands (par…
cmaglie Mar 13, 2024
9e75b4d
Removed unused parameters
cmaglie Mar 13, 2024
f1a015c
Removed unused file
cmaglie Mar 13, 2024
c4ca852
Removed ToRPCStatus in favor of standardized GRPCStatus() interface
cmaglie Mar 13, 2024
23ccd43
Inlining methods in ArduinoCoreServiceImpl (part 1: BoardListAll)
cmaglie Mar 13, 2024
53f03e5
Inlining methods in ArduinoCoreServiceImpl (part 2: BoardDetails)
cmaglie Mar 13, 2024
0df2149
Inlining methods in ArduinoCoreServiceImpl (part 3: BoardList)
cmaglie Mar 13, 2024
f65eff2
Inlining methods in ArduinoCoreServiceImpl (part 4: BoardListWatch)
cmaglie Mar 14, 2024
06d6842
Inlining methods in ArduinoCoreServiceImpl (part 5: Create and Destroy)
cmaglie Mar 14, 2024
8bd0eef
Follow convetion where context must be the first argument
cmaglie Mar 14, 2024
a81069d
Inlining methods in ArduinoCoreServiceImpl (part 6: Init)
cmaglie Mar 14, 2024
917dcc5
Inlining methods in ArduinoCoreServiceImpl (part 7: UpdateIndex)
cmaglie Mar 14, 2024
bb815cf
Inlining methods in ArduinoCoreServiceImpl (part 8: Monitor)
cmaglie Mar 15, 2024
0e434f2
Inlining methods in ArduinoCoreServiceImpl (part 9: Compile)
cmaglie Mar 18, 2024
12cf52e
Inlining methods in ArduinoCoreServiceImpl (part 10: PlatformInstall,…
cmaglie Mar 18, 2024
cfe4b27
Inlining methods in ArduinoCoreServiceImpl (part 11: LibraryDownload,…
cmaglie Mar 18, 2024
a3800fa
Inlining methods in ArduinoCoreServiceImpl (part 12: UpdateLibrariesI…
cmaglie Mar 18, 2024
738ad7c
Inlining methods in ArduinoCoreServiceImpl (part 13: NewSketch, LoadS…
cmaglie Mar 18, 2024
0442319
Inlining methods in ArduinoCoreServiceImpl (part 14: Upload, UploadUs…
cmaglie Mar 18, 2024
65ecbaf
Inlining methods in ArduinoCoreServiceImpl (part 15: SupportedUserFie…
cmaglie Mar 18, 2024
0bdc07a
Inlining methods in ArduinoCoreServiceImpl (part 16: CleanDownloadCac…
cmaglie Mar 25, 2024
3193b7c
Made utility functions private and put them in their own file
cmaglie Mar 18, 2024
c08c59e
Run tests forcing the english language
cmaglie Mar 20, 2024
e8e1574
Use correct env var to force configuration in integration test
cmaglie Apr 19, 2024
9bab3c5
Fixed markdown link
cmaglie Apr 19, 2024
6320f6e
Always use arduino-cli in user-agent string
cmaglie Apr 19, 2024
1fddba7
Removed global *viper.Viper settings instance
cmaglie Mar 20, 2024
4c50868
Implementation of Viper replacement library
cmaglie Apr 17, 2024
0453677
Use custom type to avoid context-values collisions
cmaglie Apr 22, 2024
61b66a7
Fixed test
cmaglie Apr 19, 2024
087a6f5
Fixed FindConfigFileInArgsFallbackOnEnv unit test
cmaglie Apr 19, 2024
9cd9c97
Fixed TestUserAgentHeader and TestProxy
cmaglie Apr 19, 2024
384c30c
Improved error message
cmaglie Apr 21, 2024
6aa742f
Config set adds only unique values
cmaglie Apr 21, 2024
0aafda3
Fixed initialization sequence for 'config init' command
cmaglie Apr 21, 2024
921fa61
Config search now looks into ARDUINO_DIRECTORIES_DATA env too
cmaglie Apr 21, 2024
ad8dbd9
Fixed all config* integration test
cmaglie Apr 21, 2024
4061131
Added missing type schema
cmaglie Apr 21, 2024
fa835de
Added docs
cmaglie Apr 23, 2024
72e05ee
Updated documentation about configuration file format
cmaglie Apr 29, 2024
89a79cb
Fixed a small imperfection in test
cmaglie Apr 30, 2024
240c8b3
Pass context in upload and burn-bootloader
cmaglie Apr 30, 2024
24ac040
Pass down context in all places where it's needed
cmaglie Apr 30, 2024
6cf4eb7
Removed unused parameter
cmaglie Apr 30, 2024
27e9c3e
Tolerate errors in invalid config files, and report them as warnings
cmaglie May 2, 2024
7658db6
Improved handling of incomplete configs array
cmaglie May 2, 2024
a58c350
Disable logging until it is setup in the arduino-cli pre-run
cmaglie May 6, 2024
9585728
Show config-load warning after feedback package initialization
cmaglie May 6, 2024
b279d4b
Fixed 'feedback' package initialization order
cmaglie May 6, 2024
278a331
Applied changes from code review
cmaglie May 6, 2024
c355478
Updated client_example
cmaglie May 6, 2024
cec1fdb
Improved array handling in configmap, and unit-tests
cmaglie May 6, 2024
File filter
8000

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
Inlining methods in ArduinoCoreServiceImpl (part 6: Init)
Added helpers to get init progress.
  • Loading branch information
cmaglie committed May 6, 2024
commit a81069dda0cfc5090b12796fb3a7c00a22417228
42 changes: 42 additions & 0 deletions commands/grpc_streaming_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,45 @@ func (w *streamingResponseProxyToChan[T]) SetHeader(metadata.MD) error {

func (w *streamingResponseProxyToChan[T]) SetTrailer(tr metadata.MD) {
}

// streamingResponseProxyToCallback is a streaming response proxy that
// forwards the responses to a callback function
type streamingResponseProxyToCallback[T any] struct {
ctx context.Context
cb func(*T) error
}

// creates a streaming response proxy that forwards the responses to a callback function
func streamResponseToCallback[T any](ctx context.Context, cb func(*T) error) *streamingResponseProxyToCallback[T] {
if cb == nil {
cb = func(*T) error { return nil }
}
return &streamingResponseProxyToCallback[T]{ctx: ctx, cb: cb}
}

func (w *streamingResponseProxyToCallback[T]) Send(resp *T) error {
return w.cb(resp)
}

func (w *streamingResponseProxyToCallback[T]) Context() context.Context {
return w.ctx
}

func (w *streamingResponseProxyToCallback[T]) RecvMsg(m any) error {
return errors.New("RecvMsg not implemented")
}

func (w *streamingResponseProxyToCallback[T]) SendHeader(metadata.MD) error {
return errors.New("SendHeader not implemented")
}

func (w *streamingResponseProxyToCallback[T]) SendMsg(m any) error {
return errors.New("SendMsg not implemented")
}

func (w *streamingResponseProxyToCallback[T]) SetHeader(metadata.MD) error {
return errors.New("SetHeader not implemented")
}

func (w *streamingResponseProxyToCallback[T]) SetTrailer(tr metadata.MD) {
}
19 changes: 13 additions & 6 deletions commands/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,23 +96,30 @@ func (s *arduinoCoreServerImpl) Create(ctx context.Context, req *rpc.CreateReque
return &rpc.CreateResponse{Instance: inst}, nil
}

// InitStreamResponseToCallbackFunction returns a gRPC stream to be used in Init that sends
// all responses to the callback function.
func InitStreamResponseToCallbackFunction(ctx context.Context, cb func(r *rpc.InitResponse) error) rpc.ArduinoCoreService_InitServer {
return streamResponseToCallback(ctx, cb)
}

// Init loads installed libraries and Platforms in CoreInstance with specified ID,
// a gRPC status error is returned if the CoreInstance doesn't exist.
// All responses are sent through responseCallback, can be nil to ignore all responses.
// Failures don't stop the loading process, in case of loading failure the Platform or library
// is simply skipped and an error gRPC status is sent to responseCallback.
func Init(req *rpc.InitRequest, responseCallback func(r *rpc.InitResponse)) error {
if responseCallback == nil {
responseCallback = func(r *rpc.InitResponse) {}
}
func (s *arduinoCoreServerImpl) Init(req *rpc.InitRequest, stream rpc.ArduinoCoreService_InitServer) error {
instance := req.GetInstance()
if !instances.IsValid(instance) {
return &cmderrors.InvalidInstanceError{}
}

// Setup callback functions
if responseCallback == nil {
responseCallback = func(r *rpc.InitResponse) {}
var responseCallback func(*rpc.InitResponse) error
if stream != nil {
syncSend := NewSynchronizedSend(stream.Send)
responseCallback = syncSend.Send
} else {
responseCallback = func(*rpc.InitResponse) error { return nil }
}
responseError := func(st *status.Status) {
responseCallback(&rpc.InitResponse{
Expand Down
18 changes: 6 additions & 12 deletions commands/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,6 @@ func (s *arduinoCoreServerImpl) UpdateLibrariesIndex(req *rpc.UpdateLibrariesInd
return err
}

// Init FIXMEDOC
func (s *arduinoCoreServerImpl) Init(req *rpc.InitRequest, stream rpc.ArduinoCoreService_InitServer) error {
syncSend := NewSynchronizedSend(stream.Send)
return Init(req, func(message *rpc.InitResponse) { syncSend.Send(message) })
}

// Version FIXMEDOC
func (s *arduinoCoreServerImpl) Version(ctx context.Context, req *rpc.VersionRequest) (*rpc.VersionResponse, error) {
return &rpc.VersionResponse{Version: s.versionString}, nil
Expand Down Expand Up @@ -144,7 +138,7 @@ func (s *arduinoCoreServerImpl) Compile(req *rpc.CompileRequest, stream rpc.Ardu
func (s *arduinoCoreServerImpl) PlatformInstall(req *rpc.PlatformInstallRequest, stream rpc.ArduinoCoreService_PlatformInstallServer) error {
syncSend := NewSynchronizedSend(stream.Send)
resp, err := PlatformInstall(
stream.Context(), req,
stream.Context(), s, req,
func(p *rpc.DownloadProgress) { syncSend.Send(&rpc.PlatformInstallResponse{Progress: p}) },
func(p *rpc.TaskProgress) { syncSend.Send(&rpc.PlatformInstallResponse{TaskProgress: p}) },
)
Expand All @@ -171,7 +165,7 @@ func (s *arduinoCoreServerImpl) PlatformDownload(req *rpc.PlatformDownloadReques
func (s *arduinoCoreServerImpl) PlatformUninstall(req *rpc.PlatformUninstallRequest, stream rpc.ArduinoCoreService_PlatformUninstallServer) error {
syncSend := NewSynchronizedSend(stream.Send)
resp, err := PlatformUninstall(
stream.Context(), req,
stream.Context(), s, req,
func(p *rpc.TaskProgress) { syncSend.Send(&rpc.PlatformUninstallResponse{TaskProgress: p}) },
)
if err != nil {
Expand All @@ -184,7 +178,7 @@ func (s *arduinoCoreServerImpl) PlatformUninstall(req *rpc.PlatformUninstallRequ
func (s *arduinoCoreServerImpl) PlatformUpgrade(req *rpc.PlatformUpgradeRequest, stream rpc.ArduinoCoreService_PlatformUpgradeServer) error {
syncSend := NewSynchronizedSend(stream.Send)
resp, err := PlatformUpgrade(
stream.Context(), req,
stream.Context(), s, req,
func(p *rpc.DownloadProgress) { syncSend.Send(&rpc.PlatformUpgradeResponse{Progress: p}) },
func(p *rpc.TaskProgress) { syncSend.Send(&rpc.PlatformUpgradeResponse{TaskProgress: p}) },
)
Expand Down Expand Up @@ -304,7 +298,7 @@ func (s *arduinoCoreServerImpl) LibraryDownload(req *rpc.LibraryDownloadRequest,
func (s *arduinoCoreServerImpl) LibraryInstall(req *rpc.LibraryInstallRequest, stream rpc.ArduinoCoreService_LibraryInstallServer) error {
syncSend := NewSynchronizedSend(stream.Send)
return LibraryInstall(
stream.Context(), req,
stream.Context(), s, req,
func(p *rpc.DownloadProgress) { syncSend.Send(&rpc.LibraryInstallResponse{Progress: p}) },
func(p *rpc.TaskProgress) { syncSend.Send(&rpc.LibraryInstallResponse{TaskProgress: p}) },
)
Expand All @@ -314,7 +308,7 @@ func (s *arduinoCoreServerImpl) LibraryInstall(req *rpc.LibraryInstallRequest, s
func (s *arduinoCoreServerImpl) LibraryUpgrade(req *rpc.LibraryUpgradeRequest, stream rpc.ArduinoCoreService_LibraryUpgradeServer) error {
syncSend := NewSynchronizedSend(stream.Send)
return LibraryUpgrade(
stream.Context(), req,
stream.Context(), s, req,
func(p *rpc.DownloadProgress) { syncSend.Send(&rpc.LibraryUpgradeResponse{Progress: p}) },
func(p *rpc.TaskProgress) { syncSend.Send(&rpc.LibraryUpgradeResponse{TaskProgress: p}) },
)
Expand All @@ -331,7 +325,7 @@ func (s *arduinoCoreServerImpl) LibraryUninstall(req *rpc.LibraryUninstallReques
// LibraryUpgradeAll FIXMEDOC
func (s *arduinoCoreServerImpl) LibraryUpgradeAll(req *rpc.LibraryUpgradeAllRequest, stream rpc.ArduinoCoreService_LibraryUpgradeAllServer) error {
syncSend := NewSynchronizedSend(stream.Send)
return LibraryUpgradeAll(req,
return LibraryUpgradeAll(s, req,
func(p *rpc.DownloadProgress) { syncSend.Send(&rpc.LibraryUpgradeAllResponse{Progress: p}) },
func(p *rpc.TaskProgress) { syncSend.Send(&rpc.LibraryUpgradeAllResponse{TaskProgress: p}) },
)
Expand Down
5 changes: 3 additions & 2 deletions commands/service_library_install.go
F438
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
)

// LibraryInstall resolves the library dependencies, then downloads and installs the libraries into the install location.
func LibraryInstall(ctx context.Context, req *rpc.LibraryInstallRequest, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) error {
func LibraryInstall(ctx context.Context, srv rpc.ArduinoCoreServiceServer, req *rpc.LibraryInstallRequest, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) error {
// Obtain the library index from the manager
li, err := instances.GetLibrariesIndex(req.GetInstance())
if err != nil {
Expand Down Expand Up @@ -136,7 +136,8 @@ func LibraryInstall(ctx context.Context, req *rpc.LibraryInstallRequest, downloa
}
}

if err := Init(&rpc.InitRequest{Instance: req.GetInstance()}, nil); err != nil {
stream := InitStreamResponseToCallbackFunction(ctx, nil)
if err := srv.Init(&rpc.InitRequest{Instance: req.GetInstance()}, stream); err != nil {
return err
}

Expand Down
17 changes: 10 additions & 7 deletions commands/service_library_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ import (
)

// LibraryUpgradeAll upgrades all the available libraries
func LibraryUpgradeAll(req *rpc.LibraryUpgradeAllRequest, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) error {
func LibraryUpgradeAll(srv rpc.ArduinoCoreServiceServer, req *rpc.LibraryUpgradeAllRequest, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) error {
ctx := context.Background()

li, err := instances.GetLibrariesIndex(req.GetInstance())
if err != nil {
return err
Expand All @@ -37,19 +39,20 @@ func LibraryUpgradeAll(req *rpc.LibraryUpgradeAllRequest, downloadCB rpc.Downloa
libsToUpgrade := listLibraries(lme, li, true, false)
release()

if err := upgrade(req.GetInstance(), libsToUpgrade, downloadCB, taskCB); err != nil {
if err := upgrade(ctx, srv, req.GetInstance(), libsToUpgrade, downloadCB, taskCB); err != nil {
return err
}

if err := Init(&rpc.InitRequest{Instance: req.GetInstance()}, nil); err != nil {
stream := InitStreamResponseToCallbackFunction(ctx, nil)
if err := srv.Init(&rpc.InitRequest{Instance: req.GetInstance()}, stream); err != nil {
return err
}

return nil
}

// LibraryUpgrade upgrades a library
func LibraryUpgrade(ctx context.Context, req *rpc.LibraryUpgradeRequest, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) error {
func LibraryUpgrade(ctx context.Context, srv rpc.ArduinoCoreServiceServer, req *rpc.LibraryUpgradeRequest, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) error {
li, err := instances.GetLibrariesIndex(req.GetInstance())
if err != nil {
return err
Expand All @@ -75,10 +78,10 @@ func LibraryUpgrade(ctx context.Context, req *rpc.LibraryUpgradeRequest, downloa
}

// Install update
return upgrade(req.GetInstance(), []*installedLib{lib}, downloadCB, taskCB)
return upgrade(ctx, srv, req.GetInstance(), []*installedLib{lib}, downloadCB, taskCB)
}

func upgrade(instance *rpc.Instance, libs []*installedLib, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) error {
func upgrade(ctx context.Context, srv rpc.ArduinoCoreServiceServer, instance *rpc.Instance, libs []*installedLib, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) error {
for _, lib := range libs {
libInstallReq := &rpc.LibraryInstallRequest{
Instance: instance,
Expand All @@ -87,7 +90,7 @@ func upgrade(instance *rpc.Instance, libs []*installedLib, downloadCB rpc.Downlo
NoDeps: false,
NoOverwrite: false,
}
err := LibraryInstall(context.Background(), libInstallReq, downloadCB, taskCB)
err := LibraryInstall(ctx, srv, libInstallReq, downloadCB, taskCB)
if err != nil {
return err
}
Expand Down
6 changes: 4 additions & 2 deletions commands/service_platform_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
)

// PlatformInstall FIXMEDOC
func PlatformInstall(ctx context.Context, req *rpc.PlatformInstallRequest, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) (*rpc.PlatformInstallResponse, error) {
func PlatformInstall(ctx context.Context, srv rpc.ArduinoCoreServiceServer, req *rpc.PlatformInstallRequest, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) (*rpc.PlatformInstallResponse, error) {
install := func() error {
pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance())
if err != nil {
Expand Down Expand Up @@ -73,7 +73,9 @@ func PlatformInstall(ctx context.Context, req *rpc.PlatformInstallRequest, downl
if err := install(); err != nil {
return nil, err
}
if err := Init(&rpc.InitRequest{Instance: req.GetInstance()}, nil); err != nil {

stream := InitStreamResponseToCallbackFunction(ctx, nil)
if err := srv.Init(&rpc.InitRequest{Instance: req.GetInstance()}, stream); err != nil {
return nil, err
}
return &rpc.PlatformInstallResponse{}, nil
Expand Down
4 changes: 2 additions & 2 deletions commands/service_platform_search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestPlatformSearch(t *testing.T) {
inst := createResp.GetInstance()
require.NotNil(t, inst)

err = Init(&rpc.InitRequest{Instance: inst}, nil)
err = srv.Init(&rpc.InitRequest{Instance: inst}, InitStreamResponseToCallbackFunction(ctx, nil))
require.NoError(t, err)

t.Run("SearchAllVersions", func(t *testing.T) {
Expand Down Expand Up @@ -347,7 +347,7 @@ func TestPlatformSearchSorting(t *testing.T) {
require.NoError(t, err)
inst := createResp.GetInstance()
require.NotNil(t, inst)
err = Init(&rpc.InitRequest{Instance: inst}, nil)
err = srv.Init(&rpc.InitRequest{Instance: inst}, InitStreamResponseToCallbackFunction(ctx, nil))
require.NoError(t, err)

res, stat := PlatformSearch(&rpc.PlatformSearchRequest{
Expand Down
4 changes: 2 additions & 2 deletions commands/service_platform_uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import (
)

// PlatformUninstall FIXMEDOC
func PlatformUninstall(ctx context.Context, req *rpc.PlatformUninstallRequest, taskCB rpc.TaskProgressCB) (*rpc.PlatformUninstallResponse, error) {
func PlatformUninstall(ctx context.Context, srv rpc.ArduinoCoreServiceServer, req *rpc.PlatformUninstallRequest, taskCB rpc.TaskProgressCB) (*rpc.PlatformUninstallResponse, error) {
if err := platformUninstall(req, taskCB); err != nil {
return nil, err
}
if err := Init(&rpc.InitRequest{Instance: req.GetInstance()}, nil); err != nil {
if err := srv.Init(&rpc.InitRequest{Instance: req.GetInstance()}, InitStreamResponseToCallbackFunction(ctx, nil)); err != nil {
return nil, err
}
return &rpc.PlatformUninstallResponse{}, nil
Expand Down
4 changes: 2 additions & 2 deletions commands/service_platform_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
)

// PlatformUpgrade FIXMEDOC
func PlatformUpgrade(ctx context.Context, req *rpc.PlatformUpgradeRequest, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) (*rpc.PlatformUpgradeResponse, error) {
func PlatformUpgrade(ctx context.Context, srv rpc.ArduinoCoreServiceServer, req *rpc.PlatformUpgradeRequest, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) (*rpc.PlatformUpgradeResponse, error) {
upgrade := func() (*cores.PlatformRelease, error) {
pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance())
if err != nil {
Expand Down Expand Up @@ -57,7 +57,7 @@ func PlatformUpgrade(ctx context.Context, req *rpc.PlatformUpgradeRequest, downl
if err != nil {
return &rpc.PlatformUpgradeResponse{Platform: rpcPlatform}, err
}
if err := Init(&rpc.InitRequest{Instance: req.GetInstance()}, nil); err != nil {
if err := srv.Init(&rpc.InitRequest{Instance: req.GetInstance()}, InitStreamResponseToCallbackFunction(ctx, nil)); err != nil {
return nil, err
}

Expand Down
2 changes: 1 addition & 1 deletion internal/cli/core/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func runInstallCommand(srv rpc.ArduinoCoreServiceServer, args []string, scriptFl
NoOverwrite: noOverwrite,
SkipPreUninstall: scriptFlags.DetectSkipPreUninstallValue(),
}
_, err := commands.PlatformInstall(context.Background(), platformInstallRequest, feedback.ProgressBar(), feedback.TaskProgress())
_, err := commands.PlatformInstall(ctx, srv, platformInstallRequest, feedback.ProgressBar(), feedback.TaskProgress())
if err != nil {
feedback.Fatal(tr("Error during install: %v", err), feedback.ErrGeneric)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/core/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func runSearchCommand(srv rpc.ArduinoCoreServiceServer, args []string, allVersio
for _, idxRes := range res.GetUpdatedIndexes() {
if idxRes.GetStatus() == rpc.IndexUpdateReport_STATUS_UPDATED {
// At least one index has been updated, reinitialize the instance
instance.Init(inst)
instance.Init(ctx, srv, inst)
break
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/core/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func runUninstallCommand(srv rpc.ArduinoCoreServiceServer, args []string, preUni
}
}
for _, platformRef := range platformsRefs {
_, err := commands.PlatformUninstall(context.Background(), &rpc.PlatformUninstallRequest{
_, err := commands.PlatformUninstall(ctx, srv, &rpc.PlatformUninstallRequest{
Instance: inst,
PlatformPackage: platformRef.PackageName,
Architecture: platformRef.Architecture,
< 10000 /a> Expand Down
2 changes: 1 addition & 1 deletion internal/cli/core/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func Upgrade(ctx context.Context, srv rpc.ArduinoCoreServiceServer, inst *rpc.In
SkipPostInstall: skipPostInstall,
SkipPreUninstall: skipPreUninstall,
}
response, err := commands.PlatformUpgrade(context.Background(), r, feedback.ProgressBar(), feedback.TaskProgress())
response, err := commands.PlatformUpgrade(ctx, srv, r, feedback.ProgressBar(), feedback.TaskProgress())
warningMissingIndex(response)
if err != nil {
var alreadyAtLatestVersionErr *cmderrors.PlatformAlreadyAtTheLatestVersionError
Expand Down
13 changes: 7 additions & 6 deletions internal/cli/instance/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func CreateAndInitWithProfile(ctx context.Context, srv rpc.ArduinoCoreServiceSer
if err != nil {
feedback.Fatal(tr("Error creating instance: %v", err), feedback.ErrGeneric)
}
profile := InitWithProfile(instance, profileName, sketchPath)
profile := InitWithProfile(ctx, srv, instance, profileName, sketchPath)
return instance, profile
}

Expand All @@ -62,14 +62,14 @@ func create(ctx context.Context, srv rpc.ArduinoCoreServiceServer) (*rpc.Instanc
// platform or library that we failed to load.
// Package and library indexes files are automatically updated if the
// CLI is run for the first time.
func Init(instance *rpc.Instance) {
InitWithProfile(instance, "", nil)
func Init(ctx context.Context, srv rpc.ArduinoCoreServiceServer, instance *rpc.Instance) {
InitWithProfile(ctx, srv, instance, "", nil)
}

// InitWithProfile initializes instance by loading libraries and platforms specified in the given profile of the given sketch.
// In case of loading failures return a list of errors for each platform or library that we failed to load.
// Required Package and library indexes files are automatically downloaded.
func InitWithProfile(instance *rpc.Instance, profileName string, sketchPath *paths.Path) *rpc.SketchProfile {
func InitWithProfile(ctx context.Context, srv rpc.ArduinoCoreServiceServer, instance *rpc.Instance, profileName string, sketchPath *paths.Path) *rpc.SketchProfile {
downloadCallback := feedback.ProgressBar()
taskCallback := feedback.TaskProgress()

Expand All @@ -79,7 +79,7 @@ func InitWithProfile(instance *rpc.Instance, profileName string, sketchPath *pat
initReq.Profile = profileName
}
var profile *rpc.SketchProfile
err := commands.Init(initReq, func(res *rpc.InitResponse) {
err := srv.Init(initReq, commands.InitStreamResponseToCallbackFunction(ctx, func(res *rpc.InitResponse) error {
if st := res.GetError(); st != nil {
feedback.Warning(tr("Error initializing instance: %v", st.GetMessage()))
}
Expand All @@ -96,7 +96,8 @@ func InitWithProfile(instance *rpc.Instance, profileName string, sketchPath *pat
if p := res.GetProfile(); p != nil {
profile = p
}
})
return nil
}))
if err != nil {
feedback.Warning(tr("Error initializing instance: %v", err))
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/lib/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func runInstallCommand(srv rpc.ArduinoCoreServiceServer, args []string, noDeps b
NoOverwrite: noOverwrite,
InstallLocation: installLocation,
}
err := commands.LibraryInstall(context.Background(), libraryInstallRequest, feedback.ProgressBar(), feedback.TaskProgress())
err := commands.LibraryInstall(ctx, srv, libraryInstallRequest, feedback.ProgressBar(), feedback.TaskProgress())
if err != nil {
feedback.Fatal(tr("Error installing %s: %v", libRef.Name, err), feedback.ErrGeneric)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/lib/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func runSearchCommand(srv rpc.ArduinoCoreServiceServer, args []string, namesOnly
feedback.Fatal(tr("Error updating library index: %v", err), feedback.ErrGeneric)
}
if res.GetLibrariesIndex().GetStatus() == rpc.IndexUpdateReport_STATUS_UPDATED {
instance.Init(inst)
instance.Init(ctx, srv, inst)
}

searchResp, err := commands.LibrarySearch(context.Background(), &rpc.LibrarySearchRequest{
Expand Down
Loading
0