Unverified Commit 5efa9b5d authored by Silvano Cerza's avatar Silvano Cerza Committed by GitHub

bugfix: `lib upgrade` command does not install new libraries dependencies (#1935)

parent 120b8525
......@@ -17,11 +17,8 @@ package lib
import (
"context"
"errors"
"github.com/arduino/arduino-cli/arduino"
"github.com/arduino/arduino-cli/arduino/libraries"
"github.com/arduino/arduino-cli/arduino/libraries/librariesmanager"
"github.com/arduino/arduino-cli/commands"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
)
......@@ -33,7 +30,7 @@ func LibraryUpgradeAll(req *rpc.LibraryUpgradeAllRequest, downloadCB rpc.Downloa
return &arduino.InvalidInstanceError{}
}
if err := upgrade(lm, listLibraries(lm, true, false), downloadCB, taskCB); err != nil {
if err := upgrade(req.Instance, listLibraries(lm, true, false), downloadCB, taskCB); err != nil {
return err
}
......@@ -47,6 +44,9 @@ func LibraryUpgradeAll(req *rpc.LibraryUpgradeAllRequest, downloadCB rpc.Downloa
// LibraryUpgrade upgrades a library
func LibraryUpgrade(ctx context.Context, req *rpc.LibraryUpgradeRequest, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) error {
lm := commands.GetLibraryManager(req)
if lm == nil {
return &arduino.InvalidInstanceError{}
}
// Get the library to upgrade
name := req.GetName()
......@@ -61,23 +61,21 @@ func LibraryUpgrade(ctx context.Context, req *rpc.LibraryUpgradeRequest, downloa
}
// Install update
return upgrade(lm, []*installedLib{lib}, downloadCB, taskCB)
return upgrade(req.Instance, []*installedLib{lib}, downloadCB, taskCB)
}
func upgrade(lm *librariesmanager.LibrariesManager, libs []*installedLib, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) error {
// Go through the list and download them
func upgrade(instance *rpc.Instance, libs []*installedLib, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) error {
for _, lib := range libs {
if err := downloadLibrary(lm, lib.Available, downloadCB, taskCB); err != nil {
return err
libInstallReq := &rpc.LibraryInstallRequest{
Instance: instance,
Name: lib.Library.Name,
Version: "",
NoDeps: false,
NoOverwrite: false,
}
}
// Go through the list and install them
for _, lib := range libs {
if err := installLibrary(lm, lib.Available, libraries.User, taskCB); err != nil {
if !errors.Is(err, librariesmanager.ErrAlreadyInstalled) {
return err
}
err := LibraryInstall(context.Background(), libInstallReq, downloadCB, taskCB)
if err != nil {
return err
}
}
......
......@@ -199,3 +199,48 @@ func TestLibDepsOutput(t *testing.T) {
require.Equal(t, "WiFiNINA", jsonDeps.Dependencies[6].Name)
require.Equal(t, jsonDeps.Dependencies[6].VersionInstalled, jsonDeps.Dependencies[6].VersionRequired)
}
func TestUpgradeLibraryWithDependencies(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()
// Updates index for cores and libraries
_, _, err := cli.Run("core", "update-index")
require.NoError(t, err)
_, _, err = cli.Run("lib", "update-index")
require.NoError(t, err)
// Install library
_, _, err = cli.Run("lib", "install", "Arduino_ConnectionHandler@0.3.3")
require.NoError(t, err)
stdOut, _, err := cli.Run("lib", "deps", "Arduino_ConnectionHandler@0.3.3", "--format", "json")
require.NoError(t, err)
var jsonDeps struct {
Dependencies []struct {
Name string `json:"name"`
VersionRequired string `json:"version_required"`
VersionInstalled string `json:"version_installed"`
} `json:"dependencies"`
}
err = json.Unmarshal(stdOut, &jsonDeps)
require.NoError(t, err)
require.Len(t, jsonDeps.Dependencies, 6)
require.Equal(t, "Arduino_ConnectionHandler", jsonDeps.Dependencies[0].Name)
require.Equal(t, "Arduino_DebugUtils", jsonDeps.Dependencies[1].Name)
require.Equal(t, "MKRGSM", jsonDeps.Dependencies[2].Name)
require.Equal(t, "MKRNB", jsonDeps.Dependencies[3].Name)
require.Equal(t, "WiFi101", jsonDeps.Dependencies[4].Name)
require.Equal(t, "WiFiNINA", jsonDeps.Dependencies[5].Name)
// Test lib upgrade also install new dependencies of already installed library
_, _, err = cli.Run("lib", "upgrade", "Arduino_ConnectionHandler")
require.NoError(t, err)
stdOut, _, err = cli.Run("lib", "deps", "Arduino_ConnectionHandler", "--format", "json")
require.NoError(t, err)
jsonOut := requirejson.Parse(t, stdOut)
dependency := jsonOut.Query(`.dependencies[] | select(.name=="MKRWAN")`)
require.Equal(t, dependency.Query(".version_required"), dependency.Query(".version_installed"))
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment