Skip to content

Commit d3df720

Browse files
authored
Merge pull request #79 from ianfixes/2019-01-11_small_fixes
Small fixes
2 parents 47b0733 + 4349c33 commit d3df720

7 files changed

+29
-33
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
66

77
## [Unreleased]
88
### Added
9-
109
- Provide an `itoa` function. It is present in Arduino's runtime environment but not on most (all?) host systems because itoa is not a portable standard function.
1110

1211
### Changed
12+
- Simplified the use of `Array.each` with a return statement; it's now simply `Array.find`
13+
- `autolocate!` for Arduino installations now raises `ArduinoInstallationError` if `force_install` fails
14+
- Errors due to missing YAML are now named `ConfigurationError`
1315

1416
### Deprecated
1517

1618
### Removed
1719

1820
### Fixed
21+
- Determining a working OSX launch command no longer breaks on non-English installations
1922

2023
### Security
2124

REFERENCE.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,8 @@ unittest(interrupt_attachment) {
405405
assertEqual(state->interrupt[7].mode, 3);
406406
detachInterrupt(7);
407407
assertFalse(state->interrupt[7].attached);
408-
}```
408+
}
409+
```
409410

410411

411412
### SPI

lib/arduino_ci/arduino_downloader.rb

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,7 @@ def self.autolocated_executable
3232
# if it exists. I'm not sure why we would have both, but if we did
3333
# a force install then let's make sure we actually use it.
3434
locations = [self.force_installed_executable, self.existing_executable]
35-
locations.each do |loc|
36-
next if loc.nil?
37-
next unless File.exist? loc
38-
39-
return loc
40-
end
41-
nil
35+
locations.find { |loc| !loc.nil? && File.exist?(loc) }
4236
end
4337

4438
# The autolocated directory of the installation
@@ -49,13 +43,7 @@ def self.autolocated_installation
4943
# if it exists. I'm not sure why we would have both, but if we did
5044
# a force install then let's make sure we actually use it.
5145
locations = [self.force_install_location, self.existing_installation]
52-
locations.each do |loc|
53-
next if loc.nil?
54-
next unless File.exist? loc
55-
56-
return loc
57-
end
58-
nil
46+
locations.find { |loc| !loc.nil? && File.exist?(loc) }
5947
end
6048

6149
# The path to the directory of an existing installation, or nil
@@ -198,7 +186,7 @@ def execute
198186
elsif File.exist? extracted_file
199187
install
200188
else
201-
puts "Arduino force-install failed"
189+
puts "Could not find extracted archive (tried #{extracted_file})"
202190
end
203191

204192
File.exist? self.class.force_install_location

lib/arduino_ci/arduino_downloader_osx.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,17 @@ def self.force_install_location
2727
# @param Array<string> a list of places to look
2828
# @return [string]
2929
def self.find_existing_arduino_dir(paths)
30-
paths.each do |path|
31-
return path if File.exist? path
32-
end
33-
nil
30+
paths.find(&File.method(:exist?))
3431
end
3532

3633
# An existing Arduino file in one of the given directories, or nil
3734
# @param Array<string> a list of places to look for the executable
3835
# @return [string]
3936
def self.find_existing_arduino_exe(paths)
40-
paths.each do |path|
37+
paths.find do |path|
4138
exe = File.join(path, "MacOS", "Arduino")
42-
return exe if File.exist? exe
39+
File.exist? exe
4340
end
44-
nil
4541
end
4642

4743
# The path to the directory of an existing installation, or nil

lib/arduino_ci/arduino_downloader_windows.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ def self.existing_installation
8181
# @return [string]
8282
def self.existing_executable
8383
arduino_reg = 'SOFTWARE\WOW6432Node\Arduino'
84-
Win32::Registry::HKEY_LOCAL_MACHINE.open(arduino_reg) do |reg|
84+
Win32::Registry::HKEY_LOCAL_MACHINE.open(arduino_reg).find do |reg|
8585
path = reg.read_s('Install_Dir')
8686
exe = File.join(path, "arduino_debug.exe")
87-
return exe if File.exist? exe
87+
File.exist? exe
8888
end
8989
rescue
9090
nil
@@ -93,10 +93,7 @@ def self.existing_executable
9393
# The executable Arduino file in a forced installation, or nil
9494
# @return [string]
9595
def self.force_installed_executable
96-
exe = File.join(self.force_install_location, "arduino_debug.exe")
97-
return nil if exe.nil?
98-
99-
exe
96+
File.join(self.force_install_location, "arduino_debug.exe")
10097
end
10198

10299
end

lib/arduino_ci/arduino_installation.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
module ArduinoCI
1515

16+
class ArduinoInstallationError < StandardError; end
17+
1618
# Manage the OS-specific install location of Arduino
1719
class ArduinoInstallation
1820

@@ -78,7 +80,13 @@ def autolocate_osx
7880
# don't want to see is a java error.
7981
args = launcher + ["--bogus-option"]
8082
result = Host.run_and_capture(*args)
81-
next unless result[:err].include? "Error: unknown option: --bogus-option"
83+
84+
# NOTE: Was originally searching for "Error: unknown option: --bogus-option"
85+
# but also need to find "Erreur: option inconnue : --bogus-option"
86+
# and who knows how many other languages.
87+
# For now, just search for the end of the error and hope that the java-style
88+
# launch of this won't include a similar string in it
89+
next unless result[:err].include? ": --bogus-option"
8290

8391
ret.base_cmd = launcher
8492
ret.binary_path = Pathname.new(osx_root)
@@ -94,7 +102,8 @@ def autolocate!
94102
return candidate unless candidate.nil?
95103

96104
# force the install
97-
force_install
105+
raise ArduinoInstallationError, "Failed to force-install Arduino" unless force_install
106+
98107
autolocate
99108
end
100109

lib/arduino_ci/ci_config.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
}.freeze
3636
module ArduinoCI
3737

38+
class ConfigurationError < StandardError; end
39+
3840
# The filename controlling (overriding) the defaults for testing.
3941
# Files with this name can be used in the root directory of the Arduino library and in any/all of the example directories
4042
CONFIG_FILENAMES = [
@@ -108,7 +110,7 @@ def validate_data(rootname, source, schema)
108110
# @return [ArduinoCI::CIConfig] a reference to self
109111
def load_yaml(path)
110112
yml = YAML.load_file(path)
111-
raise "The YAML file at #{path} failed to load" unless yml
113+
raise ConfigurationError, "The YAML file at #{path} failed to load" unless yml
112114

113115
if yml.include?("packages")
114116
yml["packages"].each do |k, v|

0 commit comments

Comments
 (0)