fill in ConfigureOp#test_c_compiler

This commit is contained in:
Josh Holtrop 2018-11-06 21:45:29 -05:00
parent c9de4f37e6
commit af033ee4e0
2 changed files with 25 additions and 2 deletions

View File

@ -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

View File

@ -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 <stdio.h>
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