check_c_compiler: print output; add a integration test

This commit is contained in:
Josh Holtrop 2018-11-06 22:16:38 -05:00
parent 07d9b97ddc
commit 7eeb6312ba
3 changed files with 38 additions and 6 deletions

View File

@ -0,0 +1,3 @@
configure do
check_c_compiler "gcc", "clang"
end

View File

@ -33,6 +33,7 @@ module Rscons
# #
# @return [void] # @return [void]
def check_c_compiler(ccc) def check_c_compiler(ccc)
$stdout.write("Checking for C compiler... ")
if ccc.empty? if ccc.empty?
# Default C compiler search array. # Default C compiler search array.
ccc = %w[gcc clang] ccc = %w[gcc clang]
@ -40,6 +41,12 @@ module Rscons
cc = ccc.find do |cc| cc = ccc.find do |cc|
test_c_compiler(cc) test_c_compiler(cc)
end end
if cc
Ansi.write($stdout, :green, cc, "\n")
else
Ansi.write($stdout, :red, "not found\n")
raise ConfigureFailure.new
end
end end
private private
@ -67,13 +74,25 @@ module Rscons
when "clang" when "clang"
command = %W[clang -o #{@work_dir}/cfgtest.exe #{@work_dir}/cfgtest.c] command = %W[clang -o #{@work_dir}/cfgtest.exe #{@work_dir}/cfgtest.c]
else else
raise ConfigureFailure.new("Unknown C compiler (#{cc})") $stderr.puts "Unknown C compiler (#{cc})"
raise ConfigureFailure.new
end end
_, _, status = log_and_test_command(command)
status == 0
end
# Execute a test command and log the result.
def log_and_test_command(command)
begin
@log_fh.puts("Command: #{command.join(" ")}") @log_fh.puts("Command: #{command.join(" ")}")
stdout, stderr, status = Open3.capture3(*command) stdout, stderr, status = Open3.capture3(*command)
@log_fh.puts("Exit status: #{status.to_i}")
@log_fh.write(stdout) @log_fh.write(stdout)
@log_fh.write(stderr) @log_fh.write(stderr)
status != 0 [stdout, stderr, status]
rescue Errno::ENOENT
["", "", 127]
end
end end
end end

View File

@ -1489,6 +1489,16 @@ EOF
expect(result.stderr).to match /NoMethodError/ expect(result.stderr).to match /NoMethodError/
expect(result.status).to_not eq 0 expect(result.status).to_not eq 0
end end
context "check_c_compiler" do
it "finds the first listed C compiler" do
test_dir "configure"
result = run_rscons(rsconsfile: "check_c_compiler_find_first.rb", op: "configure")
expect(result.stderr).to eq ""
expect(result.status).to eq 0
expect(result.stdout).to match /Checking for C compiler\.\.\. gcc/
end
end
end end
end end