@@ -21,7 +21,6 @@ import (
21
21
"errors"
22
22
"net/url"
23
23
"os"
24
- "path/filepath"
25
24
"strings"
26
25
27
26
"github.com/arduino/go-paths-helper"
@@ -30,41 +29,42 @@ import (
30
29
"github.com/sirupsen/logrus"
31
30
)
32
31
33
- var arduinoIDEDirectory * string
34
-
35
32
// IsBundledInDesktopIDE returns true if the CLI is bundled with the Arduino IDE.
36
- func IsBundledInDesktopIDE () bool {
37
- if arduinoIDEDirectory != nil {
38
- return * arduinoIDEDirectory != ""
33
+ func ( config * Configuration ) IsBundledInDesktopIDE () bool {
34
+ if config . IDEBundledCheckResult != nil {
35
+ return * config . IDEBundledCheckResult
39
36
}
40
- empty := ""
41
- arduinoIDEDirectory = & empty
37
+
38
+ res := false
39
+ config .IDEBundledCheckResult = & res
42
40
43
41
logrus .Info ("Checking if CLI is Bundled into the IDE" )
44
42
executable , err := os .Executable ()
45
43
if err != nil {
46
44
logrus .WithError (err ).Warn ("Cannot get executable path" )
47
45
return false
48
46
}
49
- executable , err = filepath . EvalSymlinks (executable )
50
- if err != nil {
51
- logrus .WithError (err ).Warn ("Cannot get executable path (symlinks error) " )
47
+ executablePath := paths . New (executable )
48
+ if err := executablePath . FollowSymLink (); err != nil {
49
+ logrus .WithError (err ).Warn ("Cannot get executable path" )
52
50
return false
53
51
}
54
- ideDir := filepath . Dir ( executable )
52
+ ideDir := executablePath . Parent ( )
55
53
logrus .Info ("Candidate IDE Directory: " , ideDir )
56
54
57
- tests := []string {"tools-builder" , "Examples/01.Basics/Blink" }
55
+ tests := []string {
56
+ "tools-builder" ,
57
+ "examples/01.Basics/Blink" ,
58
+ }
58
59
for _ , test := range tests {
59
- filePath := filepath .Join (ideDir , test )
60
- _ , err := os .Stat (filePath )
61
- if ! os .IsNotExist (err ) {
62
- arduinoIDEDirectory = & ideDir
63
- break
60
+ if ! ideDir .Join (test ).Exist () {
61
+ return false
64
62
}
65
63
}
66
64
67
- return * arduinoIDEDirectory != ""
65
+ config .ArduinoIDEDirectory = ideDir
66
+ res = true
67
+ return true
68
68
}
69
69
70
70
// LoadFromDesktopIDEPreferences loads the config from the Desktop IDE preferences.txt file
@@ -127,9 +127,9 @@ func proxyConfigsFromIDEPrefs(props properties.Map) error {
127
127
// IDEBundledLibrariesDir returns the libraries directory bundled in
128
128
// the Arduino IDE. If there is no Arduino IDE or the directory doesn't
129
129
// exists then nil is returned
130
- func IDEBundledLibrariesDir () * paths.Path {
131
- if IsBundledInDesktopIDE () {
132
- libDir := paths . New ( * arduinoIDEDirectory , "libraries" )
130
+ func ( config * Configuration ) IDEBundledLibrariesDir () * paths.Path {
131
+ if config . IsBundledInDesktopIDE () {
132
+ libDir := config . ArduinoIDEDirectory . Join ( "libraries" )
133
133
if libDir .IsDir () {
134
134
return libDir
135
135
}
0 commit comments