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
Next Next commit
Removed IDE-bundle autodetection
  • Loading branch information
cmaglie committed Sep 1, 2022
commit fd5dc838672cf5370aeb9c5f0c90419617a2a07f
2 changes: 1 addition & 1 deletion arduino/cores/packagemanager/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions cli/config/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
27 changes: 3 additions & 24 deletions commands/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import (
"context"
"fmt"
"io"
"path/filepath"
"sort"
"strings"

"github.com/arduino/arduino-cli/arduino"
Expand All @@ -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"
)

Expand Down Expand Up @@ -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()...)
Expand Down Expand Up @@ -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()
Expand Down
6 changes: 4 additions & 2 deletions commands/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,10 @@ 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 {
lm.AddLibrariesDir(bundledLibsDir, libraries.IDEBuiltIn)
if bundledLibsDir := configuration.IDEBuiltinLibrariesDir(configuration.Settings); bundledLibsDir != nil {
for _, d := range bundledLibsDir {
lm.AddLibrariesDir(d, libraries.IDEBuiltIn)
}
}

// Add libraries directory from config file
Expand Down
56 changes: 0 additions & 56 deletions configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -132,61 +131,6 @@ 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
}

// FindConfigFileInArgsOrWorkingDirectory returns the config file path using the
// argument '--config-file' (if specified) or looking in the current working dir
func FindConfigFileInArgsOrWorkingDirectory(args []string) string {
Expand Down
2 changes: 2 additions & 0 deletions configuration/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,7 @@ func SetDefaults(settings *viper.Viper) {
settings.BindEnv("directories.User", "ARDUINO_SKETCHBOOK_DIR")
settings.BindEnv("directories.Downloads", "ARDUINO_DOWNLOADS_DIR")
settings.BindEnv("directories.Data", "ARDUINO_DATA_DIR")
settings.BindEnv("directories.builtin.tools", "ARDUINO_BUILTIN_TOOLS_DIR")
settings.BindEnv("directories.builtin.libraires", "ARDUINO_BUILTIN_LIBRARIES_DIR")
settings.BindEnv("sketch.always_export_binaries", "ARDUINO_SKETCH_ALWAYS_EXPORT_BINARIES")
}
41 changes: 9 additions & 32 deletions configuration/directories.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,8 @@ 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)
}
for _, bundledHardwareDir := range BuiltinToolsDirectories(Settings) {
res.Add(bundledHardwareDir)
}

if settings.IsSet("directories.Data") {
Expand All @@ -50,34 +46,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 paths. Usually
// one of these directories is present in the Arduino IDE.
func IDEBuiltinLibrariesDir(settings *viper.Viper) paths.PathList {
return paths.NewPathList(Settings.GetStringSlice("directories.builtin.Libraries")...)
}

// LibrariesDir returns the full path to the user directory containing
Expand Down