Skip to content

Commit 7c554cf

Browse files
committed
Removed IDE-bundle autodetection
1 parent 5332ffd commit 7c554cf

File tree

5 files changed

+17
-115
lines changed

5 files changed

+17
-115
lines changed

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

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

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

4343
return merr

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

@@ -121,7 +118,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
121118

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

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

162+
builderCtx.BuiltInLibrariesDirs = configuration.IDEBuiltinLibrariesDir(configuration.Settings)
163+
165164
// Will be deprecated.
166165
builderCtx.ArduinoAPIVersion = "10607"
167166

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

Diff for: commands/instances.go

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

351351
if profile == nil {
352352
// Add directories of libraries bundled with IDE
353-
if bundledLibsDir := configuration.IDEBundledLibrariesDir(configuration.Settings); bundledLibsDir != nil {
354-
lm.AddLibrariesDir(bundledLibsDir, libraries.IDEBuiltIn)
353+
if bundledLibsDir := configuration.IDEBuiltinLibrariesDir(configuration.Settings); bundledLibsDir != nil {
354+
for _, d := range bundledLibsDir {
355+
lm.AddLibrariesDir(d, libraries.IDEBuiltIn)
356+
}
355357
}
356358

357359
// 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/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)