Skip to content

Commit fdd2c65

Browse files
committed
try to test an actual library
1 parent b48a96d commit fdd2c65

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
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+
library_path = File.join(File.dirname(File.dirname(__FILE__)), "SampleProjects", "DoSomething")
53+
puts "verify the examples of a library (#{library_path})..."
54+
puts " - Install the library"
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

+44
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,42 @@ 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+
library_name = File.basename(library_path)
207+
destination_path = File.join(@installation.lib_dir, library_name)
208+
209+
# things get weird if the sketchbook contains the library.
210+
# check that first
211+
if File.exist? destination_path
212+
uhoh = "There is already a library '#{library_name}' in the library directory"
213+
return destination_path if destination_path == library_path
214+
215+
# maybe it's a symlink? that would be OK
216+
if File.symlink?(destination_path)
217+
return destination_path if File.readlink(destination_path) == library_path
218+
puts "#{uhoh} and it's not symlinked to #{library_path}"
219+
return nil
220+
end
221+
222+
puts "#{uhoh}. It may need to be removed manually."
223+
return nil
224+
end
225+
226+
# install the library
227+
FileUtils.ln_s(library_path, destination_path)
228+
destination_path
229+
end
230+
231+
def each_library_example(installed_library_path)
232+
example_path = File.join(installed_library_path, "examples")
233+
examples = Pathname.new(example_path).children.select(&:directory?).map(&:to_path).map(&File.method(:basename))
234+
examples.each do |e|
235+
proj_file = File.join(example_path, e, "#{e}.ino")
236+
puts "Considering #{proj_file}"
237+
yield proj_file if File.exist?(proj_file)
238+
end
239+
end
196240
end
197241
end

lib/arduino_ci/arduino_installation.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def autolocate
5555
"processing.app.Base",
5656
]
5757
end
58-
ret.lib_dir = File.join(osx_place, "Libraries")
58+
ret.lib_dir = File.join(osx_place, "Libraries") # TODO: probably wrong
5959
ret.requires_x = false
6060
return ret
6161
end

0 commit comments

Comments
 (0)