@@ -6,53 +6,96 @@ module ArduinoCI
6
6
7
7
# Manage the OS-specific install location of Arduino
8
8
class ArduinoInstallation
9
- attr_accessor :cmd_path
9
+ attr_accessor :base_cmd
10
10
attr_accessor :lib_dir
11
+ attr_accessor :requires_x
11
12
12
13
class << self
13
14
def force_install_location
14
15
File . join ( ENV [ 'HOME' ] , 'arduino_ci_ide' )
15
16
end
16
17
18
+ def from_forced_install
19
+ ret = new
20
+ builder = File . join ( force_install_location , "arduino-builder" )
21
+ if File . exist? builder
22
+ ret . base_cmd = [ builder ]
23
+ ret . requires_x = false
24
+ else
25
+ ret . base_cmd = [ File . join ( force_install_location , "arduino" ) ]
26
+ ret . requires_x = true
27
+ end
28
+ ret . lib_dir = File . join ( force_install_location , "libraries" )
29
+ # TODO: "libraries" is what's in the adafruit install.sh script
30
+ ret
31
+ end
32
+
17
33
# attempt to find a workable Arduino executable across platforms
18
34
def autolocate
19
- ret = new
35
+ osx_root = "/Applications/Arduino.app"
36
+ old_way = false
37
+ if File . exist? osx_root
38
+ ret = new
39
+ osx_place = "#{ osx_root } /Contents/MacOS"
20
40
21
- osx_place = "/Applications/Arduino.app/Contents/MacOS"
22
- if File . exist? osx_place
23
- ret . cmd_path = File . join ( osx_place , "Arduino" )
41
+ if old_way
42
+ ret . base_cmd = [ File . join ( osx_place , "Arduino" ) ]
43
+ else
44
+ jvm_runtime = `/usr/libexec/java_home`
45
+ ret . base_cmd = [
46
+ "java" ,
47
+ "-cp" , "#{ osx_root } /Contents/Java/*" ,
48
+ "-DAPP_DIR=#{ osx_root } /Contents/Java" ,
49
+ "-Djava.ext.dirs=$JVM_RUNTIME/Contents/Home/lib/ext/:#{ jvm_runtime } /Contents/Home/jre/lib/ext/" ,
50
+ "-Dfile.encoding=UTF-8" ,
51
+ "-Dapple.awt.UIElement=true" ,
52
+ "-Xms128M" ,
53
+ "-Xmx512M" ,
54
+ "processing.app.Base" ,
55
+ ]
56
+ end
24
57
ret . lib_dir = File . join ( osx_place , "Libraries" )
58
+ ret . requires_x = false
25
59
return ret
26
60
end
27
61
62
+ # # AAARRRRGGGGHHH
63
+ # # Even though arduino-builder is an awesome CLI for Arduino,
64
+ # # ALL THE OPTIONS ARE DIFFERENT (single vs double dash for flags)
65
+ # # USELESS FOR THE TIME BEING
66
+ #
67
+ # posix_place = Host.which("arduino-builder")
68
+ # unless posix_place.nil?
69
+ # ret = new
70
+ # ret.base_cmd = [posix_place]
71
+ # ret.lib_dir = File.join(ENV['HOME'], "Sketchbook") # assume linux
72
+ # ret.requires_x = false
73
+ # # https://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use/how-to-install-a-library
74
+ # return ret
75
+ # end
76
+
28
77
posix_place = Host . which ( "arduino" )
29
78
unless posix_place . nil?
30
- ret . cmd_path = posix_place
79
+ ret = new
80
+ ret . base_cmd = [ posix_place ]
31
81
ret . lib_dir = File . join ( ENV [ 'HOME' ] , "Sketchbook" ) # assume linux
82
+ ret . requires_x = true
32
83
# https://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use/how-to-install-a-library
33
84
return ret
34
85
end
35
86
36
- if File . exist? force_install_location
37
- ret . cmd_path = File . join ( force_install_location , "arduino" )
38
- ret . lib_dir = File . join ( force_install_location , "libraries" )
39
- # TODO: "libraries" is what's in the adafruit install.sh script
40
- return ret
41
- end
87
+ return from_forced_install if File . exist? force_install_location
42
88
43
- ret
89
+ new
44
90
end
45
91
46
92
# Attempt to find a workable Arduino executable across platforms, and install it if we don't
47
93
def autolocate!
48
94
candidate = autolocate
49
- return candidate unless candidate . cmd_path . nil?
50
- # force the install
95
+ return candidate unless candidate . base_cmd . nil?
51
96
52
- if force_install
53
- candidate . cmd_path = File . join ( force_install_location , "arduino" )
54
- candidate . lib_dir = File . join ( force_install_location , "libraries" )
55
- end
97
+ # force the install
98
+ candidate = from_forced_install if force_install
56
99
candidate
57
100
end
58
101
0 commit comments