@@ -21,7 +21,6 @@ import (
2121 "errors"
2222 "net/url"
2323 "os"
24- "path/filepath"
2524 "strings"
2625
2726 "github.com/arduino/go-paths-helper"
@@ -30,41 +29,42 @@ import (
3029 "github.com/sirupsen/logrus"
3130)
3231
33- var arduinoIDEDirectory * string
34-
3532// 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
3936 }
40- empty := ""
41- arduinoIDEDirectory = & empty
37+
38+ res := false
39+ config .IDEBundledCheckResult = & res
4240
4341 logrus .Info ("Checking if CLI is Bundled into the IDE" )
4442 executable , err := os .Executable ()
4543 if err != nil {
4644 logrus .WithError (err ).Warn ("Cannot get executable path" )
4745 return false
4846 }
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" )
5250 return false
5351 }
54- ideDir := filepath . Dir ( executable )
52+ ideDir := executablePath . Parent ( )
5553 logrus .Info ("Candidate IDE Directory: " , ideDir )
5654
57- tests := []string {"tools-builder" , "Examples/01.Basics/Blink" }
55+ tests := []string {
56+ "tools-builder" ,
57+ "examples/01.Basics/Blink" ,
58+ }
5859 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
6462 }
6563 }
6664
67- return * arduinoIDEDirectory != ""
65+ config .ArduinoIDEDirectory = ideDir
66+ res = true
67+ return true
6868}
6969
7070// LoadFromDesktopIDEPreferences loads the config from the Desktop IDE preferences.txt file
@@ -127,9 +127,9 @@ func proxyConfigsFromIDEPrefs(props properties.Map) error {
127127// IDEBundledLibrariesDir returns the libraries directory bundled in
128128// the Arduino IDE. If there is no Arduino IDE or the directory doesn't
129129// 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" )
133133 if libDir .IsDir () {
134134 return libDir
135135 }
0 commit comments