Skip to content

Commit 32de3b4

Browse files
authored
Merge pull request #3 from ifreecarve/2018-01-10_ci
Fix CI redux
2 parents a0a95f2 + 64b0886 commit 32de3b4

15 files changed

+603
-155
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
/pkg/
88
/spec/reports/
99
vendor
10+
*.gem
1011

1112
# rspec failure tracking
1213
.rspec_status

.travis.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
sudo: false
22
language: ruby
33

4-
rvm:
4+
# rvm:
55
# - "2.0.0"
66
# - "2.1.0"
77
# - "2.2.0"
88
# - rbx
9-
- "2.5.0"
9+
# - "2.5.0"
1010

1111
before_install: gem install bundler -v 1.15.4
1212
script:
1313
- bundle exec rubocop --version
1414
- bundle exec rubocop -D .
1515
- bundle exec rspec
16+
- bundle exec ci_system_check.rb

CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,25 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
66

77
## [Unreleased]
88
### Added
9+
- `ArduinoInstallation` class for managing lib / executable paths
10+
- `DisplayManager` class for managing Xvfb instance if needed
11+
- `ArduinoCmd` captures and caches preferences
12+
- `ArduinoCmd` reports on whether a board is installed
13+
- `ArduinoCmd` sets preferences
14+
- `ArduinoCmd` installs boards
15+
- `ArduinoCmd` installs libraries
16+
- `ArduinoCmd` selects boards (compiler preference)
917

1018
### Changed
19+
- `DisplayManger.with_display` doesn't `disable` if the display was enabled prior to starting the block
1120

1221
### Deprecated
1322

1423
### Removed
1524

1625
### Fixed
26+
- Built gems are `.gitignore`d
27+
- Updated gems based on Github's security advisories
1728

1829
### Security
1930

arduino_ci.gemspec

+7-4
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,17 @@ Gem::Specification.new do |spec|
1414
spec.description = spec.description
1515
spec.homepage = "http://github.com/ifreecarve/arduino_ci"
1616

17-
spec.files = ['README.md', '.yardopts'] + Dir['lib/**/*.*'].reject { |f| f.match(%r{^(test|spec|features)/}) }
18-
1917
spec.bindir = "exe"
18+
rejection_regex = %r{^(test|spec|features)/}
19+
libfiles = Dir['lib/**/*.*'].reject { |f| f.match(rejection_regex) }
20+
binfiles = Dir[File.join(spec.bindir, '/**/*.*')].reject { |f| f.match(rejection_regex) }
21+
spec.files = ['README.md', '.yardopts'] + libfiles + binfiles
22+
2023
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
2124
spec.require_paths = ["lib"]
2225

2326
spec.add_development_dependency "bundler", "~> 1.15"
2427
spec.add_development_dependency "rspec", "~> 3.0"
25-
spec.add_development_dependency 'rubocop', '~> 0', '>= 0.46.0'
26-
spec.add_development_dependency 'yard', '~>0.8', '>= 0.8'
28+
spec.add_development_dependency 'rubocop', '~>0.49.0'
29+
spec.add_development_dependency 'yard', '~>0.9.11'
2730
end

exe/ci_system_check.rb

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
require 'arduino_ci'
2+
3+
puts "Enabling display with display manager"
4+
ArduinoCI::DisplayManager::instance.enable
5+
6+
puts "Autlocating Arduino command"
7+
arduino_cmd = ArduinoCI::ArduinoCmd.autolocate!
8+
9+
board_tests = {
10+
"arduino:avr:uno" => true,
11+
"eggs:milk:wheat" => false,
12+
}
13+
14+
got_problem = false
15+
board_tests.each do |k, v|
16+
puts "I expect arduino_cmd.board_installed?(#{k}) to be #{v}"
17+
result = arduino_cmd.board_installed?(k)
18+
puts " board_installed?(#{k}) returns #{result}. expected #{v}"
19+
got_problem = true if v != result
20+
end
21+
22+
urls = [
23+
"https://adafruit.github.io/arduino-board-index/package_adafruit_index.json",
24+
"http://arduino.esp8266.com/stable/package_esp8266com_index.json"
25+
]
26+
27+
puts "Setting additional URLs"
28+
got_problem = true unless arduino_cmd.set_pref("boardsmanager.additional.urls", urls.join(","))
29+
30+
puts "Installing arduino:sam"
31+
got_problem = true unless arduino_cmd.install_board("arduino:sam")
32+
puts "Installing USBHost"
33+
got_problem = true unless arduino_cmd.install_library("USBHost")
34+
puts "checking that library is indexed"
35+
got_problem = true unless arduino_cmd.library_is_indexed
36+
puts "setting compiler warning level"
37+
got_problem = true unless arduino_cmd.set_pref("compiler.warning_level", "all")
38+
puts "use board! (install board)"
39+
got_problem = true unless arduino_cmd.use_board!("arduino:samd:zero")
40+
puts "verify that board has been installed"
41+
got_problem = true unless arduino_cmd.board_installed?("arduino:samd:zero")
42+
43+
abort if got_problem
44+
exit(0)

lib/arduino_ci.rb

+1-117
Original file line numberDiff line numberDiff line change
@@ -1,124 +1,8 @@
11
require "arduino_ci/version"
2-
3-
require 'singleton'
4-
5-
# Cross-platform way of finding an executable in the $PATH.
6-
# via https://stackoverflow.com/a/5471032/2063546
7-
# which('ruby') #=> /usr/bin/ruby
8-
def which(cmd)
9-
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
10-
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
11-
exts.each do |ext|
12-
exe = File.join(path, "#{cmd}#{ext}")
13-
return exe if File.executable?(exe) && !File.directory?(exe)
14-
end
15-
end
16-
nil
17-
end
2+
require "arduino_ci/arduino_cmd"
183

194
# ArduinoCI contains classes for automated testing of Arduino code on the command line
205
# @author Ian Katz <[email protected]>
216
module ArduinoCI
227

23-
# Wrap the Arduino executable. This requires, in some cases, a faked display.
24-
class ArduinoCmd
25-
26-
# create as many ArduinoCmds as you like, but we need one and only one display manager
27-
class DisplayMgr
28-
include Singleton
29-
attr_reader :enabled
30-
31-
def initialize
32-
@existing = existing_display?
33-
@enabled = false
34-
@pid = nil
35-
end
36-
37-
# attempt to determine if the machine is running a graphical display (i.e. not Travis)
38-
def existing_display?
39-
return true if RUBY_PLATFORM.include? "darwin"
40-
return true if ENV["DISPLAY"].nil?
41-
return true if ENV["DISPLAY"].include? ":"
42-
false
43-
end
44-
45-
# enable a virtual display
46-
def enable
47-
return @enabled = true if @existing # silent no-op if built in display
48-
return unless @pid.nil?
49-
50-
@enabled = true
51-
@pid = fork do
52-
puts "Forking Xvfb"
53-
system("Xvfb", ":1", "-ac", "-screen", "0", "1280x1024x16")
54-
puts "Xvfb unexpectedly quit!"
55-
end
56-
sleep(3) # TODO: test a connection to the X server?
57-
end
58-
59-
# disable the virtual display
60-
def disable
61-
return @enabled = false if @existing # silent no-op if built in display
62-
return if @pid.nil?
63-
64-
begin
65-
Process.kill 9, @pid
66-
ensure
67-
Process.wait @pid
68-
@pid = nil
69-
end
70-
puts "Xvfb killed"
71-
end
72-
73-
# Enable a virtual display for the duration of the given block
74-
def with_display
75-
enable
76-
begin
77-
yield environment
78-
ensure
79-
disable
80-
end
81-
end
82-
83-
def environment
84-
return nil unless @existing || @enabled
85-
return {} if @existing
86-
{ DISPLAY => ":1.0" }
87-
end
88-
89-
# On finalize, ensure child process is ended
90-
def self.finalize
91-
disable
92-
end
93-
end
94-
95-
class << self
96-
protected :new
97-
98-
# attempt to find a workable Arduino executable across platforms
99-
def guess_executable_location
100-
osx_place = "/Applications/Arduino.app/Contents/MacOS/Arduino"
101-
places = {
102-
"arduino" => !which("arduino").nil?,
103-
osx_place => (File.exist? osx_place),
104-
}
105-
places.each { |k, v| return k if v }
106-
nil
107-
end
108-
109-
def autolocate
110-
ret = new
111-
ret.path = guess_executable_location
112-
ret
113-
end
114-
end
115-
116-
attr_accessor :path
117-
118-
def initialize
119-
@display_mgr = DisplayMgr::instance
120-
end
121-
122-
end
123-
1248
end

0 commit comments

Comments
 (0)