From af033ee4e097c26512e8f5b6927be77881237de3 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 6 Nov 2018 21:45:29 -0500 Subject: [PATCH] fill in ConfigureOp#test_c_compiler --- lib/rscons/application.rb | 2 +- lib/rscons/configure_op.rb | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/rscons/application.rb b/lib/rscons/application.rb index 2cb9786..e7bad87 100644 --- a/lib/rscons/application.rb +++ b/lib/rscons/application.rb @@ -88,7 +88,7 @@ module Rscons if ccc = @script.check_c_compiler co.check_c_compiler(ccc) end - rescue ConfigureOp::ConfigFailure + rescue ConfigureOp::ConfigureFailure rv = 1 end co.close diff --git a/lib/rscons/configure_op.rb b/lib/rscons/configure_op.rb index 3c13b74..f82896f 100644 --- a/lib/rscons/configure_op.rb +++ b/lib/rscons/configure_op.rb @@ -1,11 +1,12 @@ require "fileutils" +require "open3" module Rscons # Class to manage a configure operation. class ConfigureOp # Exception raised when a configuration error occurs. - class ConfigFailure < Exception; end + class ConfigureFailure < Exception; end # Create a ConfigureOp. # @@ -51,6 +52,28 @@ module Rscons # @return [Boolean] # Whether the C compiler tested successfully. def test_c_compiler(cc) + File.open("#{@work_dir}/cfgtest.c", "wb") do |fh| + fh.puts <<-EOF + #include + int main(int argc, char * argv[]) { + printf("Hello.\\n"); + return 0; + } + EOF + end + case cc + when "gcc" + command = %W[gcc -o #{@work_dir}/cfgtest.exe #{@work_dir}/cfgtest.c] + when "clang" + command = %W[clang -o #{@work_dir}/cfgtest.exe #{@work_dir}/cfgtest.c] + else + raise ConfigureFailure.new("Unknown C compiler (#{cc})") + 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