check_c_compiler: print output; add a integration test
This commit is contained in:
parent
07d9b97ddc
commit
7eeb6312ba
3
build_tests/configure/check_c_compiler_find_first.rb
Normal file
3
build_tests/configure/check_c_compiler_find_first.rb
Normal file
@ -0,0 +1,3 @@
|
||||
configure do
|
||||
check_c_compiler "gcc", "clang"
|
||||
end
|
@ -33,6 +33,7 @@ module Rscons
|
||||
#
|
||||
# @return [void]
|
||||
def check_c_compiler(ccc)
|
||||
$stdout.write("Checking for C compiler... ")
|
||||
if ccc.empty?
|
||||
# Default C compiler search array.
|
||||
ccc = %w[gcc clang]
|
||||
@ -40,6 +41,12 @@ module Rscons
|
||||
cc = ccc.find do |cc|
|
||||
test_c_compiler(cc)
|
||||
end
|
||||
if cc
|
||||
Ansi.write($stdout, :green, cc, "\n")
|
||||
else
|
||||
Ansi.write($stdout, :red, "not found\n")
|
||||
raise ConfigureFailure.new
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
@ -67,13 +74,25 @@ module Rscons
|
||||
when "clang"
|
||||
command = %W[clang -o #{@work_dir}/cfgtest.exe #{@work_dir}/cfgtest.c]
|
||||
else
|
||||
raise ConfigureFailure.new("Unknown C compiler (#{cc})")
|
||||
$stderr.puts "Unknown C compiler (#{cc})"
|
||||
raise ConfigureFailure.new
|
||||
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(" ")}")
|
||||
stdout, stderr, status = Open3.capture3(*command)
|
||||
@log_fh.puts("Exit status: #{status.to_i}")
|
||||
@log_fh.write(stdout)
|
||||
@log_fh.write(stderr)
|
||||
[stdout, stderr, status]
|
||||
rescue Errno::ENOENT
|
||||
["", "", 127]
|
||||
end
|
||||
@log_fh.puts("Command: #{command.join(" ")}")
|
||||
stdout, stderr, status = Open3.capture3(*command)
|
||||
@log_fh.write(stdout)
|
||||
@log_fh.write(stderr)
|
||||
status != 0
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -1489,6 +1489,16 @@ EOF
|
||||
expect(result.stderr).to match /NoMethodError/
|
||||
expect(result.status).to_not eq 0
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user