Commit 76f55490 authored by Silvano Cerza's avatar Silvano Cerza Committed by Silvano Cerza

Add flag to skip libraries dependencies installation to gRPC LibraryInstall function (#1195)

parent 3164edc1
...@@ -118,49 +118,16 @@ func runInstallCommand(cmd *cobra.Command, args []string) { ...@@ -118,49 +118,16 @@ func runInstallCommand(cmd *cobra.Command, args []string) {
os.Exit(errorcodes.ErrBadArgument) os.Exit(errorcodes.ErrBadArgument)
} }
toInstall := map[string]*rpc.LibraryDependencyStatus{} for _, libRef := range libRefs {
if installFlags.noDeps {
for _, libRef := range libRefs {
toInstall[libRef.Name] = &rpc.LibraryDependencyStatus{
Name: libRef.Name,
VersionRequired: libRef.Version,
}
}
} else {
for _, libRef := range libRefs {
depsResp, err := lib.LibraryResolveDependencies(context.Background(), &rpc.LibraryResolveDependenciesReq{
Instance: instance,
Name: libRef.Name,
Version: libRef.Version,
})
if err != nil {
feedback.Errorf("Error resolving dependencies for %s: %s", libRef, err)
os.Exit(errorcodes.ErrGeneric)
}
for _, dep := range depsResp.GetDependencies() {
feedback.Printf("%s depends on %s@%s", libRef, dep.GetName(), dep.GetVersionRequired())
if existingDep, has := toInstall[dep.GetName()]; has {
if existingDep.GetVersionRequired() != dep.GetVersionRequired() {
// TODO: make a better error
feedback.Errorf("The library %s is required in two different versions: %s and %s",
dep.GetName(), dep.GetVersionRequired(), existingDep.GetVersionRequired())
os.Exit(errorcodes.ErrGeneric)
}
}
toInstall[dep.GetName()] = dep
}
}
}
for _, library := range toInstall {
libraryInstallReq := &rpc.LibraryInstallReq{ libraryInstallReq := &rpc.LibraryInstallReq{
Instance: instance, Instance: instance,
Name: library.Name, Name: libRef.Name,
Version: library.VersionRequired, Version: libRef.Version,
NoDeps: installFlags.noDeps,
} }
err := lib.LibraryInstall(context.Background(), libraryInstallReq, output.ProgressBar(), output.TaskProgress()) err := lib.LibraryInstall(context.Background(), libraryInstallReq, output.ProgressBar(), output.TaskProgress())
if err != nil { if err != nil {
feedback.Errorf("Error installing %s: %v", library, err) feedback.Errorf("Error installing %s: %v", libRef.Name, err)
os.Exit(errorcodes.ErrGeneric) os.Exit(errorcodes.ErrGeneric)
} }
} }
......
...@@ -207,6 +207,10 @@ func main() { ...@@ -207,6 +207,10 @@ func main() {
log.Println("calling LibraryInstall(WiFi101@0.15.2)") log.Println("calling LibraryInstall(WiFi101@0.15.2)")
callLibInstall(client, instance, "0.15.2") callLibInstall(client, instance, "0.15.2")
// Install a library skipping deps installation
log.Println("calling LibraryInstall(Arduino_MKRIoTCarrier@0.9.9) skipping dependencies")
callLibInstallNoDeps(client, instance, "0.9.9")
// Upgrade all libs to latest // Upgrade all libs to latest
log.Println("calling LibraryUpgradeAll()") log.Println("calling LibraryUpgradeAll()")
callLibUpgradeAll(client, instance) callLibUpgradeAll(client, instance)
...@@ -813,6 +817,38 @@ func callLibInstall(client rpc.ArduinoCoreClient, instance *rpc.Instance, versio ...@@ -813,6 +817,38 @@ func callLibInstall(client rpc.ArduinoCoreClient, instance *rpc.Instance, versio
} }
} }
func callLibInstallNoDeps(client rpc.ArduinoCoreClient, instance *rpc.Instance, version string) {
installRespStream, err := client.LibraryInstall(context.Background(),
&rpc.LibraryInstallReq{
Instance: instance,
Name: "Arduino_MKRIoTCarrier",
Version: version,
NoDeps: true,
})
if err != nil {
log.Fatalf("Error installing library: %s", err)
}
for {
installResp, err := installRespStream.Recv()
if err == io.EOF {
log.Print("Lib install done")
break
}
if err != nil {
log.Fatalf("Install error: %s", err)
}
if installResp.GetProgress() != nil {
log.Printf("DOWNLOAD: %s\n", installResp.GetProgress())
}
if installResp.GetTaskProgress() != nil {
log.Printf("TASK: %s\n", installResp.GetTaskProgress())
}
}
}
func callLibUpgradeAll(client rpc.ArduinoCoreClient, instance *rpc.Instance) { func callLibUpgradeAll(client rpc.ArduinoCoreClient, instance *rpc.Instance) {
libUpgradeAllRespStream, err := client.LibraryUpgradeAll(context.Background(), libUpgradeAllRespStream, err := client.LibraryUpgradeAll(context.Background(),
&rpc.LibraryUpgradeAllReq{ &rpc.LibraryUpgradeAllReq{
......
...@@ -32,17 +32,49 @@ func LibraryInstall(ctx context.Context, req *rpc.LibraryInstallReq, ...@@ -32,17 +32,49 @@ func LibraryInstall(ctx context.Context, req *rpc.LibraryInstallReq,
lm := commands.GetLibraryManager(req.GetInstance().GetId()) lm := commands.GetLibraryManager(req.GetInstance().GetId())
libRelease, err := findLibraryIndexRelease(lm, req) toInstall := map[string]*rpc.LibraryDependencyStatus{}
if err != nil { if req.NoDeps {
return fmt.Errorf("looking for library: %s", err) toInstall[req.Name] = &rpc.LibraryDependencyStatus{
} Name: req.Name,
VersionRequired: req.Version,
if err := downloadLibrary(lm, libRelease, downloadCB, taskCB); err != nil { }
return fmt.Errorf("downloading library: %s", err) } else {
res, err := LibraryResolveDependencies(ctx, &rpc.LibraryResolveDependenciesReq{
Instance: req.Instance,
Name: req.Name,
Version: req.Version,
})
if err != nil {
return fmt.Errorf("Error resolving dependencies for %s@%s: %s", req.Name, req.Version, err)
}
for _, dep := range res.Dependencies {
if existingDep, has := toInstall[dep.Name]; has {
if existingDep.VersionRequired != dep.VersionRequired {
return fmt.Errorf("two different versions of the library %s are required: %s and %s",
dep.Name, dep.VersionRequired, existingDep.VersionRequired)
}
}
toInstall[dep.Name] = dep
}
} }
if err := installLibrary(lm, libRelease, taskCB); err != nil { for _, lib := range toInstall {
return err libRelease, err := findLibraryIndexRelease(lm, &rpc.LibraryInstallReq{
Name: lib.Name,
Version: lib.VersionRequired,
})
if err != nil {
return fmt.Errorf("looking for library: %s", err)
}
if err := downloadLibrary(lm, libRelease, downloadCB, taskCB); err != nil {
return fmt.Errorf("downloading library: %s", err)
}
if err := installLibrary(lm, libRelease, taskCB); err != nil {
return err
}
} }
if _, err := commands.Rescan(req.GetInstance().GetId()); err != nil { if _, err := commands.Rescan(req.GetInstance().GetId()); err != nil {
......
This diff is collapsed.
...@@ -42,6 +42,8 @@ message LibraryInstallReq { ...@@ -42,6 +42,8 @@ message LibraryInstallReq {
string name = 2; string name = 2;
// The version of the library to install. // The version of the library to install.
string version = 3; string version = 3;
// Set to true to skip installation of specified library's dependencies, defaults to false.
bool noDeps = 4;
} }
message LibraryInstallResp { message LibraryInstallResp {
...@@ -317,4 +319,4 @@ message GitLibraryInstallReq { ...@@ -317,4 +319,4 @@ message GitLibraryInstallReq {
message GitLibraryInstallResp { message GitLibraryInstallResp {
// Description of the current stage of the installation. // Description of the current stage of the installation.
TaskProgress task_progress = 1; TaskProgress task_progress = 1;
} }
...@@ -194,8 +194,55 @@ def test_install(run_command): ...@@ -194,8 +194,55 @@ def test_install(run_command):
# Test failing-install of library with wrong dependency # Test failing-install of library with wrong dependency
# (https://github.com/arduino/arduino-cli/issues/534) # (https://github.com/arduino/arduino-cli/issues/534)
result = run_command("lib install MD_Parola@3.2.0") res = run_command("lib install MD_Parola@3.2.0")
assert "Error resolving dependencies for MD_Parola@3.2.0: dependency 'MD_MAX72xx' is not available" in result.stderr assert res.failed
assert "Error resolving dependencies for MD_Parola@3.2.0: dependency 'MD_MAX72xx' is not available" in res.stderr
def test_install_library_with_dependencies(run_command):
assert run_command("update")
# Verifies libraries are not installed
res = run_command("lib list --format json")
assert res.ok
data = json.loads(res.stdout)
installed_libraries = [l["library"]["name"] for l in data]
assert "MD_Parola" not in installed_libraries
assert "MD_MAX72XX" not in installed_libraries
# Install library
assert run_command("lib install MD_Parola@3.5.5")
# Verifies library's dependencies are correctly installed
res = run_command("lib list --format json")
assert res.ok
data = json.loads(res.stdout)
installed_libraries = [l["library"]["name"] for l in data]
assert "MD_Parola" in installed_libraries
assert "MD_MAX72XX" in installed_libraries
def test_install_no_deps(run_command):
assert run_command("update")
# Verifies libraries are not installed
res = run_command("lib list --format json")
assert res.ok
data = json.loads(res.stdout)
installed_libraries = [l["library"]["name"] for l in data]
assert "MD_Parola" not in installed_libraries
assert "MD_MAX72XX" not in installed_libraries
# Install library skipping dependencies installation
assert run_command("lib install MD_Parola@3.5.5 --no-deps")
# Verifies library's dependencies are not installed
res = run_command("lib list --format json")
assert res.ok
data = json.loads(res.stdout)
installed_libraries = [l["library"]["name"] for l in data]
assert "MD_Parola" in installed_libraries
assert "MD_MAX72XX" not in installed_libraries
def test_install_git_url_and_zip_path_flags_visibility(run_command, data_dir, downloads_dir): def test_install_git_url_and_zip_path_flags_visibility(run_command, data_dir, downloads_dir):
......
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