Skip to content

[breaking] Remove auto detection of Arduino IDE built-in libraries and tools / Allow gRPC install of built-in libraries #1817

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 13 commits into from
Sep 2, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Allow library installation on bundled libs dir via gRPC
  • Loading branch information
cmaglie committed Sep 1, 2022
commit a2132702ef7cc2b41879ece965b85a8c28d6667a
16 changes: 14 additions & 2 deletions arduino/libraries/libraries_location.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (d *LibraryLocation) UnmarshalJSON(b []byte) error {
func (d *LibraryLocation) ToRPCLibraryLocation() rpc.LibraryLocation {
switch *d {
case IDEBuiltIn:
return rpc.LibraryLocation_LIBRARY_LOCATION_IDE_BUILTIN
return rpc.LibraryLocation_LIBRARY_LOCATION_BUILTIN
case PlatformBuiltIn:
return rpc.LibraryLocation_LIBRARY_LOCATION_PLATFORM_BUILTIN
case ReferencedPlatformBuiltIn:
Expand All @@ -110,7 +110,7 @@ func (d *LibraryLocation) ToRPCLibraryLocation() rpc.LibraryLocation {
// FromRPCLibraryLocation converts a rpc.LibraryLocation to a LibraryLocation
func FromRPCLibraryLocation(l rpc.LibraryLocation) LibraryLocation {
switch l {
case rpc.LibraryLocation_LIBRARY_LOCATION_IDE_BUILTIN:
case rpc.LibraryLocation_LIBRARY_LOCATION_BUILTIN:
return IDEBuiltIn
case rpc.LibraryLocation_LIBRARY_LOCATION_PLATFORM_BUILTIN:
return PlatformBuiltIn
Expand All @@ -124,3 +124,15 @@ func FromRPCLibraryLocation(l rpc.LibraryLocation) LibraryLocation {
panic(fmt.Sprintf("invalid rpc.LibraryLocation value %d", l))
}
}

// FromRPCLibraryInstallLocation converts a rpc.LibraryInstallLocation to a LibraryLocation
func FromRPCLibraryInstallLocation(l rpc.LibraryInstallLocation) LibraryLocation {
switch l {
case rpc.LibraryInstallLocation_LIBRARY_INSTALL_LOCATION_BUILTIN:
return IDEBuiltIn
case rpc.LibraryInstallLocation_LIBRARY_INSTALL_LOCATION_USER:
return User
default:
panic(fmt.Sprintf("invalid rpc.LibraryInstallLocation value %d", l))
}
}
23 changes: 13 additions & 10 deletions arduino/libraries/librariesmanager/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ var (
// InstallPrerequisiteCheck performs prequisite checks to install a library. It returns the
// install path, where the library should be installed and the possible library that is already
// installed on the same folder and it's going to be replaced by the new one.
func (lm *LibrariesManager) InstallPrerequisiteCheck(indexLibrary *librariesindex.Release) (*paths.Path, *libraries.Library, error) {
func (lm *LibrariesManager) InstallPrerequisiteCheck(indexLibrary *librariesindex.Release, installLocation libraries.LibraryLocation) (*paths.Path, *libraries.Library, error) {
saneName := utils.SanitizeName(indexLibrary.Library.Name)

var replaced *libraries.Library
if installedLibs, have := lm.Libraries[saneName]; have {
for _, installedLib := range installedLibs.Alternatives {
if installedLib.Location != libraries.User {
if installedLib.Location != installLocation {
continue
}
if installedLib.Version != nil && installedLib.Version.Equal(indexLibrary.Version) {
Expand All @@ -64,9 +64,12 @@ func (lm *LibrariesManager) InstallPrerequisiteCheck(indexLibrary *librariesinde
}
}

libsDir := lm.getUserLibrariesDir()
libsDir := lm.getLibrariesDir(installLocation)
if libsDir == nil {
return nil, nil, fmt.Errorf(tr("User directory not set"))
if installLocation == libraries.User {
return nil, nil, fmt.Errorf(tr("User directory not set"))
}
return nil, nil, fmt.Errorf(tr("Builtin libraries directory not set"))
}

libPath := libsDir.Join(saneName)
Expand All @@ -79,8 +82,8 @@ func (lm *LibrariesManager) InstallPrerequisiteCheck(indexLibrary *librariesinde
}

// Install installs a library on the specified path.
func (lm *LibrariesManager) Install(indexLibrary *librariesindex.Release, libPath *paths.Path) error {
libsDir := lm.getUserLibrariesDir()
func (lm *LibrariesManager) Install(indexLibrary *librariesindex.Release, libPath *paths.Path, installLocation libraries.LibraryLocation) error {
libsDir := lm.getLibrariesDir(installLocation)
if libsDir == nil {
return fmt.Errorf(tr("User directory not set"))
}
Expand All @@ -100,9 +103,9 @@ func (lm *LibrariesManager) Uninstall(lib *libraries.Library) error {
return nil
}

//InstallZipLib installs a Zip library on the specified path.
// InstallZipLib installs a Zip library on the specified path.
func (lm *LibrariesManager) InstallZipLib(ctx context.Context, archivePath string, overwrite bool) error {
libsDir := lm.getUserLibrariesDir()
libsDir := lm.getLibrariesDir(libraries.User)
if libsDir == nil {
return fmt.Errorf(tr("User directory not set"))
}
Expand Down Expand Up @@ -184,9 +187,9 @@ func (lm *LibrariesManager) InstallZipLib(ctx context.Context, archivePath strin
return nil
}

//InstallGitLib installs a library hosted on a git repository on the specified path.
// InstallGitLib installs a library hosted on a git repository on the specified path.
func (lm *LibrariesManager) InstallGitLib(gitURL string, overwrite bool) error {
libsDir := lm.getUserLibrariesDir()
libsDir := lm.getLibrariesDir(libraries.User)
if libsDir == nil {
return fmt.Errorf(tr("User directory not set"))
}
Expand Down
4 changes: 2 additions & 2 deletions arduino/libraries/librariesmanager/librariesmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ func (lm *LibrariesManager) RescanLibraries() []*status.Status {
return statuses
}

func (lm *LibrariesManager) getUserLibrariesDir() *paths.Path {
func (lm *LibrariesManager) getLibrariesDir(installLocation libraries.LibraryLocation) *paths.Path {
for _, dir := range lm.LibrariesDir {
if dir.Location == libraries.User {
if dir.Location == installLocation {
return dir.Path
}
}
Expand Down
13 changes: 7 additions & 6 deletions commands/lib/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"

"github.com/arduino/arduino-cli/arduino"
"github.com/arduino/arduino-cli/arduino/libraries"
"github.com/arduino/arduino-cli/arduino/libraries/librariesindex"
"github.com/arduino/arduino-cli/arduino/libraries/librariesmanager"
"github.com/arduino/arduino-cli/commands"
Expand All @@ -30,13 +31,13 @@ import (

// LibraryInstall FIXMEDOC
func LibraryInstall(ctx context.Context, req *rpc.LibraryInstallRequest, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) error {

lm := commands.GetLibraryManager(req)
if lm == nil {
return &arduino.InvalidInstanceError{}
}

toInstall := map[string]*rpc.LibraryDependencyStatus{}
installLocation := libraries.FromRPCLibraryInstallLocation(req.GetInstallLocation())
if req.NoDeps {
toInstall[req.Name] = &rpc.LibraryDependencyStatus{
Name: req.Name,
Expand Down Expand Up @@ -81,7 +82,7 @@ func LibraryInstall(ctx context.Context, req *rpc.LibraryInstallRequest, downloa
// Check if any of the libraries to install is already installed and remove it from the list
j := 0
for i, libRelease := range libReleasesToInstall {
_, libReplaced, err := lm.InstallPrerequisiteCheck(libRelease)
_, libReplaced, err := lm.InstallPrerequisiteCheck(libRelease, installLocation)
if errors.Is(err, librariesmanager.ErrAlreadyInstalled) {
taskCB(&rpc.TaskProgress{Message: tr("Already installed %s", libRelease), Completed: true})
} else if err != nil {
Expand All @@ -104,7 +105,7 @@ func LibraryInstall(ctx context.Context, req *rpc.LibraryInstallRequest, downloa
return err
}

if err := installLibrary(lm, libRelease, taskCB); err != nil {
if err := installLibrary(lm, libRelease, installLocation, taskCB); err != nil {
if errors.Is(err, librariesmanager.ErrAlreadyInstalled) {
continue
} else {
Expand All @@ -123,10 +124,10 @@ func LibraryInstall(ctx context.Context, req *rpc.LibraryInstallRequest, downloa
return nil
}

func installLibrary(lm *librariesmanager.LibrariesManager, libRelease *librariesindex.Release, taskCB rpc.TaskProgressCB) error {
func installLibrary(lm *librariesmanager.LibrariesManager, libRelease *librariesindex.Release, installLocation libraries.LibraryLocation, taskCB rpc.TaskProgressCB) error {
taskCB(&rpc.TaskProgress{Name: tr("Installing %s", libRelease)})
logrus.WithField("library", libRelease).Info("Installing library")
libPath, libReplaced, err := lm.InstallPrerequisiteCheck(libRelease)
libPath, libReplaced, err := lm.InstallPrerequisiteCheck(libRelease, installLocation)
if errors.Is(err, librariesmanager.ErrAlreadyInstalled) {
taskCB(&rpc.TaskProgress{Message: tr("Already installed %s", libRelease), Completed: true})
return err
Expand All @@ -140,7 +141,7 @@ func installLibrary(lm *librariesmanager.LibrariesManager, libRelease *libraries
taskCB(&rpc.TaskProgress{Message: tr("Replacing %[1]s with %[2]s", libReplaced, libRelease)})
}

if err := lm.Install(libRelease, libPath); err != nil {
if err := lm.Install(libRelease, libPath, installLocation); err != nil {
return &arduino.FailedLibraryInstallError{Cause: err}
}

Expand Down
3 changes: 2 additions & 1 deletion commands/lib/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"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"
Expand Down Expand Up @@ -64,7 +65,7 @@ func upgrade(lm *librariesmanager.LibrariesManager, libs []*installedLib, downlo

// Go through the list and install them
for _, lib := range libs {
if err := installLibrary(lm, lib.Available, taskCB); err != nil {
if err := installLibrary(lm, lib.Available, libraries.User, taskCB); err != nil {
if !errors.Is(err, librariesmanager.ErrAlreadyInstalled) {
return err
}
Expand Down
Loading