Skip to content

Commit 304c554

Browse files
committed
Fix lib upgrade command not installing new libraries dependencies
1 parent 43ba63f commit 304c554

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
@@ -182,3 +182,38 @@ func TestLibDepsOutput(t *testing.T) {
182182
{"name":"WiFiNINA","version_required":"1.8.13","version_installed":"1.8.13"}]}`
183183
require.JSONEq(t, expectedOutput, string(stdOut))
184184
}
185+
186+
func TestUpgradeLibraryWithDependencies(t *testing.T) {
187+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
188+
defer env.CleanUp()
189+
190+
// Updates index for cores and libraries
191+
_, _, err := cli.Run("core", "update-index")
192+
require.NoError(t, err)
193+
_, _, err = cli.Run("lib", "update-index")
194+
require.NoError(t, err)
195+
196+
// Install library
197+
_, _, err = cli.Run("lib", "install", "[email protected]")
198+
require.NoError(t, err)
199+
stdOut, _, err := cli.Run("lib", "deps", "[email protected]", "--format", "json")
200+
require.NoError(t, err)
201+
expectedOutput := `{"dependencies":[
202+
{"name":"Arduino_ConnectionHandler","version_required":"0.3.3","version_installed":"0.3.3"},
203+
{"name":"Arduino_DebugUtils","version_required":"1.3.0","version_installed":"1.3.0"},
204+
{"name":"MKRGSM","version_required":"1.5.0","version_installed":"1.5.0"},
205+
{"name":"MKRNB","version_required":"1.5.1","version_installed":"1.5.1"},
206+
{"name":"WiFi101","version_required":"0.16.1","version_installed":"0.16.1"},
207+
{"name":"WiFiNINA","version_required":"1.8.13","version_installed":"1.8.13"}]}`
208+
require.JSONEq(t, expectedOutput, string(stdOut))
209+
210+
// Test lib upgrade also install new dependencies of already installed library
211+
_, _, err = cli.Run("lib", "upgrade", "Arduino_ConnectionHandler")
212+
require.NoError(t, err)
213+
stdOut, _, err = cli.Run("lib", "deps", "Arduino_ConnectionHandler", "--format", "json")
214+
require.NoError(t, err)
215+
216+
jsonOut := requirejson.Parse(t, stdOut)
217+
dependency := jsonOut.Query(`.dependencies[] | select(.name=="MKRWAN")`)
218+
require.Equal(t, dependency.Query(".version_required"), dependency.Query(".version_installed"))
219+
}

0 commit comments

Comments
 (0)