Skip to content

Commit fd512f1

Browse files
committed
expose library-indexing operation
1 parent c53d30e commit fd512f1

File tree

3 files changed

+30
-15
lines changed

3 files changed

+30
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
99
- Arduino command wrapper now natively supports board manager URLs
1010
- `arduino_ci_remote.rb` checks for proper board manager URLs for requested platforms
1111
- `arduino_ci_remote.rb` reports on Arduino executable location
12+
- exposed `index_libraries` in `ArduinoCmd` so it can be used as an explicit build step
1213

1314
### Changed
1415
- Centralized file listing code in `arduino_ci_remote.rb`

exe/arduino_ci_remote.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ def display_files(pathname)
109109
@arduino_cmd = ArduinoCI::ArduinoInstallation.autolocate!
110110
inform("Located Arduino binary") { @arduino_cmd.binary_path.to_s }
111111

112+
# index the existing libraries
113+
attempt("Indexing libraries") { @arduino_cmd.index_libraries } unless @arduino_cmd.libraries_indexed
114+
112115
# initialize library under test
113116
installed_library_path = attempt("Installing library under test") do
114117
@arduino_cmd.install_local_library(Pathname.new("."))

lib/arduino_ci/arduino_cmd.rb

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
require 'fileutils'
22
require 'pathname'
33

4+
# workaround for https://github.com/arduino/Arduino/issues/3535
5+
WORKAROUND_LIB = "USBHost".freeze
6+
47
module ArduinoCI
58

69
# Wrap the Arduino executable. This requires, in some cases, a faked display.
@@ -27,7 +30,7 @@ def self.flag(name, text = nil)
2730
attr_accessor :binary_path
2831

2932
# part of a workaround for https://github.com/arduino/Arduino/issues/3535
30-
attr_reader :library_is_indexed
33+
attr_reader :libraries_indexed
3134

3235
# @return [String] STDOUT of the most recently-run command
3336
attr_reader :last_out
@@ -51,7 +54,7 @@ def self.flag(name, text = nil)
5154
def initialize
5255
@prefs_cache = {}
5356
@prefs_fetched = false
54-
@library_is_indexed = false
57+
@libraries_indexed = false
5558
@last_out = ""
5659
@last_err = ""
5760
@last_msg = ""
@@ -186,21 +189,29 @@ def install_boards(boardfamily)
186189
# install a library by name
187190
# @param name [String] the library name
188191
# @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
197198

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
200204

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)
204215
end
205216

206217
# generate the (very likely) path of a library given its name

0 commit comments

Comments
 (0)