Skip to content

Commit e54bc88

Browse files
committed
Track command and output of GCC
1 parent 13c8564 commit e54bc88

File tree

3 files changed

+58
-39
lines changed

3 files changed

+58
-39
lines changed

exe/arduino_ci_remote.rb

+20-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# terminate after printing any debug info. TODO: capture debug info
1010
def terminate
1111
puts "Failures: #{@failure_count}"
12-
unless failure_count.zero?
12+
unless @failure_count.zero?
1313
puts "Last message: #{@arduino_cmd.last_msg}"
1414
puts "========== Stdout:"
1515
puts @arduino_cmd.last_out
@@ -96,10 +96,8 @@ def assure(message, &block)
9696
attempt("Verifying #{example_name}") do
9797
ret = @arduino_cmd.verify_sketch(example_path)
9898
unless ret
99-
puts "Last message: #{@arduino_cmd.last_msg}"
100-
puts "========== Stdout:"
101-
puts @arduino_cmd.last_out
102-
puts "========== Stderr:"
99+
puts
100+
puts "Last command: #{@arduino_cmd.last_msg}"
103101
puts @arduino_cmd.last_err
104102
end
105103
ret
@@ -112,6 +110,22 @@ def assure(message, &block)
112110
assure("Switching to board for #{p} (#{board})") { @arduino_cmd.use_board(board) }
113111
cpp_library.test_files.each do |unittest_path|
114112
unittest_name = File.basename(unittest_path)
115-
attempt("Unit testing #{unittest_name}") { cpp_library.test(unittest_path) }
113+
attempt("Unit testing #{unittest_name}") do
114+
exe = build_for_test_with_configuration(
115+
unittest_path,
116+
config.aux_libraries_for_unittest,
117+
config.gcc_config(p)
118+
)
119+
unless exe
120+
puts
121+
puts "Last command: #{cpp_library.last_cmd}"
122+
puts cpp_library.last_out
123+
puts cpp_library.last_err
124+
next false
125+
end
126+
cpp_library.run_test_file(exe)
127+
end
116128
end
117129
end
130+
131+
terminate

lib/arduino_ci/ci_config.rb

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

177-
def features(platform_name)
177+
def gcc_config(platform_name)
178178
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]
179+
return {} if plat.nil?
180+
return {} if plat[:gcc].nil?
181+
plat[:gcc]
183182
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-
209183
end
210184

211185
end

lib/arduino_ci/cpp_library.rb

+34-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,16 @@ class CppLibrary
1414
attr_reader :base_dir
1515
attr_reader :artifacts
1616

17+
attr_reader :last_err
18+
attr_reader :last_out
19+
attr_reader :last_cmd
20+
1721
def initialize(base_dir)
1822
@base_dir = base_dir
1923
@artifacts = []
24+
@last_err = ""
25+
@last_out = ""
26+
@last_msg = ""
2027
end
2128

2229
def cpp_files_in(some_dir)
@@ -56,9 +63,23 @@ def header_dirs
5663

5764
# wrapper for the GCC command
5865
def run_gcc(*args, **kwargs)
59-
# TODO: detect env!!
66+
pipe_out, pipe_out_wr = IO.pipe
67+
pipe_err, pipe_err_wr = IO.pipe
6068
full_args = ["g++"] + args
61-
Host.run(*full_args, **kwargs)
69+
@last_cmd = " $ #{full_args.join(' ')}"
70+
our_kwargs = { out: pipe_out_wr, err: pipe_err_wr }
71+
eventual_kwargs = our_kwargs.merge(kwargs)
72+
success = Host.run(*full_args, **eventual_kwargs)
73+
74+
pipe_out_wr.close
75+
pipe_err_wr.close
76+
str_out = pipe_out.read
77+
str_err = pipe_err.read
78+
pipe_out.close
79+
pipe_err.close
80+
@last_err = str_err
81+
@last_out = str_out
82+
success
6283
end
6384

6485
# GCC command line arguments for including aux libraries
@@ -104,12 +125,22 @@ def test_args(aux_libraries, ci_gcc_config)
104125

105126
# run a test of the given unit test file
106127
def test_with_configuration(test_file, aux_libraries, ci_gcc_config)
128+
executable = build_for_test_with_configuration(test_file, aux_libraries, ci_gcc_config)
129+
run_test_file(executable)
130+
end
131+
132+
# run a test of the given unit test file
133+
def build_for_test_with_configuration(test_file, aux_libraries, ci_gcc_config)
107134
base = File.basename(test_file)
108135
executable = File.expand_path("unittest_#{base}.bin")
109136
File.delete(executable) if File.exist?(executable)
110137
args = ["-o", executable] + test_args(aux_libraries, ci_gcc_config) + [test_file]
111-
return false unless run_gcc(*args)
138+
return nil unless run_gcc(*args)
112139
artifacts << executable
140+
executable
141+
end
142+
143+
def run_test_file(executable)
113144
Host.run(executable)
114145
end
115146

0 commit comments

Comments
 (0)