1
1
require 'fileutils'
2
2
require 'pathname'
3
3
4
+ # workaround for https://github.com/arduino/Arduino/issues/3535
5
+ WORKAROUND_LIB = "USBHost" . freeze
6
+
4
7
module ArduinoCI
5
8
6
9
# Wrap the Arduino executable. This requires, in some cases, a faked display.
@@ -27,7 +30,7 @@ def self.flag(name, text = nil)
27
30
attr_accessor :binary_path
28
31
29
32
# part of a workaround for https://github.com/arduino/Arduino/issues/3535
30
- attr_reader :library_is_indexed
33
+ attr_reader :libraries_indexed
31
34
32
35
# @return [String] STDOUT of the most recently-run command
33
36
attr_reader :last_out
@@ -51,7 +54,7 @@ def self.flag(name, text = nil)
51
54
def initialize
52
55
@prefs_cache = { }
53
56
@prefs_fetched = false
54
- @library_is_indexed = false
57
+ @libraries_indexed = false
55
58
@last_out = ""
56
59
@last_err = ""
57
60
@last_msg = ""
@@ -186,21 +189,29 @@ def install_boards(boardfamily)
186
189
# install a library by name
187
190
# @param name [String] the library name
188
191
# @return [bool] whether the command succeeded
189
- def install_library ( library_name )
190
- # workaround for https://github.com/arduino/Arduino/issues/3535
191
- # use a dummy library name but keep open the possiblity that said library
192
- # might be selected by choice for installation
193
- workaround_lib = "USBHost"
194
- unless @library_is_indexed || workaround_lib == library_name
195
- @library_is_indexed = run_and_capture ( flag_install_library , workaround_lib )
196
- end
192
+ def _install_library ( library_name )
193
+ success = run_and_capture ( flag_install_library , library_name ) [ :success ]
194
+
195
+ @libraries_indexed = ( @libraries_indexed || success ) if library_name == WORKAROUND_LIB
196
+ success
197
+ end
197
198
198
- # actual installation
199
- result = run_and_capture ( flag_install_library , library_name )
199
+ # index the set of libraries by installing a dummy library
200
+ # related to WORKAROUND_LIB and https://github.com/arduino/Arduino/issues/3535
201
+ # TODO: unclear if this is still necessary
202
+ def index_libraries
203
+ return true if @libraries_indexed
200
204
201
- # update flag if necessary
202
- @library_is_indexed = ( @library_is_indexed || result [ :success ] ) if library_name == workaround_lib
203
- result [ :success ]
205
+ _install_library ( WORKAROUND_LIB )
206
+ @libraries_indexed
207
+ end
208
+
209
+ # install a library by name
210
+ # @param name [String] the library name
211
+ # @return [bool] whether the command succeeded
212
+ def install_library ( library_name )
213
+ index_libraries
214
+ _install_library ( library_name )
204
215
end
205
216
206
217
# generate the (very likely) path of a library given its name
0 commit comments