Skip to content

Commit d9dee36

Browse files
committed
Add support for extracting code files from C++ libs
1 parent 800501c commit d9dee36

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

lib/arduino_ci.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require "arduino_ci/version"
22
require "arduino_ci/arduino_installation"
3+
require "arduino_ci/cpp_library"
34

45
# ArduinoCI contains classes for automated testing of Arduino code on the command line
56
# @author Ian Katz <[email protected]>

lib/arduino_ci/cpp_library.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
require 'find'
2+
require "arduino_ci/host"
3+
4+
HPP_EXTENSIONS = [".hpp", ".hh", ".h", ".hxx", ".h++"].freeze
5+
CPP_EXTENSIONS = [".cpp", ".cc", ".c", ".cxx", ".c++"].freeze
6+
7+
module ArduinoCI
8+
9+
# Information about an Arduino CPP library, specifically for compilation purposes
10+
class CppLibrary
11+
12+
attr_reader :base_dir
13+
14+
def initialize(base_dir)
15+
@base_dir = base_dir
16+
end
17+
18+
def cpp_files
19+
Find.find(@base_dir).select { |path| CPP_EXTENSIONS.include?(File.extname(path)) }
20+
end
21+
22+
def header_dirs
23+
files = Find.find(@base_dir).select { |path| HPP_EXTENSIONS.include?(File.extname(path)) }
24+
files.map { |path| File.dirname(path) }.uniq
25+
end
26+
27+
end
28+
29+
end

spec/cpp_library_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
require "spec_helper"
2+
3+
sampleproj_path = File.join(File.dirname(File.dirname(__FILE__)), "SampleProjects")
4+
5+
RSpec.describe ArduinoCI::CppLibrary do
6+
cpp_lib_path = File.join(sampleproj_path, "DoSomething")
7+
cpp_library = ArduinoCI::CppLibrary.new(cpp_lib_path)
8+
context "cpp_files" do
9+
it "finds cpp files in directory" do
10+
dosomething_cpp_files = ["DoSomething/do-something.cpp"]
11+
relative_paths = cpp_library.cpp_files.map { |f| f.split("SampleProjects/", 2)[1] }
12+
expect(relative_paths).to match_array(dosomething_cpp_files)
13+
end
14+
end
15+
16+
context "header_dirs" do
17+
it "finds directories containing h files" do
18+
dosomething_header_dirs = ["DoSomething"]
19+
relative_paths = cpp_library.header_dirs.map { |f| f.split("SampleProjects/", 2)[1] }
20+
expect(relative_paths).to match_array(dosomething_header_dirs)
21+
end
22+
end
23+
24+
end

0 commit comments

Comments
 (0)