Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 5 additions & 38 deletions cli/lib/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
36 changes: 36 additions & 0 deletions client_example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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{
Expand Down
50 changes: 41 additions & 9 deletions commands/lib/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading