Skip to content

Commit cf75835

Browse files
committed
Removed IDE-bundle autodetection
1 parent 63f1e18 commit cf75835

File tree

7 files changed

+21
-115
lines changed

7 files changed

+21
-115
lines changed

Diff for: arduino/cores/packagemanager/loader.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func (pm *Builder) LoadHardware() []error {
3838
hardwareDirs := configuration.HardwareDirectories(configuration.Settings)
3939
merr := pm.LoadHardwareFromDirectories(hardwareDirs)
4040

41-
bundleToolDirs := configuration.BundleToolsDirectories(configuration.Settings)
41+
bundleToolDirs := configuration.BuiltinToolsDirectories(configuration.Settings)
4242
merr = append(merr, pm.LoadToolsFromBundleDirectories(bundleToolDirs)...)
4343

4444
return merr

Diff for: cli/config/validate.go

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ var validMap = map[string]reflect.Kind{
3030
"directories.data": reflect.String,
3131
"directories.downloads": reflect.String,
3232
"directories.user": reflect.String,
33+
"directories.builtin.tools": reflect.String,
34+
"directories.builtin.libraries": reflect.String,
3335
"library.enable_unsafe_install": reflect.Bool,
3436
"logging.file": reflect.String,
3537
"logging.format": reflect.String,

Diff for: commands/compile/compile.go

+3-24
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ import (
1919
"context"
2020
"fmt"
2121
"io"
22-
"path/filepath"
23-
"sort"
2422
"strings"
2523

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

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

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

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

164+
builderCtx.BuiltInLibrariesDirs = configuration.IDEBuiltinLibrariesDir(configuration.Settings)
165+
167166
// Will be deprecated.
168167
builderCtx.ArduinoAPIVersion = "10607"
169168

170-
// Check if Arduino IDE is installed and get it's libraries location.
171-
// TODO: Remove?
172-
dataDir := paths.New(configuration.Settings.GetString("directories.Data"))
173-
preferencesTxt := dataDir.Join("preferences.txt")
174-
ideProperties, err := properties.LoadFromPath(preferencesTxt)
175-
if err == nil {
176-
lastIdeSubProperties := ideProperties.SubTree("last").SubTree("ide")
177-
// Preferences can contain records from previous IDE versions. Find the latest one.
178-
var pathVariants []string
179-
for k := range lastIdeSubProperties.AsMap() {
180-
if strings.HasSuffix(k, ".hardwarepath") {
181-
pathVariants = append(pathVariants, k)
182-
}
183-
}
184-
sort.Strings(pathVariants)
185-
ideHardwarePath := lastIdeSubProperties.Get(pathVariants[len(pathVariants)-1])
186-
ideLibrariesPath := filepath.Join(filepath.Dir(ideHardwarePath), "libraries")
187-
builderCtx.BuiltInLibrariesDirs = paths.NewPathList(ideLibrariesPath)
188-
}
189-
190169
builderCtx.Stdout = outStream
191170
builderCtx.Stderr = errStream
192171
builderCtx.Clean = req.GetClean()

Diff for: commands/instances.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,10 @@ func Init(req *rpc.InitRequest, responseCallback func(r *rpc.InitResponse)) erro
389389

390390
if profile == nil {
391391
// Add directories of libraries bundled with IDE
392-
if bundledLibsDir := configuration.IDEBundledLibrariesDir(configuration.Settings); bundledLibsDir != nil {
393-
lm.AddLibrariesDir(bundledLibsDir, libraries.IDEBuiltIn)
392+
if bundledLibsDir := configuration.IDEBuiltinLibrariesDir(configuration.Settings); bundledLibsDir != nil {
393+
for _, d := range bundledLibsDir {
394+
lm.AddLibrariesDir(d, libraries.IDEBuiltIn)
395+
}
394396
}
395397

396398
// Add libraries directory from config file

Diff for: configuration/configuration.go

-56
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"github.com/arduino/arduino-cli/i18n"
2626
paths "github.com/arduino/go-paths-helper"
2727
"github.com/arduino/go-win32-utils"
28-
"github.com/sirupsen/logrus"
2928
"github.com/spf13/cobra"
3029
jww "github.com/spf13/jwalterweatherman"
3130
"github.com/spf13/viper"
@@ -132,61 +131,6 @@ func getDefaultUserDir() string {
132131
}
133132
}
134133

135-
// IsBundledInDesktopIDE returns true if the CLI is bundled with the Arduino IDE.
136-
func IsBundledInDesktopIDE(settings *viper.Viper) bool {
137-
// value is cached the first time we run the check
138-
if settings.IsSet("IDE.Bundled") {
139-
return settings.GetBool("IDE.Bundled")
140-
}
141-
142-
settings.Set("IDE.Bundled", false)
143-
settings.Set("IDE.Portable", false)
144-
145-
logrus.Info("Checking if CLI is Bundled into the IDE")
146-
executable, err := os.Executable()
147-
if err != nil {
148-
feedback.Errorf(tr("Cannot get executable path: %v"), err)
149-
return false
150-
}
151-
152-
executablePath, err := filepath.EvalSymlinks(executable)
153-
if err != nil {
154-
feedback.Errorf(tr("Cannot get executable path: %v"), err)
155-
return false
156-
}
157-
158-
ideDir := paths.New(executablePath).Parent()
159-
logrus.WithField("dir", ideDir).Trace("Candidate IDE directory")
160-
161-
// To determine if the CLI is bundled with an IDE, We check an arbitrary
162-
// number of folders that are part of the IDE install tree
163-
tests := []string{
164-
"tools-builder",
165-
"examples/01.Basics/Blink",
166-
}
167-
168-
for _, test := range tests {
169-
if !ideDir.Join(test).Exist() {
170-
// the test folder doesn't exist or is not accessible
171-
return false
172-
}
173-
}
174-
175-
logrus.Info("The CLI is bundled in the Arduino IDE")
176-
177-
// Persist IDE-related config settings
178-
settings.Set("IDE.Bundled", true)
179-
settings.Set("IDE.Directory", ideDir)
180-
181-
// Check whether this is a portable install
182-
if ideDir.Join("portable").Exist() {
183-
logrus.Info("The IDE installation is 'portable'")
184-
settings.Set("IDE.Portable", true)
185-
}
186-
187-
return true
188-
}
189-
190134
// FindConfigFileInArgsOrWorkingDirectory returns the config file path using the
191135
// argument '--config-file' (if specified) or looking in the current working dir
192136
func FindConfigFileInArgsOrWorkingDirectory(args []string) string {

Diff for: configuration/defaults.go

+2
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,7 @@ func SetDefaults(settings *viper.Viper) {
6565
settings.BindEnv("directories.User", "ARDUINO_SKETCHBOOK_DIR")
6666
settings.BindEnv("directories.Downloads", "ARDUINO_DOWNLOADS_DIR")
6767
settings.BindEnv("directories.Data", "ARDUINO_DATA_DIR")
68+
settings.BindEnv("directories.builtin.tools", "ARDUINO_BUILTIN_TOOLS_DIR")
69+
settings.BindEnv("directories.builtin.libraires", "ARDUINO_BUILTIN_LIBRARIES_DIR")
6870
settings.BindEnv("sketch.always_export_binaries", "ARDUINO_SKETCH_ALWAYS_EXPORT_BINARIES")
6971
}

Diff for: configuration/directories.go

+9-32
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,8 @@ import (
2424
func HardwareDirectories(settings *viper.Viper) paths.PathList {
2525
res := paths.PathList{}
2626

27-
if IsBundledInDesktopIDE(settings) {
28-
ideDir := paths.New(settings.GetString("IDE.Directory"))
29-
bundledHardwareDir := ideDir.Join("hardware")
30-
if bundledHardwareDir.IsDir() {
31-
res.Add(bundledHardwareDir)
32-
}
27+
for _, bundledHardwareDir := range BuiltinToolsDirectories(Settings) {
28+
res.Add(bundledHardwareDir)
3329
}
3430

3531
if settings.IsSet("directories.Data") {
@@ -50,34 +46,15 @@ func HardwareDirectories(settings *viper.Viper) paths.PathList {
5046
return res
5147
}
5248

53-
// BundleToolsDirectories returns all paths that may contains bundled-tools.
54-
func BundleToolsDirectories(settings *viper.Viper) paths.PathList {
55-
res := paths.PathList{}
56-
57-
if IsBundledInDesktopIDE(settings) {
58-
ideDir := paths.New(settings.GetString("IDE.Directory"))
59-
bundledToolsDir := ideDir.Join("hardware", "tools")
60-
if bundledToolsDir.IsDir() {
61-
res = append(res, bundledToolsDir)
62-
}
63-
}
64-
65-
return res
49+
// BuiltinToolsDirectories returns all paths that may contains bundled-tools.
50+
func BuiltinToolsDirectories(settings *viper.Viper) paths.PathList {
51+
return paths.NewPathList(settings.GetStringSlice("directories.builtin.Tools")...)
6652
}
6753

68-
// IDEBundledLibrariesDir returns the libraries directory bundled in
69-
// the Arduino IDE. If there is no Arduino IDE or the directory doesn't
70-
// exists then nil is returned
71-
func IDEBundledLibrariesDir(settings *viper.Viper) *paths.Path {
72-
if IsBundledInDesktopIDE(settings) {
73-
ideDir := paths.New(Settings.GetString("IDE.Directory"))
74-
libDir := ideDir.Join("libraries")
75-
if libDir.IsDir() {
76-
return libDir
77-
}
78-
}
79-
80-
return nil
54+
// IDEBuiltinLibrariesDir returns the IDE-bundled libraries paths. Usually
55+
// one of these directories is present in the Arduino IDE.
56+
func IDEBuiltinLibrariesDir(settings *viper.Viper) paths.PathList {
57+
return paths.NewPathList(Settings.GetStringSlice("directories.builtin.Libraries")...)
8158
}
8259

8360
// LibrariesDir returns the full path to the user directory containing

0 commit comments

Comments
 (0)