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
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
2 changes: 1 addition & 1 deletion arduino/cores/packagemanager/loader.go
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ func (pm *Builder) LoadHardware() []error {
hardwareDirs := configuration.HardwareDirectories(configuration.Settings)
merr := pm.LoadHardwareFromDirectories(hardwareDirs)

bundleToolDirs := configuration.BundleToolsDirectories(configuration.Settings)
bundleToolDirs := configuration.BuiltinToolsDirectories(configuration.Settings)
merr = append(merr, pm.LoadToolsFromBundleDirectories(bundleToolDirs)...)

return merr
2 changes: 1 addition & 1 deletion arduino/cores/packagemanager/package_manager_test.go
Original file line number Diff line number Diff line change
@@ -224,7 +224,7 @@ func TestFindToolsRequiredForBoard(t *testing.T) {
pmb := packagemanager.NewBuilder(
dataDir1,
configuration.PackagesDir(configuration.Settings),
paths.New(configuration.Settings.GetString("directories.Downloads")),
configuration.DownloadsDir(configuration.Settings),
dataDir1,
"test",
)
16 changes: 14 additions & 2 deletions arduino/libraries/libraries_location.go
Original file line number Diff line number Diff line change
@@ -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:
@@ -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
@@ -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
@@ -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) {
@@ -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)
@@ -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"))
}
@@ -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"))
}
@@ -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"))
}
15 changes: 8 additions & 7 deletions arduino/libraries/librariesmanager/librariesmanager.go
Original file line number Diff line number Diff line change
@@ -78,9 +78,9 @@ func (alts *LibraryAlternatives) Remove(library *libraries.Library) {
}

// FindVersion returns the library mathching the provided version or nil if not found
func (alts *LibraryAlternatives) FindVersion(version *semver.Version) *libraries.Library {
func (alts *LibraryAlternatives) FindVersion(version *semver.Version, installLocation libraries.LibraryLocation) *libraries.Library {
for _, lib := range alts.Alternatives {
if lib.Version.Equal(version) {
if lib.Version.Equal(version) && lib.Location == installLocation {
return lib
}
}
@@ -118,6 +118,7 @@ func NewLibraryManager(indexDir *paths.Path, downloadsDir *paths.Path) *Librarie
// LoadIndex reads a library_index.json from a file and returns
// the corresponding Index structure.
func (lm *LibrariesManager) LoadIndex() error {
logrus.WithField("index", lm.IndexFile).Info("Loading libraries index file")
index, err := librariesindex.LoadIndex(lm.IndexFile)
if err != nil {
lm.Index = librariesindex.EmptyIndex
@@ -175,9 +176,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
}
}
@@ -244,7 +245,7 @@ func (lm *LibrariesManager) LoadLibraryFromDir(libRootDir *paths.Path, location
// FindByReference return the installed library matching the Reference
// name and version or, if the version is nil, the library installed
// in the User folder.
func (lm *LibrariesManager) FindByReference(libRef *librariesindex.Reference) *libraries.Library {
func (lm *LibrariesManager) FindByReference(libRef *librariesindex.Reference, installLocation libraries.LibraryLocation) *libraries.Library {
saneName := utils.SanitizeName(libRef.Name)
alternatives, have := lm.Libraries[saneName]
if !have {
@@ -253,11 +254,11 @@ func (lm *LibrariesManager) FindByReference(libRef *librariesindex.Reference) *l
// TODO: Move "search into user" into another method...
if libRef.Version == nil {
for _, candidate := range alternatives.Alternatives {
if candidate.Location == libraries.User {
if candidate.Location == installLocation {
return candidate
}
}
return nil
}
return alternatives.FindVersion(libRef.Version)
return alternatives.FindVersion(libRef.Version, installLocation)
}
4 changes: 2 additions & 2 deletions cli/cache/clean.go
Original file line number Diff line number Diff line change
@@ -40,8 +40,8 @@ func initCleanCommand() *cobra.Command {
func runCleanCommand(cmd *cobra.Command, args []string) {
logrus.Info("Executing `arduino-cli cache clean`")

cachePath := configuration.Settings.GetString("directories.Downloads")
err := os.RemoveAll(cachePath)
cachePath := configuration.DownloadsDir(configuration.Settings)
err := cachePath.RemoveAll()
if err != nil {
feedback.Errorf(tr("Error cleaning caches: %v"), err)
os.Exit(errorcodes.ErrGeneric)
2 changes: 1 addition & 1 deletion cli/cli.go
Original file line number Diff line number Diff line change
@@ -158,7 +158,7 @@ func preRun(cmd *cobra.Command, args []string) {
configFile := configuration.Settings.ConfigFileUsed()

// initialize inventory
err := inventory.Init(configuration.Settings.GetString("directories.Data"))
err := inventory.Init(configuration.DataDir(configuration.Settings).String())
if err != nil {
feedback.Errorf("Error: %v", err)
os.Exit(errorcodes.ErrBadArgument)
2 changes: 2 additions & 0 deletions cli/config/validate.go
Original file line number Diff line number Diff line change
@@ -30,6 +30,8 @@ var validMap = map[string]reflect.Kind{
"directories.data": reflect.String,
"directories.downloads": reflect.String,
"directories.user": reflect.String,
"directories.builtin.tools": reflect.String,
"directories.builtin.libraries": reflect.String,
"library.enable_unsafe_install": reflect.Bool,
"logging.file": reflect.String,
"logging.format": reflect.String,
3 changes: 1 addition & 2 deletions cli/core/search.go
Original file line number Diff line number Diff line change
@@ -34,7 +34,6 @@ import (
"github.com/arduino/arduino-cli/configuration"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"github.com/arduino/arduino-cli/table"
"github.com/arduino/go-paths-helper"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@@ -130,7 +129,7 @@ func (sr searchResults) String() string {
// of 24 hours is used.
// Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
func indexesNeedUpdating(duration string) bool {
indexpath := paths.New(configuration.Settings.GetString("directories.Data"))
indexpath := configuration.DataDir(configuration.Settings)

now := time.Now()
modTimeThreshold, err := time.ParseDuration(duration)
3 changes: 3 additions & 0 deletions cli/daemon/daemon.go
Original file line number Diff line number Diff line change
@@ -72,6 +72,9 @@ func NewCommand() *cobra.Command {
func runDaemonCommand(cmd *cobra.Command, args []string) {
logrus.Info("Executing `arduino-cli daemon`")

// Bundled libraries support is enabled by default when running as a daemon
configuration.Settings.SetDefault("directories.builtin.Libraries", configuration.GetDefaultBuiltinLibrariesDir())

port := configuration.Settings.GetString("daemon.port")
gRPCOptions := []grpc.ServerOption{}
if debugFile != "" {
2 changes: 1 addition & 1 deletion cli/instance/instance.go
Original file line number Diff line number Diff line change
@@ -125,7 +125,7 @@ func InitWithProfile(instance *rpc.Instance, profileName string, sketchPath *pat
// This ideally is only executed the first time the CLI is run.
func FirstUpdate(instance *rpc.Instance) error {
// Gets the data directory to verify if library_index.json and package_index.json exist
dataDir := paths.New(configuration.Settings.GetString("directories.data"))
dataDir := configuration.DataDir(configuration.Settings)

libraryIndex := dataDir.Join("library_index.json")
packageIndex := dataDir.Join("package_index.json")
27 changes: 3 additions & 24 deletions commands/compile/compile.go
Original file line number Diff line number Diff line change
@@ -19,8 +19,6 @@ import (
"context"
"fmt"
"io"
"path/filepath"
"sort"
"strings"

"github.com/arduino/arduino-cli/arduino"
@@ -35,7 +33,6 @@ import (
"github.com/arduino/arduino-cli/legacy/builder/types"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
paths "github.com/arduino/go-paths-helper"
properties "github.com/arduino/go-properties-orderedmap"
"github.com/sirupsen/logrus"
)

@@ -123,7 +120,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream

// FIXME: This will be redundant when arduino-builder will be part of the cli
builderCtx.HardwareDirs = configuration.HardwareDirectories(configuration.Settings)
builderCtx.BuiltInToolsDirs = configuration.BundleToolsDirectories(configuration.Settings)
builderCtx.BuiltInToolsDirs = configuration.BuiltinToolsDirectories(configuration.Settings)

// FIXME: This will be redundant when arduino-builder will be part of the cli
builderCtx.OtherLibrariesDirs = paths.NewPathList(req.GetLibraries()...)
@@ -164,29 +161,11 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
}
}

builderCtx.BuiltInLibrariesDirs = configuration.IDEBuiltinLibrariesDir(configuration.Settings)

// Will be deprecated.
builderCtx.ArduinoAPIVersion = "10607"

// Check if Arduino IDE is installed and get it's libraries location.
// TODO: Remove?
dataDir := paths.New(configuration.Settings.GetString("directories.Data"))
preferencesTxt := dataDir.Join("preferences.txt")
ideProperties, err := properties.LoadFromPath(preferencesTxt)
if err == nil {
lastIdeSubProperties := ideProperties.SubTree("last").SubTree("ide")
// Preferences can contain records from previous IDE versions. Find the latest one.
var pathVariants []string
for k := range lastIdeSubProperties.AsMap() {
if strings.HasSuffix(k, ".hardwarepath") {
pathVariants = append(pathVariants, k)
}
}
sort.Strings(pathVariants)
ideHardwarePath := lastIdeSubProperties.Get(pathVariants[len(pathVariants)-1])
ideLibrariesPath := filepath.Join(filepath.Dir(ideHardwarePath), "libraries")
builderCtx.BuiltInLibrariesDirs = paths.NewPathList(ideLibrariesPath)
}

builderCtx.Stdout = outStream
builderCtx.Stderr = errStream
builderCtx.Clean = req.GetClean()
8 changes: 4 additions & 4 deletions commands/instances.go
Original file line number Diff line number Diff line change
@@ -149,7 +149,7 @@ func Create(req *rpc.CreateRequest, extraUserAgent ...string) (*rpc.CreateRespon
instance := &CoreInstance{}

// Setup downloads directory
downloadsDir := paths.New(configuration.Settings.GetString("directories.Downloads"))
downloadsDir := configuration.DownloadsDir(configuration.Settings)
if downloadsDir.NotExist() {
err := downloadsDir.MkdirAll()
if err != nil {
@@ -158,7 +158,7 @@ func Create(req *rpc.CreateRequest, extraUserAgent ...string) (*rpc.CreateRespon
}

// Setup data directory
dataDir := paths.New(configuration.Settings.GetString("directories.Data"))
dataDir := configuration.DataDir(configuration.Settings)
packagesDir := configuration.PackagesDir(configuration.Settings)
if packagesDir.NotExist() {
err := packagesDir.MkdirAll()
@@ -389,7 +389,7 @@ func Init(req *rpc.InitRequest, responseCallback func(r *rpc.InitResponse)) erro

if profile == nil {
// Add directories of libraries bundled with IDE
if bundledLibsDir := configuration.IDEBundledLibrariesDir(configuration.Settings); bundledLibsDir != nil {
if bundledLibsDir := configuration.IDEBuiltinLibrariesDir(configuration.Settings); bundledLibsDir != nil {
lm.AddLibrariesDir(bundledLibsDir, libraries.IDEBuiltIn)
}

@@ -495,7 +495,7 @@ func UpdateIndex(ctx context.Context, req *rpc.UpdateIndexRequest, downloadCB rp
return nil, &arduino.InvalidInstanceError{}
}

indexpath := paths.New(configuration.Settings.GetString("directories.Data"))
indexpath := configuration.DataDir(configuration.Settings)

urls := []string{globals.DefaultIndexURL}
urls = append(urls, configuration.Settings.GetStringSlice("board_manager.additional_urls")...)
13 changes: 7 additions & 6 deletions commands/lib/install.go
Original file line number Diff line number Diff line change
@@ -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"
@@ -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,
@@ -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 {
@@ -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 {
@@ -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
@@ -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}
}

3 changes: 2 additions & 1 deletion commands/lib/uninstall.go
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ import (
"context"

"github.com/arduino/arduino-cli/arduino"
"github.com/arduino/arduino-cli/arduino/libraries"
"github.com/arduino/arduino-cli/commands"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
)
@@ -31,7 +32,7 @@ func LibraryUninstall(ctx context.Context, req *rpc.LibraryUninstallRequest, tas
return &arduino.InvalidLibraryError{Cause: err}
}

lib := lm.FindByReference(ref)
lib := lm.FindByReference(ref, libraries.User)

if lib == nil {
taskCB(&rpc.TaskProgress{Message: tr("Library %s is not installed", req.Name), Completed: true})
3 changes: 2 additions & 1 deletion commands/lib/upgrade.go
Original file line number Diff line number Diff line change
@@ -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"
@@ -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
}
57 changes: 3 additions & 54 deletions configuration/configuration.go
Original file line number Diff line number Diff line change
@@ -25,7 +25,6 @@ import (
"github.com/arduino/arduino-cli/i18n"
paths "github.com/arduino/go-paths-helper"
"github.com/arduino/go-win32-utils"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
jww "github.com/spf13/jwalterweatherman"
"github.com/spf13/viper"
@@ -132,59 +131,9 @@ func getDefaultUserDir() string {
}
}

// IsBundledInDesktopIDE returns true if the CLI is bundled with the Arduino IDE.
func IsBundledInDesktopIDE(settings *viper.Viper) bool {
// value is cached the first time we run the check
if settings.IsSet("IDE.Bundled") {
return settings.GetBool("IDE.Bundled")
}

settings.Set("IDE.Bundled", false)
settings.Set("IDE.Portable", false)

logrus.Info("Checking if CLI is Bundled into the IDE")
executable, err := os.Executable()
if err != nil {
feedback.Errorf(tr("Cannot get executable path: %v"), err)
return false
}

executablePath, err := filepath.EvalSymlinks(executable)
if err != nil {
feedback.Errorf(tr("Cannot get executable path: %v"), err)
return false
}

ideDir := paths.New(executablePath).Parent()
logrus.WithField("dir", ideDir).Trace("Candidate IDE directory")

// To determine if the CLI is bundled with an IDE, We check an arbitrary
// number of folders that are part of the IDE install tree
tests := []string{
"tools-builder",
"examples/01.Basics/Blink",
}

for _, test := range tests {
if !ideDir.Join(test).Exist() {
// the test folder doesn't exist or is not accessible
return false
}
}

logrus.Info("The CLI is bundled in the Arduino IDE")

// Persist IDE-related config settings
settings.Set("IDE.Bundled", true)
settings.Set("IDE.Directory", ideDir)

// Check whether this is a portable install
if ideDir.Join("portable").Exist() {
logrus.Info("The IDE installation is 'portable'")
settings.Set("IDE.Portable", true)
}

return true
// GetDefaultBuiltinLibrariesDir returns the full path to the default builtin libraries dir
func GetDefaultBuiltinLibrariesDir() string {
return filepath.Join(getDefaultArduinoDataDir(), "libraries")
}

// FindConfigFileInArgsOrWorkingDirectory returns the config file path using the
55 changes: 19 additions & 36 deletions configuration/directories.go
Original file line number Diff line number Diff line change
@@ -24,14 +24,6 @@ import (
func HardwareDirectories(settings *viper.Viper) paths.PathList {
res := paths.PathList{}

if IsBundledInDesktopIDE(settings) {
ideDir := paths.New(settings.GetString("IDE.Directory"))
bundledHardwareDir := ideDir.Join("hardware")
if bundledHardwareDir.IsDir() {
res.Add(bundledHardwareDir)
}
}

if settings.IsSet("directories.Data") {
packagesDir := PackagesDir(Settings)
if packagesDir.IsDir() {
@@ -50,34 +42,15 @@ func HardwareDirectories(settings *viper.Viper) paths.PathList {
return res
}

// BundleToolsDirectories returns all paths that may contains bundled-tools.
func BundleToolsDirectories(settings *viper.Viper) paths.PathList {
res := paths.PathList{}

if IsBundledInDesktopIDE(settings) {
ideDir := paths.New(settings.GetString("IDE.Directory"))
bundledToolsDir := ideDir.Join("hardware", "tools")
if bundledToolsDir.IsDir() {
res = append(res, bundledToolsDir)
}
}

return res
// BuiltinToolsDirectories returns all paths that may contains bundled-tools.
func BuiltinToolsDirectories(settings *viper.Viper) paths.PathList {
return paths.NewPathList(settings.GetStringSlice("directories.builtin.Tools")...)
}

// IDEBundledLibrariesDir returns the libraries directory bundled in
// the Arduino IDE. If there is no Arduino IDE or the directory doesn't
// exists then nil is returned
func IDEBundledLibrariesDir(settings *viper.Viper) *paths.Path {
if IsBundledInDesktopIDE(settings) {
ideDir := paths.New(Settings.GetString("IDE.Directory"))
libDir := ideDir.Join("libraries")
if libDir.IsDir() {
return libDir
}
}

return nil
// IDEBuiltinLibrariesDir returns the IDE-bundled libraries path. Usually
// this directory is present in the Arduino IDE.
func IDEBuiltinLibrariesDir(settings *viper.Viper) *paths.Path {
return paths.New(Settings.GetString("directories.builtin.Libraries"))
}

// LibrariesDir returns the full path to the user directory containing
@@ -88,12 +61,22 @@ func LibrariesDir(settings *viper.Viper) *paths.Path {

// PackagesDir returns the full path to the packages folder
func PackagesDir(settings *viper.Viper) *paths.Path {
return paths.New(settings.GetString("directories.Data")).Join("packages")
return DataDir(settings).Join("packages")
}

// ProfilesCacheDir returns the full path to the profiles cache directory
// (it contains all the platforms and libraries used to compile a sketch
// using profiles)
func ProfilesCacheDir(settings *viper.Viper) *paths.Path {
return paths.New(settings.GetString("directories.Data")).Join("internal")
return DataDir(settings).Join("internal")
}

// DataDir returns the full path to the data directory
func DataDir(settings *viper.Viper) *paths.Path {
return paths.New(settings.GetString("directories.Data"))
}

// DownloadsDir returns the full path to the download cache directory
func DownloadsDir(settings *viper.Viper) *paths.Path {
return paths.New(settings.GetString("directories.Downloads"))
}
39 changes: 39 additions & 0 deletions docs/UPGRADING.md
Original file line number Diff line number Diff line change
@@ -266,6 +266,45 @@ must be changed to:
eventsChan, closeWatcher, err := board.Watch(req)
```

### Removed detection of Arduino IDE bundling

Arduino CLI does not check anymore if it's bundled with the Arduino IDE 1.x. Previously this check allowed the Arduino
CLI to automatically use the libraries and tools bundled in the Arduino IDE, now this is not supported anymore unless
the configuration keys `directories.builtin.libraries` and `directories.builtin.tools` are set.

### gRPC enumeration renamed enum value in `cc.arduino.cli.commands.v1.LibraryLocation`

`LIBRARY_LOCATION_IDE_BUILTIN` has been renamed to `LIBRARY_LOCATION_BUILTIN`

### go-lang API change in `LibraryManager`

The following methods:

```go
func (lm *LibrariesManager) InstallPrerequisiteCheck(indexLibrary *librariesindex.Release) (*paths.Path, *libraries.Library, error) { ... }
func (lm *LibrariesManager) Install(indexLibrary *librariesindex.Release, libPath *paths.Path) error { ... ]
func (alts *LibraryAlternatives) FindVersion(version *semver.Version, installLocation libraries.LibraryLocation) *libraries.Library { ... }
func (lm *LibrariesManager) FindByReference(libRef *librariesindex.Reference) *libraries.Library { ... }
```
now requires a new parameter `LibraryLocation`:
```go
func (lm *LibrariesManager) InstallPrerequisiteCheck(indexLibrary *librariesindex.Release, installLocation libraries.LibraryLocation) (*paths.Path, *libraries.Library, error) { ... }
func (lm *LibrariesManager) Install(indexLibrary *librariesindex.Release, libPath *paths.Path, installLocation libraries.LibraryLocation) error { ... ]
func (alts *LibraryAlternatives) FindVersion(version *semver.Version, installLocation libraries.LibraryLocation) *libraries.Library { ... }
+func (lm *LibrariesManager) FindByReference(libRef *librariesindex.Reference, installLocation libraries.LibraryLocation) *libraries.Library { ... }
```
If you're not interested in specifying the `LibraryLocation` you can use `libraries.User` to refer to the user
directory.
### go-lang functions changes in `github.com/arduino/arduino-cli/configuration`
- `github.com/arduino/arduino-cli/configuration.IsBundledInDesktopIDE` function has been removed.
- `github.com/arduino/arduino-cli/configuration.BundleToolsDirectories` has been renamed to `BuiltinToolsDirectories`
- `github.com/arduino/arduino-cli/configuration.IDEBundledLibrariesDir` has been renamed to `IDEBuiltinLibrariesDir`
## 0.26.0
### `github.com/arduino/arduino-cli/commands.DownloadToolRelease`, and `InstallToolRelease` functions have been removed
5 changes: 5 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
@@ -9,6 +9,11 @@
- `downloads` - directory used to stage downloaded archives during Boards/Library Manager installations.
- `user` - the equivalent of the Arduino IDE's ["sketchbook" directory][sketchbook directory]. Library Manager
installations are made to the `libraries` subdirectory of the user directory.
- `builtin.libraries` - the libraries in this directory will be available to all platforms without the need for the
user to install them, but with the lowest priority over other installed libraries with the same name, it's the
equivalent of the Arduino IDE's bundled libraries directory.
- `builtin.tools` - it's a list of directories of tools that will be available to all platforms without the need for
the user to install them, it's the equivalent of the Arduino IDE 1.x bundled tools directory.
- `library` - configuration options relating to Arduino libraries.
- `enable_unsafe_install` - set to `true` to enable the use of the `--git-url` and `--zip-file` flags with
[`arduino-cli lib install`][arduino cli lib install]. These are considered "unsafe" installation methods because
5 changes: 2 additions & 3 deletions docs/sketch-build-process.md
Original file line number Diff line number Diff line change
@@ -130,9 +130,8 @@ The "location priority" is determined as follows (in order of highest to lowest
([`{runtime.platform.path}/libraries`](platform-specification.md#global-predefined-properties))
1. The library is bundled with the [referenced](platform-specification.md#referencing-another-core-variant-or-tool)
board platform/core
1. The library is bundled with the Arduino IDE
([`{runtime.ide.path}/libraries`](platform-specification.md#global-predefined-properties))
- This location is only used by Arduino CLI when it's located in the Arduino IDE installation folder
1. The library is bundled with the Arduino IDE (this location is determined by the Arduino CLI configuration setting
`directories.builtin.libraries`)

#### Location priorities in Arduino Web Editor

86 changes: 74 additions & 12 deletions internal/integrationtest/arduino-cli.go
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ package integrationtest
import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"os"
@@ -28,6 +29,7 @@ import (

"github.com/arduino/arduino-cli/executils"
"github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"github.com/arduino/arduino-cli/rpc/cc/arduino/cli/settings/v1"
"github.com/arduino/go-paths-helper"
"github.com/fatih/color"
"github.com/stretchr/testify/require"
@@ -61,17 +63,18 @@ func CreateArduinoCLIWithEnvironment(t *testing.T) (*testsuite.Environment, *Ard

// ArduinoCLI is an Arduino CLI client.
type ArduinoCLI struct {
path *paths.Path
t *require.Assertions
proc *executils.Process
cliEnvVars []string
cliConfigPath *paths.Path
stagingDir *paths.Path
dataDir *paths.Path
sketchbookDir *paths.Path
daemonAddr string
daemonConn *grpc.ClientConn
daemonClient commands.ArduinoCoreServiceClient
path *paths.Path
t *require.Assertions
proc *executils.Process
cliEnvVars []string
cliConfigPath *paths.Path
stagingDir *paths.Path
dataDir *paths.Path
sketchbookDir *paths.Path
daemonAddr string
daemonConn *grpc.ClientConn
daemonClient commands.ArduinoCoreServiceClient
daemonSettingsClient settings.SettingsServiceClient
}

// ArduinoCLIConfig is the configuration of the ArduinoCLI client
@@ -196,7 +199,7 @@ func (cli *ArduinoCLI) StartDaemon(verbose bool) string {
cli.t.NoError(err)
cli.daemonConn = conn
cli.daemonClient = commands.NewArduinoCoreServiceClient(conn)

cli.daemonSettingsClient = settings.NewSettingsServiceClient(conn)
return cli.daemonAddr
}

@@ -226,6 +229,17 @@ func (cli *ArduinoCLI) Create() *ArduinoCLIInstance {
}
}

// SetValue calls the "SetValue" gRPC method.
func (cli *ArduinoCLI) SetValue(key, jsonData string) error {
req := &settings.SetValueRequest{
Key: key,
JsonData: jsonData,
}
logCallf(">>> SetValue(%+v)\n", req)
_, err := cli.daemonSettingsClient.SetValue(context.Background(), req)
return err
}

// Init calls the "Init" gRPC method.
func (inst *ArduinoCLIInstance) Init(profile string, sketchPath string, respCB func(*commands.InitResponse)) error {
initReq := &commands.InitRequest{
@@ -302,3 +316,51 @@ func (inst *ArduinoCLIInstance) Compile(ctx context.Context, fqbn, sketchPath st
logCallf(">>> Compile(%v %v)\n", fqbn, sketchPath)
return compileCl, err
}

// LibraryList calls the "LibraryList" gRPC method.
func (inst *ArduinoCLIInstance) LibraryList(ctx context.Context, name, fqbn string, all, updatable bool) (*commands.LibraryListResponse, error) {
req := &commands.LibraryListRequest{
Instance: inst.instance,
Name: name,
Fqbn: fqbn,
All: all,
Updatable: updatable,
}
logCallf(">>> LibraryList(%v) -> ", req)
resp, err := inst.cli.daemonClient.LibraryList(ctx, req)
logCallf("err=%v\n", err)
r, _ := json.MarshalIndent(resp, " ", " ")
logCallf("<<< LibraryList resp: %s\n", string(r))
return resp, err
}

// LibraryInstall calls the "LibraryInstall" gRPC method.
func (inst *ArduinoCLIInstance) LibraryInstall(ctx context.Context, name, version string, noDeps, noOverwrite, installAsBundled bool) (commands.ArduinoCoreService_LibraryInstallClient, error) {
installLocation := commands.LibraryInstallLocation_LIBRARY_INSTALL_LOCATION_USER
if installAsBundled {
installLocation = commands.LibraryInstallLocation_LIBRARY_INSTALL_LOCATION_BUILTIN
}
req := &commands.LibraryInstallRequest{
Instance: inst.instance,
Name: name,
Version: version,
NoDeps: noDeps,
NoOverwrite: noOverwrite,
InstallLocation: installLocation,
}
installCl, err := inst.cli.daemonClient.LibraryInstall(ctx, req)
logCallf(">>> LibraryInstall(%+v)\n", req)
return installCl, err
}

// LibraryUninstall calls the "LibraryUninstall" gRPC method.
func (inst *ArduinoCLIInstance) LibraryUninstall(ctx context.Context, name, version string) (commands.ArduinoCoreService_LibraryUninstallClient, error) {
req := &commands.LibraryUninstallRequest{
Instance: inst.instance,
Name: name,
Version: version,
}
installCl, err := inst.cli.daemonClient.LibraryUninstall(ctx, req)
logCallf(">>> LibraryUninstall(%+v)\n", req)
return installCl, err
}
156 changes: 156 additions & 0 deletions internal/integrationtest/daemon/daemon_lib_install_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
// This file is part of arduino-cli.
//
// Copyright 2022 ARDUINO SA (http://www.arduino.cc/)
//
// This software is released under the GNU General Public License version 3,
// which covers the main part of arduino-cli.
// The terms of this license can be found at:
// https://www.gnu.org/licenses/gpl-3.0.en.html
//
// You can be released from the requirements of the above licenses by purchasing
// a commercial license. Buying such a license is mandatory if you want to
// modify or otherwise use the software for commercial activities involving the
// Arduino software without disclosing the source code of your own applications.
// To purchase a commercial license, send an email to license@arduino.cc.

package daemon_test

import (
"context"
"fmt"
"io"
"testing"

"github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"github.com/stretchr/testify/require"
)

func TestDaemonBundleLibInstall(t *testing.T) {
env, cli := createEnvForDaemon(t)
defer env.CleanUp()

grpcInst := cli.Create()
require.NoError(t, grpcInst.Init("", "", func(ir *commands.InitResponse) {
fmt.Printf("INIT> %v\n", ir.GetMessage())
}))

// Install libraries in bundled dir
{
instCl, err := grpcInst.LibraryInstall(context.Background(), "Arduino_BuiltIn", "", false, false, true)
require.NoError(t, err)
for {
msg, err := instCl.Recv()
if err == io.EOF {
break
}
require.NoError(t, err)
fmt.Printf("LIB INSTALL> %+v\n", msg)
}
}

// Check if libraries are installed as expected
{
resp, err := grpcInst.LibraryList(context.Background(), "", "", true, false)
require.NoError(t, err)
libsAndLocation := map[string]commands.LibraryLocation{}
for _, lib := range resp.GetInstalledLibraries() {
libsAndLocation[lib.Library.Name] = lib.Library.Location
}
require.Contains(t, libsAndLocation, "Ethernet")
require.Contains(t, libsAndLocation, "SD")
require.Contains(t, libsAndLocation, "Firmata")
require.Equal(t, libsAndLocation["Ethernet"], commands.LibraryLocation_LIBRARY_LOCATION_BUILTIN)
require.Equal(t, libsAndLocation["SD"], commands.LibraryLocation_LIBRARY_LOCATION_BUILTIN)
require.Equal(t, libsAndLocation["Firmata"], commands.LibraryLocation_LIBRARY_LOCATION_BUILTIN)
}

// Install a library in sketchbook to override bundled
{
instCl, err := grpcInst.LibraryInstall(context.Background(), "Ethernet", "", false, false, false)
require.NoError(t, err)
for {
msg, err := instCl.Recv()
if err == io.EOF {
break
}
require.NoError(t, err)
fmt.Printf("LIB INSTALL> %+v\n", msg)
}
}

// Check if libraries are installed as expected
installedEthernetVersion := ""
{
resp, err := grpcInst.LibraryList(context.Background(), "", "", true, false)
require.NoError(t, err)
libsAndLocation := map[string]commands.LibraryLocation{}
for _, lib := range resp.GetInstalledLibraries() {
libsAndLocation[lib.Library.Name] = lib.Library.Location
if lib.Library.Name == "Ethernet" {
installedEthernetVersion = lib.Library.Version
}
}
require.Contains(t, libsAndLocation, "Ethernet")
require.Contains(t, libsAndLocation, "SD")
require.Contains(t, libsAndLocation, "Firmata")
require.Equal(t, libsAndLocation["Ethernet"], commands.LibraryLocation_LIBRARY_LOCATION_USER)
require.Equal(t, libsAndLocation["SD"], commands.LibraryLocation_LIBRARY_LOCATION_BUILTIN)
require.Equal(t, libsAndLocation["Firmata"], commands.LibraryLocation_LIBRARY_LOCATION_BUILTIN)
}

// Remove library from sketchbook
{
uninstCl, err := grpcInst.LibraryUninstall(context.Background(), "Ethernet", installedEthernetVersion)
require.NoError(t, err)
for {
msg, err := uninstCl.Recv()
if err == io.EOF {
break
}
require.NoError(t, err)
fmt.Printf("LIB INSTALL> %+v\n", msg)
}
}

// Check if libraries are installed as expected
{
resp, err := grpcInst.LibraryList(context.Background(), "", "", true, false)
require.NoError(t, err)
libsAndLocation := map[string]commands.LibraryLocation{}
for _, lib := range resp.GetInstalledLibraries() {
libsAndLocation[lib.Library.Name] = lib.Library.Location
}
require.Contains(t, libsAndLocation, "Ethernet")
require.Contains(t, libsAndLocation, "SD")
require.Contains(t, libsAndLocation, "Firmata")
require.Equal(t, libsAndLocation["Ethernet"], commands.LibraryLocation_LIBRARY_LOCATION_BUILTIN)
require.Equal(t, libsAndLocation["SD"], commands.LibraryLocation_LIBRARY_LOCATION_BUILTIN)
require.Equal(t, libsAndLocation["Firmata"], commands.LibraryLocation_LIBRARY_LOCATION_BUILTIN)
}

// Un-Set builtin libraries dir
err := cli.SetValue("directories.builtin.libraries", `""`)
require.NoError(t, err)

// Re-init
require.NoError(t, grpcInst.Init("", "", func(ir *commands.InitResponse) {
fmt.Printf("INIT> %v\n", ir.GetMessage())
}))

// Install libraries in bundled dir (should now fail)
{
instCl, err := grpcInst.LibraryInstall(context.Background(), "Arduino_BuiltIn", "", false, false, true)
require.NoError(t, err)
for {
msg, err := instCl.Recv()
if err == io.EOF {
require.FailNow(t, "LibraryInstall is supposed to fail because builtin libraries directory is not set")
}
if err != nil {
fmt.Println("LIB INSTALL ERROR:", err)
break
}
fmt.Printf("LIB INSTALL> %+v\n", msg)
}
}
}
10 changes: 5 additions & 5 deletions legacy/builder/libraries_loader.go
Original file line number Diff line number Diff line change
@@ -36,11 +36,11 @@ func (s *LibrariesLoader) Run(ctx *types.Context) error {
ctx.LibrariesManager = lm

builtInLibrariesFolders := ctx.BuiltInLibrariesDirs
if err := builtInLibrariesFolders.ToAbs(); err != nil {
return errors.WithStack(err)
}
for _, folder := range builtInLibrariesFolders {
lm.AddLibrariesDir(folder, libraries.IDEBuiltIn)
if builtInLibrariesFolders != nil {
if err := builtInLibrariesFolders.ToAbs(); err != nil {
return errors.WithStack(err)
}
lm.AddLibrariesDir(builtInLibrariesFolders, libraries.IDEBuiltIn)
}

if ctx.ActualPlatform != ctx.TargetPlatform {
2 changes: 1 addition & 1 deletion legacy/builder/test/builder_test.go
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@ func prepareBuilderTestContext(t *testing.T, sketchPath *paths.Path, fqbn string
FQBN: parseFQBN(t, fqbn),
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
OtherLibrariesDirs: paths.NewPathList("libraries"),
ArduinoAPIVersion: "10600",
Verbose: false,
1 change: 0 additions & 1 deletion legacy/builder/test/create_build_options_map_test.go
Original file line number Diff line number Diff line change
@@ -43,7 +43,6 @@ func TestCreateBuildOptionsMap(t *testing.T) {

require.Equal(t, `{
"additionalFiles": "",
"builtInLibrariesFolders": "",
"builtInToolsFolders": "tools",
"compiler.optimization_flags": "-Os",
"customBuildProperties": "",
10 changes: 5 additions & 5 deletions legacy/builder/test/ctags_runner_test.go
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ func TestCTagsRunner(t *testing.T) {
ctx := &types.Context{
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
OtherLibrariesDirs: paths.NewPathList("libraries"),
SketchLocation: sketchLocation,
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
@@ -84,7 +84,7 @@ func TestCTagsRunnerSketchWithClass(t *testing.T) {
ctx := &types.Context{
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
OtherLibrariesDirs: paths.NewPathList("libraries"),
SketchLocation: sketchLocation,
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
@@ -132,7 +132,7 @@ func TestCTagsRunnerSketchWithTypename(t *testing.T) {
ctx := &types.Context{
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
OtherLibrariesDirs: paths.NewPathList("libraries"),
SketchLocation: sketchLocation,
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
@@ -179,7 +179,7 @@ func TestCTagsRunnerSketchWithNamespace(t *testing.T) {
ctx := &types.Context{
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
OtherLibrariesDirs: paths.NewPathList("libraries"),
SketchLocation: sketchLocation,
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
@@ -225,7 +225,7 @@ func TestCTagsRunnerSketchWithTemplates(t *testing.T) {
ctx := &types.Context{
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
OtherLibrariesDirs: paths.NewPathList("libraries"),
SketchLocation: sketchLocation,
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
16 changes: 8 additions & 8 deletions legacy/builder/test/includes_to_include_folders_test.go
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ func TestIncludesToIncludeFolders(t *testing.T) {
ctx := &types.Context{
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
OtherLibrariesDirs: paths.NewPathList("libraries"),
SketchLocation: paths.New("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino"),
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
@@ -68,7 +68,7 @@ func TestIncludesToIncludeFoldersSketchWithIfDef(t *testing.T) {
ctx := &types.Context{
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
OtherLibrariesDirs: paths.NewPathList("libraries"),
SketchLocation: paths.New("SketchWithIfDef", "SketchWithIfDef.ino"),
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
@@ -103,7 +103,7 @@ func TestIncludesToIncludeFoldersIRremoteLibrary(t *testing.T) {
ctx := &types.Context{
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
OtherLibrariesDirs: paths.NewPathList("libraries"),
SketchLocation: paths.New("sketch9", "sketch9.ino"),
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
@@ -141,7 +141,7 @@ func TestIncludesToIncludeFoldersANewLibrary(t *testing.T) {
ctx := &types.Context{
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
OtherLibrariesDirs: paths.NewPathList("libraries"),
SketchLocation: paths.New("sketch10", "sketch10.ino"),
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
@@ -176,7 +176,7 @@ func TestIncludesToIncludeFoldersDuplicateLibs(t *testing.T) {
ctx := &types.Context{
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware", "user_hardware"),
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
SketchLocation: paths.New("user_hardware", "my_avr_platform", "avr", "libraries", "SPI", "examples", "BarometricPressureSensor", "BarometricPressureSensor.ino"),
FQBN: parseFQBN(t, "my_avr_platform:avr:custom_yun"),
ArduinoAPIVersion: "10600",
@@ -213,7 +213,7 @@ func TestIncludesToIncludeFoldersDuplicateLibsWithConflictingLibsOutsideOfPlatfo
ctx := &types.Context{
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware", "user_hardware"),
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
OtherLibrariesDirs: paths.NewPathList("libraries"),
SketchLocation: paths.New("user_hardware", "my_avr_platform", "avr", "libraries", "SPI", "examples", "BarometricPressureSensor", "BarometricPressureSensor.ino"),
FQBN: parseFQBN(t, "my_avr_platform:avr:custom_yun"),
@@ -251,7 +251,7 @@ func TestIncludesToIncludeFoldersDuplicateLibs2(t *testing.T) {
ctx := &types.Context{
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware", "downloaded_board_manager_stuff"),
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
OtherLibrariesDirs: paths.NewPathList("libraries"),
SketchLocation: paths.New("sketch_usbhost", "sketch_usbhost.ino"),
FQBN: parseFQBN(t, "arduino:samd:arduino_zero_native"),
@@ -289,7 +289,7 @@ func TestIncludesToIncludeFoldersSubfolders(t *testing.T) {
ctx := &types.Context{
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
OtherLibrariesDirs: paths.NewPathList("libraries"),
SketchLocation: paths.New("sketch_with_subfolders", "sketch_with_subfolders.ino"),
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
8 changes: 4 additions & 4 deletions legacy/builder/test/libraries_loader_test.go
Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@ func TestLoadLibrariesAVR(t *testing.T) {

ctx := &types.Context{
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
OtherLibrariesDirs: paths.NewPathList("libraries"),
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
}
@@ -152,7 +152,7 @@ func TestLoadLibrariesSAM(t *testing.T) {

ctx := &types.Context{
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
OtherLibrariesDirs: paths.NewPathList("libraries"),
FQBN: parseFQBN(t, "arduino:sam:arduino_due_x_dbg"),
}
@@ -235,7 +235,7 @@ func TestLoadLibrariesAVRNoDuplicateLibrariesFolders(t *testing.T) {

ctx := &types.Context{
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
OtherLibrariesDirs: paths.NewPathList("libraries", filepath.Join("downloaded_hardware", "arduino", "avr", "libraries")),
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
}
@@ -264,7 +264,7 @@ func TestLoadLibrariesMyAVRPlatform(t *testing.T) {

ctx := &types.Context{
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "user_hardware", "downloaded_hardware"),
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
OtherLibrariesDirs: paths.NewPathList("libraries", filepath.Join("downloaded_hardware", "arduino", "avr", "libraries")),
FQBN: parseFQBN(t, "my_avr_platform:avr:custom_yun"),
}
8 changes: 4 additions & 4 deletions legacy/builder/test/merge_sketch_with_bootloader_test.go
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ func TestMergeSketchWithBootloader(t *testing.T) {
ctx := &types.Context{
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
OtherLibrariesDirs: paths.NewPathList("libraries"),
SketchLocation: paths.New("sketch1", "sketch1.ino"),
FQBN: parseFQBN(t, "arduino:avr:uno"),
@@ -104,7 +104,7 @@ func TestMergeSketchWithBootloaderSketchInBuildPath(t *testing.T) {
ctx := &types.Context{
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
OtherLibrariesDirs: paths.NewPathList("libraries"),
SketchLocation: paths.New("sketch1", "sketch1.ino"),
FQBN: parseFQBN(t, "arduino:avr:uno"),
@@ -175,7 +175,7 @@ func TestMergeSketchWithBootloaderWhenNoBootloaderAvailable(t *testing.T) {
ctx := &types.Context{
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
OtherLibrariesDirs: paths.NewPathList("libraries"),
SketchLocation: paths.New("sketch1", "sketch1.ino"),
FQBN: parseFQBN(t, "arduino:avr:uno"),
@@ -213,7 +213,7 @@ func TestMergeSketchWithBootloaderPathIsParameterized(t *testing.T) {
ctx := &types.Context{
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware", "user_hardware"),
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
OtherLibrariesDirs: paths.NewPathList("libraries"),
SketchLocation: paths.New("sketch1", "sketch1.ino"),
FQBN: parseFQBN(t, "my_avr_platform:avr:mymega:cpu=atmega2560"),
42 changes: 21 additions & 21 deletions legacy/builder/test/prototypes_adder_test.go
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@ func TestPrototypesAdderBridgeExample(t *testing.T) {
ctx := &types.Context{
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
OtherLibrariesDirs: paths.NewPathList("libraries"),
SketchLocation: sketchLocation,
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
@@ -77,7 +77,7 @@ func TestPrototypesAdderSketchWithIfDef(t *testing.T) {
ctx := &types.Context{
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
OtherLibrariesDirs: paths.NewPathList("libraries"),
SketchLocation: paths.New("SketchWithIfDef", "SketchWithIfDef.ino"),
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
@@ -117,7 +117,7 @@ func TestPrototypesAdderBaladuino(t *testing.T) {
ctx := &types.Context{
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
OtherLibrariesDirs: paths.NewPathList("libraries"),
SketchLocation: paths.New("Baladuino", "Baladuino.ino"),
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
@@ -157,7 +157,7 @@ func TestPrototypesAdderCharWithEscapedDoubleQuote(t *testing.T) {
ctx := &types.Context{
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
OtherLibrariesDirs: paths.NewPathList("libraries"),
SketchLocation: paths.New("CharWithEscapedDoubleQuote", "CharWithEscapedDoubleQuote.ino"),
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
@@ -197,7 +197,7 @@ func TestPrototypesAdderIncludeBetweenMultilineComment(t *testing.T) {
ctx := &types.Context{
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
OtherLibrariesDirs: paths.NewPathList("libraries"),
SketchLocation: paths.New("IncludeBetweenMultilineComment", "IncludeBetweenMultilineComment.ino"),
FQBN: parseFQBN(t, "arduino:sam:arduino_due_x_dbg"),
@@ -237,7 +237,7 @@ func TestPrototypesAdderLineContinuations(t *testing.T) {
ctx := &types.Context{
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
OtherLibrariesDirs: paths.NewPathList("libraries"),
SketchLocation: paths.New("LineContinuations", "LineContinuations.ino"),
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
@@ -277,7 +277,7 @@ func TestPrototypesAdderStringWithComment(t *testing.T) {
ctx := &types.Context{
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
OtherLibrariesDirs: paths.NewPathList("libraries"),
SketchLocation: paths.New("StringWithComment", "StringWithComment.ino"),
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
@@ -317,7 +317,7 @@ func TestPrototypesAdderSketchWithStruct(t *testing.T) {
ctx := &types.Context{
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
OtherLibrariesDirs: paths.NewPathList("libraries"),
SketchLocation: paths.New("SketchWithStruct", "SketchWithStruct.ino"),
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
@@ -365,7 +365,7 @@ func TestPrototypesAdderSketchWithConfig(t *testing.T) {
ctx := &types.Context{
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
OtherLibrariesDirs: paths.NewPathList("libraries"),
SketchLocation: sketchLocation,
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
@@ -411,7 +411,7 @@ func TestPrototypesAdderSketchNoFunctionsTwoFiles(t *testing.T) {
ctx := &types.Context{
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
OtherLibrariesDirs: paths.NewPathList("libraries"),
SketchLocation: paths.New("sketch_no_functions_two_files", "sketch_no_functions_two_files.ino"),
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
@@ -451,7 +451,7 @@ func TestPrototypesAdderSketchNoFunctions(t *testing.T) {
ctx := &types.Context{
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
OtherLibrariesDirs: paths.NewPathList("libraries"),
SketchLocation: paths.New("sketch_no_functions", "sketch_no_functions.ino"),
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
@@ -497,7 +497,7 @@ func TestPrototypesAdderSketchWithDefaultArgs(t *testing.T) {
ctx := &types.Context{
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
OtherLibrariesDirs: paths.NewPathList("libraries"),
SketchLocation: sketchLocation,
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
@@ -540,7 +540,7 @@ func TestPrototypesAdderSketchWithInlineFunction(t *testing.T) {
ctx := &types.Context{
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
OtherLibrariesDirs: paths.NewPathList("libraries"),
SketchLocation: sketchLocation,
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
@@ -594,7 +594,7 @@ func TestPrototypesAdderSketchWithFunctionSignatureInsideIFDEF(t *testing.T) {
ctx := &types.Context{
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
OtherLibrariesDirs: paths.NewPathList("libraries"),
SketchLocation: sketchLocation,
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
@@ -638,7 +638,7 @@ func TestPrototypesAdderSketchWithUSBCON(t *testing.T) {
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
OtherLibrariesDirs: paths.NewPathList("libraries"),
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
SketchLocation: sketchLocation,
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
ArduinoAPIVersion: "10600",
@@ -679,7 +679,7 @@ func TestPrototypesAdderSketchWithTypename(t *testing.T) {

ctx := &types.Context{
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
BuiltInLibrariesDirs: paths.NewPathList("libraries", "downloaded_libraries"),
BuiltInLibrariesDirs: paths.New("libraries", "downloaded_libraries"),
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
SketchLocation: sketchLocation,
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
@@ -728,7 +728,7 @@ func TestPrototypesAdderSketchWithIfDef2(t *testing.T) {
ctx := &types.Context{
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
OtherLibrariesDirs: paths.NewPathList("libraries"),
SketchLocation: sketchLocation,
FQBN: parseFQBN(t, "arduino:avr:yun"),
@@ -774,7 +774,7 @@ func TestPrototypesAdderSketchWithIfDef2SAM(t *testing.T) {
ctx := &types.Context{
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
OtherLibrariesDirs: paths.NewPathList("libraries"),
SketchLocation: sketchLocation,
FQBN: parseFQBN(t, "arduino:sam:arduino_due_x_dbg"),
@@ -820,7 +820,7 @@ func TestPrototypesAdderSketchWithConst(t *testing.T) {
ctx := &types.Context{
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
OtherLibrariesDirs: paths.NewPathList("libraries"),
SketchLocation: sketchLocation,
FQBN: parseFQBN(t, "arduino:avr:uno"),
@@ -860,7 +860,7 @@ func TestPrototypesAdderSketchWithDosEol(t *testing.T) {
ctx := &types.Context{
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
OtherLibrariesDirs: paths.NewPathList("libraries"),
SketchLocation: paths.New("eol_processing", "eol_processing.ino"),
FQBN: parseFQBN(t, "arduino:avr:uno"),
@@ -900,7 +900,7 @@ func TestPrototypesAdderSketchWithSubstringFunctionMember(t *testing.T) {
ctx := &types.Context{
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
OtherLibrariesDirs: paths.NewPathList("libraries"),
SketchLocation: sketchLocation,
FQBN: parseFQBN(t, "arduino:avr:uno"),
2 changes: 1 addition & 1 deletion legacy/builder/test/store_build_options_map_test.go
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ func TestStoreBuildOptionsMap(t *testing.T) {
ctx := &types.Context{
HardwareDirs: paths.NewPathList("hardware"),
BuiltInToolsDirs: paths.NewPathList("tools"),
BuiltInLibrariesDirs: paths.NewPathList("built-in libraries"),
BuiltInLibrariesDirs: paths.New("built-in libraries"),
OtherLibrariesDirs: paths.NewPathList("libraries"),
SketchLocation: paths.New("sketchLocation"),
FQBN: parseFQBN(t, "my:nice:fqbn"),
Original file line number Diff line number Diff line change
@@ -210,7 +210,7 @@ func makeDefaultContext(t *testing.T) *types.Context {
ctx := &types.Context{
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware", "downloaded_board_manager_stuff"),
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
OtherLibrariesDirs: paths.NewPathList("libraries"),
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
ArduinoAPIVersion: "10607",
8 changes: 5 additions & 3 deletions legacy/builder/types/context.go
Original file line number Diff line number Diff line change
@@ -68,7 +68,7 @@ type Context struct {
// Build options
HardwareDirs paths.PathList
BuiltInToolsDirs paths.PathList
BuiltInLibrariesDirs paths.PathList
BuiltInLibrariesDirs *paths.Path
OtherLibrariesDirs paths.PathList
LibraryDirs paths.PathList // List of paths pointing to individual library root folders
SketchLocation *paths.Path // SketchLocation points to the main Sketch file
@@ -208,7 +208,9 @@ func (ctx *Context) ExtractBuildOptions() *properties.Map {
opts := properties.NewMap()
opts.Set("hardwareFolders", strings.Join(ctx.HardwareDirs.AsStrings(), ","))
opts.Set("builtInToolsFolders", strings.Join(ctx.BuiltInToolsDirs.AsStrings(), ","))
opts.Set("builtInLibrariesFolders", strings.Join(ctx.BuiltInLibrariesDirs.AsStrings(), ","))
if ctx.BuiltInLibrariesDirs != nil {
opts.Set("builtInLibrariesFolders", ctx.BuiltInLibrariesDirs.String())
}
opts.Set("otherLibrariesFolders", strings.Join(ctx.OtherLibrariesDirs.AsStrings(), ","))
opts.SetPath("sketchLocation", ctx.SketchLocation)
var additionalFilesRelative []string
@@ -233,7 +235,7 @@ func (ctx *Context) ExtractBuildOptions() *properties.Map {
func (ctx *Context) InjectBuildOptions(opts *properties.Map) {
ctx.HardwareDirs = paths.NewPathList(strings.Split(opts.Get("hardwareFolders"), ",")...)
ctx.BuiltInToolsDirs = paths.NewPathList(strings.Split(opts.Get("builtInToolsFolders"), ",")...)
ctx.BuiltInLibrariesDirs = paths.NewPathList(strings.Split(opts.Get("builtInLibrariesFolders"), ",")...)
ctx.BuiltInLibrariesDirs = paths.New(opts.Get("builtInLibrariesFolders"))
ctx.OtherLibrariesDirs = paths.NewPathList(strings.Split(opts.Get("otherLibrariesFolders"), ",")...)
ctx.SketchLocation = opts.GetPath("sketchLocation")
fqbn, err := cores.ParseFQBN(opts.Get("fqbn"))
61 changes: 61 additions & 0 deletions legacy/builder/types/context_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// This file is part of arduino-cli.
//
// Copyright 2022 ARDUINO SA (http://www.arduino.cc/)
//
// This software is released under the GNU General Public License version 3,
// which covers the main part of arduino-cli.
// The terms of this license can be found at:
// https://www.gnu.org/licenses/gpl-3.0.en.html
//
// You can be released from the requirements of the above licenses by purchasing
// a commercial license. Buying such a license is mandatory if you want to
// modify or otherwise use the software for commercial activities involving the
// Arduino software without disclosing the source code of your own applications.
// To purchase a commercial license, send an email to license@arduino.cc.

package types

import (
"testing"

"github.com/arduino/arduino-cli/arduino/cores"
paths "github.com/arduino/go-paths-helper"
"github.com/stretchr/testify/require"
)

func TestInjectBuildOption(t *testing.T) {
fqbn, err := cores.ParseFQBN("aaa:bbb:ccc")
require.NoError(t, err)

{
ctx := &Context{
HardwareDirs: paths.NewPathList("aaa", "bbb"),
BuiltInToolsDirs: paths.NewPathList("ccc", "ddd"),
BuiltInLibrariesDirs: paths.New("eee"),
OtherLibrariesDirs: paths.NewPathList("fff", "ggg"),
SketchLocation: paths.New("hhh"),
FQBN: fqbn,
ArduinoAPIVersion: "iii",
CustomBuildProperties: []string{"jjj", "kkk"},
OptimizationFlags: "lll",
}
newCtx := &Context{}
newCtx.InjectBuildOptions(ctx.ExtractBuildOptions())
require.Equal(t, ctx, newCtx)
}
{
ctx := &Context{
HardwareDirs: paths.NewPathList("aaa", "bbb"),
BuiltInToolsDirs: paths.NewPathList("ccc", "ddd"),
OtherLibrariesDirs: paths.NewPathList("fff", "ggg"),
SketchLocation: paths.New("hhh"),
FQBN: fqbn,
ArduinoAPIVersion: "iii",
CustomBuildProperties: []string{"jjj", "kkk"},
OptimizationFlags: "lll",
}
newCtx := &Context{}
newCtx.InjectBuildOptions(ctx.ExtractBuildOptions())
require.Equal(t, ctx, newCtx)
}
}
872 changes: 472 additions & 400 deletions rpc/cc/arduino/cli/commands/v1/lib.pb.go

Large diffs are not rendered by default.

14 changes: 12 additions & 2 deletions rpc/cc/arduino/cli/commands/v1/lib.proto
Original file line number Diff line number Diff line change
@@ -48,6 +48,16 @@ message LibraryInstallRequest {
// Set to true to skip installation if a different version of the library or
// one of its dependencies is already installed, defaults to false.
bool no_overwrite = 5;
// Install the library and dependencies in the specified location
LibraryInstallLocation install_location = 6;
}

enum LibraryInstallLocation {
// In the `libraries` subdirectory of the user directory (sketchbook). This is
// the default if not specified.
LIBRARY_INSTALL_LOCATION_USER = 0;
// In the configured 'builtin.libraries' directory.
LIBRARY_INSTALL_LOCATION_BUILTIN = 1;
}

message LibraryInstallResponse {
@@ -307,8 +317,8 @@ enum LibraryLayout {
}

enum LibraryLocation {
// In the `libraries` subdirectory of the Arduino IDE installation.
LIBRARY_LOCATION_IDE_BUILTIN = 0;
// In the configured 'builtin.libraries' directory.
LIBRARY_LOCATION_BUILTIN = 0;
// In the `libraries` subdirectory of the user directory (sketchbook).
LIBRARY_LOCATION_USER = 1;
// In the `libraries` subdirectory of a platform.