Skip to content

Commit ea4cd94

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

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

exe/arduino_ci_remote.rb

+15-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,17 @@ 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+
ret = cpp_library.test(unittest_path)
115+
unless ret
116+
puts
117+
puts "Last command: #{cpp_library.last_cmd}"
118+
puts cpp_library.last_out
119+
puts cpp_library.last_err
120+
end
121+
ret
122+
end
116123
end
117124
end
125+
126+
terminate

lib/arduino_ci/cpp_library.rb

+23-2
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

0 commit comments

Comments
 (0)