Skip to content
Permalink
Browse files

Add flag to skip libraries dependencies installation to gRPC LibraryI…

…nstall function (#1195)
  • Loading branch information
silvanocerza committed Feb 24, 2021
1 parent 4c9ce83 commit b8c9e89682c85d4e302217a897d461a359e4810f
Showing with 424 additions and 330 deletions.
  1. +5 −38 cli/lib/install.go
  2. +36 −0 client_example/main.go
  3. +41 −9 commands/lib/install.go
  4. +290 −280 rpc/commands/lib.pb.go
  5. +3 −1 rpc/commands/lib.proto
  6. +49 −2 test/test_lib.py
@@ -118,49 +118,16 @@ func runInstallCommand(cmd *cobra.Command, args []string) {
os.Exit(errorcodes.ErrBadArgument)
}

toInstall := map[string]*rpc.LibraryDependencyStatus{}
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 {
for _, libRef := range libRefs {
libraryInstallReq := &rpc.LibraryInstallReq{
Instance: instance,
Name: library.Name,
Version: library.VersionRequired,
Name: libRef.Name,
Version: libRef.Version,
NoDeps: installFlags.noDeps,
}
err := lib.LibraryInstall(context.Background(), libraryInstallReq, output.ProgressBar(), output.TaskProgress())
if err != nil {
feedback.Errorf("Error installing %s: %v", library, err)
feedback.Errorf("Error installing %s: %v", libRef.Name, err)
os.Exit(errorcodes.ErrGeneric)
}
}
@@ -207,6 +207,10 @@ func main() {
log.Println("calling LibraryInstall([email protected])")
callLibInstall(client, instance, "0.15.2")

// Install a library skipping deps installation
log.Println("calling LibraryInstall([email protected]) skipping dependencies")
callLibInstallNoDeps(client, instance, "0.9.9")

// Upgrade all libs to latest
log.Println("calling LibraryUpgradeAll()")
callLibUpgradeAll(client, instance)
@@ -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) {
libUpgradeAllRespStream, err := client.LibraryUpgradeAll(context.Background(),
&rpc.LibraryUpgradeAllReq{
@@ -32,17 +32,49 @@ func LibraryInstall(ctx context.Context, req *rpc.LibraryInstallReq,

lm := commands.GetLibraryManager(req.GetInstance().GetId())

libRelease, err := findLibraryIndexRelease(lm, req)
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)
toInstall := map[string]*rpc.LibraryDependencyStatus{}
if req.NoDeps {
toInstall[req.Name] = &rpc.LibraryDependencyStatus{
Name: req.Name,
VersionRequired: req.Version,
}
} 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 {
return err
for _, lib := range toInstall {
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 {

0 comments on commit b8c9e89

Please sign in to comment.