Skip to content

Commit f4d8d91

Browse files
committed
Fix lib upgrade command not installing new libraries dependencies
1 parent 473a7a5 commit f4d8d91

File tree

2 files changed

+50
-17
lines changed

2 files changed

+50
-17
lines changed

Diff for: commands/lib/upgrade.go

+15-17
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@ package lib
1717

1818
import (
1919
"context"
20-
"errors"
2120

2221
"github.com/arduino/arduino-cli/arduino"
23-
"github.com/arduino/arduino-cli/arduino/libraries"
24-
"github.com/arduino/arduino-cli/arduino/libraries/librariesmanager"
2522
"github.com/arduino/arduino-cli/commands"
2623
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
2724
)
@@ -33,7 +30,7 @@ func LibraryUpgradeAll(req *rpc.LibraryUpgradeAllRequest, downloadCB rpc.Downloa
3330
return &arduino.InvalidInstanceError{}
3431
}
3532

36-
if err := upgrade(lm, listLibraries(lm, true, false), downloadCB, taskCB); err != nil {
33+
if err := upgrade(req.Instance, listLibraries(lm, true, false), downloadCB, taskCB); err != nil {
3734
return err
3835
}
3936

@@ -47,6 +44,9 @@ func LibraryUpgradeAll(req *rpc.LibraryUpgradeAllRequest, downloadCB rpc.Downloa
4744
// LibraryUpgrade upgrades a library
4845
func LibraryUpgrade(ctx context.Context, req *rpc.LibraryUpgradeRequest, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) error {
4946
lm := commands.GetLibraryManager(req)
47+
if lm == nil {
48+
return &arduino.InvalidInstanceError{}
49+
}
5050

5151
// Get the library to upgrade
5252
name := req.GetName()
@@ -61,23 +61,21 @@ func LibraryUpgrade(ctx context.Context, req *rpc.LibraryUpgradeRequest, downloa
6161
}
6262

6363
// Install update
64-
return upgrade(lm, []*installedLib{lib}, downloadCB, taskCB)
64+
return upgrade(req.Instance, []*installedLib{lib}, downloadCB, taskCB)
6565
}
6666

67-
func upgrade(lm *librariesmanager.LibrariesManager, libs []*installedLib, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) error {
68-
// Go through the list and download them
67+
func upgrade(instance *rpc.Instance, libs []*installedLib, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) error {
6968
for _, lib := range libs {
70-
if err := downloadLibrary(lm, lib.Available, downloadCB, taskCB); err != nil {
71-
return err
69+
libInstallReq := &rpc.LibraryInstallRequest{
70+
Instance: instance,
71+
Name: lib.Library.Name,
72+
Version: "",
73+
NoDeps: false,
74+
NoOverwrite: false,
7275
}
73-
}
74-
75-
// Go through the list and install them
76-
for _, lib := range libs {
77-
if err := installLibrary(lm, lib.Available, libraries.User, taskCB); err != nil {
78-
if !errors.Is(err, librariesmanager.ErrAlreadyInstalled) {
79-
return err
80-
}
76+
err := LibraryInstall(context.Background(), libInstallReq, downloadCB, taskCB)
77+
if err != nil {
78+
return err
8179
}
8280
}
8381

Diff for: internal/integrationtest/lib/lib_test.go

+35
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,38 @@ func TestLibDepsOutput(t *testing.T) {
199199
require.Equal(t, "WiFiNINA", jsonDeps.Dependencies[6].Name)
200200
require.Equal(t, jsonDeps.Dependencies[6].VersionInstalled, jsonDeps.Dependencies[6].VersionRequired)
201201
}
202+
203+
func TestUpgradeLibraryWithDependencies(t *testing.T) {
204+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
205+
defer env.CleanUp()
206+
207+
// Updates index for cores and libraries
208+
_, _, err := cli.Run("core", "update-index")
209+
require.NoError(t, err)
210+
_, _, err = cli.Run("lib", "update-index")
211+
require.NoError(t, err)
212+
213+
// Install library
214+
_, _, err = cli.Run("lib", "install", "[email protected]")
215+
require.NoError(t, err)
216+
stdOut, _, err := cli.Run("lib", "deps", "[email protected]", "--format", "json")
217+
require.NoError(t, err)
218+
expectedOutput := `{"dependencies":[
219+
{"name":"Arduino_ConnectionHandler","version_required":"0.3.3","version_installed":"0.3.3"},
220+
{"name":"Arduino_DebugUtils","version_required":"1.3.0","version_installed":"1.3.0"},
221+
{"name":"MKRGSM","version_required":"1.5.0","version_installed":"1.5.0"},
222+
{"name":"MKRNB","version_required":"1.5.1","version_installed":"1.5.1"},
223+
{"name":"WiFi101","version_required":"0.16.1","version_installed":"0.16.1"},
224+
{"name":"WiFiNINA","version_required":"1.8.13","version_installed":"1.8.13"}]}`
225+
require.JSONEq(t, expectedOutput, string(stdOut))
226+
227+
// Test lib upgrade also install new dependencies of already installed library
228+
_, _, err = cli.Run("lib", "upgrade", "Arduino_ConnectionHandler")
229+
require.NoError(t, err)
230+
stdOut, _, err = cli.Run("lib", "deps", "Arduino_ConnectionHandler", "--format", "json")
231+
require.NoError(t, err)
232+
233+
jsonOut := requirejson.Parse(t, stdOut)
234+
dependency := jsonOut.Query(`.dependencies[] | select(.name=="MKRWAN")`)
235+
require.Equal(t, dependency.Query(".version_required"), dependency.Query(".version_installed"))
236+
}

0 commit comments

Comments
 (0)