Skip to content

Commit 9409f08

Browse files
committed
factor out gcc args
1 parent e9eb4af commit 9409f08

File tree

2 files changed

+79
-4
lines changed

2 files changed

+79
-4
lines changed

lib/arduino_ci/ci_config.rb

+32
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,38 @@ def aux_libraries_for_unittest
174174
@unittest_info[:libraries]
175175
end
176176

177+
def features(platform_name)
178+
plat = @platform_info[platform_name]
179+
return [] if plat.nil?
180+
return [] if plat[:gcc].nil?
181+
return [] if plat[:gcc][:features].nil?
182+
plat[:gcc][:features]
183+
end
184+
185+
def warnings(platform_name)
186+
plat = @platform_info[platform_name]
187+
return [] if plat.nil?
188+
return [] if plat[:gcc].nil?
189+
return [] if plat[:gcc][:warnings].nil?
190+
plat[:gcc][:warnings]
191+
end
192+
193+
def flags(platform_name)
194+
plat = @platform_info[platform_name]
195+
return [] if plat.nil?
196+
return [] if plat[:gcc].nil?
197+
return [] if plat[:gcc][:flags].nil?
198+
plat[:gcc][:flags]
199+
end
200+
201+
def defines(platform_name)
202+
plat = @platform_info[platform_name]
203+
return [] if plat.nil?
204+
return [] if plat[:gcc].nil?
205+
return [] if plat[:gcc][:flags].nil?
206+
plat[:gcc][:flags]
207+
end
208+
177209
end
178210

179211
end

lib/arduino_ci/cpp_library.rb

+47-4
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,63 @@ def run_gcc(*args, **kwargs)
6161
Host.run(*full_args, **kwargs)
6262
end
6363

64-
def test_args
65-
["-I#{UNITTEST_HEADER_DIR}"] + build_args + cpp_files_arduino + cpp_files_unittest + cpp_files
64+
# GCC command line arguments for including aux libraries
65+
def include_args(aux_libraries)
66+
places = [ARDUINO_HEADER_DIR, UNITTEST_HEADER_DIR] + header_dirs + aux_libraries
67+
places.map { |d| "-I#{d}" }
6668
end
6769

68-
def test(test_file)
70+
# GCC command line arguments for features (e.g. -fno-weak)
71+
def feature_args(ci_gcc_config)
72+
return [] if ci_gcc_config[:features].nil?
73+
ci_gcc_config[:features].map { |f| "-f#{f}" }
74+
end
75+
76+
# GCC command line arguments for warning (e.g. -Wall)
77+
def warning_args(ci_gcc_config)
78+
return [] if ci_gcc_config[:warnings].nil?
79+
ci_gcc_config[:features].map { |w| "-W#{w}" }
80+
end
81+
82+
# GCC command line arguments for defines (e.g. -Dhave_something)
83+
def define_args(ci_gcc_config)
84+
return [] if ci_gcc_config[:defines].nil?
85+
ci_gcc_config[:defines].map { |d| "-D#{d}" }
86+
end
87+
88+
# GCC command line arguments as-is
89+
def flag_args(ci_gcc_config)
90+
return [] if ci_gcc_config[:flags].nil?
91+
ci_gcc_config[:flags]
92+
end
93+
94+
# All GCC command line args for building any unit test
95+
def test_args(aux_libraries, ci_gcc_config)
96+
# TODO: something with libraries?
97+
cgc = ci_gcc_config
98+
ret = include_args(aux_libraries) + cpp_files_arduino + cpp_files_unittest + cpp_files
99+
unless ci_gcc_config.nil?
100+
ret = feature_args(cgc) + warning_args(cgc) + define_args(cgc) + flag_args(cgc) + ret
101+
end
102+
ret
103+
end
104+
105+
# run a test of the given unit test file
106+
def test_with_configuration(test_file, aux_libraries, ci_gcc_config)
69107
base = File.basename(test_file)
70108
executable = File.expand_path("unittest_#{base}.bin")
71109
File.delete(executable) if File.exist?(executable)
72-
args = ["-o", executable] + test_args + [test_file]
110+
args = ["-o", executable] + test_args(aux_libraries, ci_gcc_config) + [test_file]
73111
return false unless run_gcc(*args)
74112
artifacts << executable
75113
Host.run(executable)
76114
end
77115

116+
# legacy shortcut for rspec
117+
def test(test_file)
118+
test_with_configuration(test_file, [], nil)
119+
end
120+
78121
end
79122

80123
end

0 commit comments

Comments
 (0)