Skip to content

Commit

Permalink
Rename ArduinoCmd to ArduinoBackend
Browse files Browse the repository at this point in the history
  • Loading branch information
ianfixes committed Nov 25, 2020
1 parent 3ef72f2 commit 734ae68
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 47 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Changed
- Arduino backend is now `arduino-cli` version `0.13.0`
- `ArduinoCmd` is now `ArduinoBackend`

### Deprecated
- `arduino_ci_remote.rb` CLI switch `--skip-compilation`
Expand Down
34 changes: 17 additions & 17 deletions exe/arduino_ci.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ def self.parse(options)
def terminate(final = nil)
puts "Failures: #{@failure_count}"
unless @failure_count.zero? || final
puts "Last message: #{@arduino_cmd.last_msg}"
puts "Last message: #{@arduino_backend.last_msg}"
puts "========== Stdout:"
puts @arduino_cmd.last_out
puts @arduino_backend.last_out
puts "========== Stderr:"
puts @arduino_cmd.last_err
puts @arduino_backend.last_err
end
retcode = @failure_count.zero? ? 0 : 1
exit(retcode)
Expand Down Expand Up @@ -174,10 +174,10 @@ def display_files(pathname)

def install_arduino_library_dependencies(aux_libraries)
aux_libraries.each do |l|
if @arduino_cmd.library_present?(l)
if @arduino_backend.library_present?(l)
inform("Using pre-existing library") { l.to_s }
else
assure("Installing aux library '#{l}'") { @arduino_cmd.install_library(l) }
assure("Installing aux library '#{l}'") { @arduino_backend.install_library(l) }
end
end
end
Expand All @@ -189,7 +189,7 @@ def perform_unit_tests(file_config)
end
config = file_config.with_override_config(@cli_options[:ci_config])
cpp_library = ArduinoCI::CppLibrary.new(Pathname.new("."),
@arduino_cmd.lib_dir,
@arduino_backend.lib_dir,
config.exclude_dirs.map(&Pathname.method(:new)))

# check GCC
Expand Down Expand Up @@ -264,18 +264,18 @@ def perform_compilation_tests(config)

# initialize library under test
installed_library_path = attempt("Installing library under test") do
@arduino_cmd.install_local_library(Pathname.new("."))
@arduino_backend.install_local_library(Pathname.new("."))
end

if !installed_library_path.nil? && installed_library_path.exist?
inform("Library installed at") { installed_library_path.to_s }
else
assure_multiline("Library installed successfully") do
if installed_library_path.nil?
puts @arduino_cmd.last_msg
puts @arduino_backend.last_msg
else
# print out the contents of the deepest directory we actually find
@arduino_cmd.lib_dir.ascend do |path_part|
@arduino_backend.lib_dir.ascend do |path_part|
next unless path_part.exist?

break display_files(path_part)
Expand All @@ -284,7 +284,7 @@ def perform_compilation_tests(config)
end
end
end
library_examples = @arduino_cmd.library_examples(installed_library_path)
library_examples = @arduino_backend.library_examples(installed_library_path)

# gather up all required boards for compilation so we can install them up front.
# start with the "platforms to unittest" and add the examples
Expand Down Expand Up @@ -330,13 +330,13 @@ def perform_compilation_tests(config)

unless all_urls.empty?
assure("Setting board manager URLs") do
@arduino_cmd.board_manager_urls = all_urls
@arduino_backend.board_manager_urls = all_urls
end
end

all_packages.each do |p|
assure("Installing board package #{p}") do
@arduino_cmd.install_boards(p)
@arduino_backend.install_boards(p)
end
end

Expand Down Expand Up @@ -367,11 +367,11 @@ def perform_compilation_tests(config)
example_paths.each do |example_path|
example_name = File.basename(example_path)
attempt("Compiling #{example_name} for #{board}") do
ret = @arduino_cmd.compile_sketch(example_path, board)
ret = @arduino_backend.compile_sketch(example_path, board)
unless ret
puts
puts "Last command: #{@arduino_cmd.last_msg}"
puts @arduino_cmd.last_err
puts "Last command: #{@arduino_backend.last_msg}"
puts @arduino_backend.last_err
end
ret
end
Expand All @@ -383,8 +383,8 @@ def perform_compilation_tests(config)
# initialize command and config
config = ArduinoCI::CIConfig.default.from_project_library

@arduino_cmd = ArduinoCI::ArduinoInstallation.autolocate!
inform("Located arduino-cli binary") { @arduino_cmd.binary_path.to_s }
@arduino_backend = ArduinoCI::ArduinoInstallation.autolocate!
inform("Located arduino-cli binary") { @arduino_backend.binary_path.to_s }

perform_unit_tests(config)
perform_compilation_tests(config)
Expand Down
4 changes: 2 additions & 2 deletions exe/arduino_library_location.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
require 'arduino_ci'

# locate and/or forcibly install Arduino, keep stdout clean
@arduino_cmd = ArduinoCI::ArduinoInstallation.autolocate!($stderr)
@arduino_backend = ArduinoCI::ArduinoInstallation.autolocate!($stderr)

puts @arduino_cmd.lib_dir
puts @arduino_backend.lib_dir
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module ArduinoCI
class ArduinoExecutionError < StandardError; end

# Wrap the Arduino executable. This requires, in some cases, a faked display.
class ArduinoCmd
class ArduinoBackend

# Enable a shortcut syntax for command line flags
# @param name [String] What the flag will be called (prefixed with 'flag_')
Expand Down
8 changes: 4 additions & 4 deletions lib/arduino_ci/arduino_installation.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'pathname'
require "arduino_ci/host"
require "arduino_ci/arduino_cmd"
require "arduino_ci/arduino_backend"
require "arduino_ci/arduino_downloader_osx"
require "arduino_ci/arduino_downloader_linux"
require "arduino_ci/arduino_downloader_windows" if ArduinoCI::Host.os == :windows
Expand All @@ -19,7 +19,7 @@ class << self
# attempt to find a workable Arduino executable across platforms
#
# Autolocation assumed to be an expensive operation
# @return [ArduinoCI::ArduinoCmd] an instance of the command or nil if it can't be found
# @return [ArduinoCI::ArduinoBackend] an instance of the command or nil if it can't be found
def autolocate
downloader_class = case Host.os
when :osx then ArduinoDownloaderOSX
Expand All @@ -30,11 +30,11 @@ def autolocate
loc = downloader_class.autolocated_executable
return nil if loc.nil?

ArduinoCmd.new(loc)
ArduinoBackend.new(loc)
end

# Attempt to find a workable Arduino executable across platforms, and install it if we don't
# @return [ArduinoCI::ArduinoCmd] an instance of a command
# @return [ArduinoCI::ArduinoBackend] an instance of a command
def autolocate!(output = $stdout)
candidate = autolocate
return candidate unless candidate.nil?
Expand Down
38 changes: 19 additions & 19 deletions spec/arduino_cmd_spec.rb → spec/arduino_backend_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,67 +6,67 @@ def get_sketch(dir, file)
end


RSpec.describe ArduinoCI::ArduinoCmd do
RSpec.describe ArduinoCI::ArduinoBackend do
next if skip_ruby_tests

arduino_cmd = ArduinoCI::ArduinoInstallation.autolocate!
arduino_backend = ArduinoCI::ArduinoInstallation.autolocate!

after(:each) do |example|
if example.exception
puts "Last message: #{arduino_cmd.last_msg}"
puts "Last message: #{arduino_backend.last_msg}"
puts "========== Stdout:"
puts arduino_cmd.last_out
puts arduino_backend.last_out
puts "========== Stderr:"
puts arduino_cmd.last_err
puts arduino_backend.last_err
end
end

context "initialize" do
it "sets base vars" do
expect(arduino_cmd.binary_path).not_to be nil
expect(arduino_backend.binary_path).not_to be nil
end
end

context "board_installed?" do
it "Finds installed boards" do
uno_installed = arduino_cmd.board_installed? "arduino:avr:uno"
uno_installed = arduino_backend.board_installed? "arduino:avr:uno"
expect(uno_installed).to be true
expect(uno_installed).not_to be nil
end

it "Doesn't find bogus boards" do
bogus_installed = arduino_cmd.board_installed? "eggs:milk:wheat"
bogus_installed = arduino_backend.board_installed? "eggs:milk:wheat"
expect(bogus_installed).to be false
expect(bogus_installed).not_to be nil
end
end

context "installation of boards" do
it "installs and sets boards" do
expect(arduino_cmd.install_boards("arduino:sam")).to be true
expect(arduino_backend.install_boards("arduino:sam")).to be true
end
end

context "libraries" do
it "knows where to find libraries" do
fake_lib = "_____nope"
expected_dir = Pathname.new(arduino_cmd.lib_dir) + fake_lib
expect(arduino_cmd.library_path(fake_lib)).to eq(expected_dir)
expect(arduino_cmd.library_present?(fake_lib)).to be false
expected_dir = Pathname.new(arduino_backend.lib_dir) + fake_lib
expect(arduino_backend.library_path(fake_lib)).to eq(expected_dir)
expect(arduino_backend.library_present?(fake_lib)).to be false
end
end

context "board_manager" do
it "Reads and writes board_manager URLs" do
fake_urls = ["http://foo.bar", "http://arduino.ci"]
existing_urls = arduino_cmd.board_manager_urls
existing_urls = arduino_backend.board_manager_urls

# try to ensure maxiumum variability in the test
test_url_sets = (existing_urls.empty? ? [fake_urls, []] : [[], fake_urls]) + [existing_urls]

test_url_sets.each do |urls|
arduino_cmd.board_manager_urls = urls
expect(arduino_cmd.board_manager_urls).to match_array(urls)
arduino_backend.board_manager_urls = urls
expect(arduino_backend.board_manager_urls).to match_array(urls)
end
end
end
Expand All @@ -80,19 +80,19 @@ def get_sketch(dir, file)
sketch_path_bad = get_sketch("BadSketch", "BadSketch.ino")

it "Rejects a PDE sketch at #{sketch_path_pde}" do
expect(arduino_cmd.compile_sketch(sketch_path_pde, "arduino:avr:uno")).to be false
expect(arduino_backend.compile_sketch(sketch_path_pde, "arduino:avr:uno")).to be false
end

it "Fails a missing sketch at #{sketch_path_mia}" do
expect(arduino_cmd.compile_sketch(sketch_path_mia, "arduino:avr:uno")).to be false
expect(arduino_backend.compile_sketch(sketch_path_mia, "arduino:avr:uno")).to be false
end

it "Fails a bad sketch at #{sketch_path_bad}" do
expect(arduino_cmd.compile_sketch(sketch_path_bad, "arduino:avr:uno")).to be false
expect(arduino_backend.compile_sketch(sketch_path_bad, "arduino:avr:uno")).to be false
end

it "Passes a simple INO sketch at #{sketch_path_ino}" do
expect(arduino_cmd.compile_sketch(sketch_path_ino, "arduino:avr:uno")).to be true
expect(arduino_backend.compile_sketch(sketch_path_ino, "arduino:avr:uno")).to be true
end
end
end
8 changes: 4 additions & 4 deletions spec/arduino_installation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
end

context "autolocate!" do
arduino_cmd = ArduinoCI::ArduinoInstallation.autolocate!
arduino_backend = ArduinoCI::ArduinoInstallation.autolocate!
it "doesn't fail" do
expect(arduino_cmd.binary_path).not_to be nil
expect(arduino_cmd.lib_dir).not_to be nil
expect(arduino_backend.binary_path).not_to be nil
expect(arduino_backend.lib_dir).not_to be nil
end
end

Expand All @@ -23,7 +23,7 @@
output.rewind
expect(output.read.empty?).to be true
# install a bogus version to save time downloading
arduino_cmd = ArduinoCI::ArduinoInstallation.force_install(output, "BOGUS VERSION")
arduino_backend = ArduinoCI::ArduinoInstallation.force_install(output, "BOGUS VERSION")
output.rewind
expect(output.read.empty?).to be false
end
Expand Down

0 comments on commit 734ae68

Please sign in to comment.