Skip to content

Commit 6eaa473

Browse files
committed
try to test an actual library
1 parent f39b490 commit 6eaa473

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

exe/ci_system_check.rb

+11
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,16 @@
4949
puts "verify a simple sketch"
5050
got_problem = true unless arduino_cmd.verify_sketch(simple_sketch)
5151

52+
puts "verify the examples of a library..."
53+
puts " - Install the library"
54+
library_path = File.join(File.dirname(__FILE__), "SampleProjects", "DoSomething")
55+
installed_library_path = arduino_cmd.install_local_library(library_path)
56+
got_problem = true if installed_library_path.nil?
57+
puts " - Iterate over the examples"
58+
arduino_cmd.each_library_example(installed_library_path) do |example_path|
59+
puts "Iterating #{example_path}"
60+
got_problem_ true unless arduino_cmd.verify_sketch(example_path)
61+
end
62+
5263
abort if got_problem
5364
exit(0)

lib/arduino_ci/arduino_cmd.rb

+45
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require 'fileutils'
12
require 'arduino_ci/display_manager'
23
require 'arduino_ci/arduino_installation'
34

@@ -159,6 +160,12 @@ def install_library(library_name)
159160
result[:success]
160161
end
161162

163+
# generate the (very likely) path of a library given its name
164+
def library_path(library_name)
165+
sketchbook = get_pref("sketchbook.path")
166+
File.join(sketchbook, library_name)
167+
end
168+
162169
# update the library index
163170
def update_library_index
164171
# install random lib so the arduino IDE grabs a new library index
@@ -193,5 +200,43 @@ def verify_sketch(path)
193200
run("--verify", path, err: :out)
194201
end
195202

203+
# ensure that the given library is installed, or symlinked as appropriate
204+
# return the path of the prepared library, or nil
205+
def install_local_library(library_path)
206+
sketchbook = get_pref("sketchbook.path")
207+
library_name = File.basename(library_path)
208+
destination_path = File.join(sketchbook, library_name)
209+
210+
# things get weird if the sketchbook contains the library.
211+
# check that first
212+
if File.exist? destination_path
213+
uhoh = "There is already a library '#{library_name}' in the sketchbook"
214+
return destination_path if destination_path == library_path
215+
216+
# maybe it's a symlink? that would be OK
217+
if File.symlink?(destination_path)
218+
return destination_path if File.readlink(destination_path) == library_path
219+
puts "#{uhoh} and it's not symlinked to #{library_path}"
220+
return nil
221+
end
222+
223+
puts "#{uhoh}. It may need to be removed manually."
224+
return nil
225+
end
226+
227+
# install the library
228+
FileUtils.ln_s(library_path, destination_path)
229+
destination_path
230+
end
231+
232+
def each_library_example(installed_library_path)
233+
example_path = File.join(installed_library_path, "examples")
234+
examples = Pathname.new(example_path).children.select(&:directory?).map(&:to_path).reject { |n| n[0] == '.' }
235+
examples.each do |e|
236+
proj_file = File.join(example_path, e, "#{e}.ino")
237+
puts "Considering #{proj_file}"
238+
yield e if File.exist?(proj_file)
239+
end
240+
end
196241
end
197242
end

0 commit comments

Comments
 (0)