implement ConfigureOp#check_c_header
This commit is contained in:
parent
95d5ada865
commit
6bb0a55a55
3
build_tests/configure/check_c_header_failure.rb
Normal file
3
build_tests/configure/check_c_header_failure.rb
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
configure do
|
||||||
|
check_c_header "not___found.h"
|
||||||
|
end
|
3
build_tests/configure/check_c_header_no_fail.rb
Normal file
3
build_tests/configure/check_c_header_no_fail.rb
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
configure do
|
||||||
|
check_c_header "not___found.h", fail: false
|
||||||
|
end
|
3
build_tests/configure/check_c_header_success.rb
Normal file
3
build_tests/configure/check_c_header_success.rb
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
configure do
|
||||||
|
check_c_header "string.h"
|
||||||
|
end
|
@ -94,6 +94,11 @@ module Rscons
|
|||||||
if cdc = @script.check_d_compiler
|
if cdc = @script.check_d_compiler
|
||||||
co.check_d_compiler(cdc)
|
co.check_d_compiler(cdc)
|
||||||
end
|
end
|
||||||
|
if cchs = @script.check_c_headers
|
||||||
|
cchs.each do |cch|
|
||||||
|
co.check_c_header(*cch)
|
||||||
|
end
|
||||||
|
end
|
||||||
rescue ConfigureOp::ConfigureFailure
|
rescue ConfigureOp::ConfigureFailure
|
||||||
rv = 1
|
rv = 1
|
||||||
end
|
end
|
||||||
|
@ -98,6 +98,27 @@ module Rscons
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Check for a C header.
|
||||||
|
def check_c_header(header_name, options = {})
|
||||||
|
$stdout.write("Checking for C header '#{header_name}'... ")
|
||||||
|
File.open("#{@work_dir}/cfgtest.c", "wb") do |fh|
|
||||||
|
fh.puts <<-EOF
|
||||||
|
#include "#{header_name}"
|
||||||
|
int main(int argc, char * argv[]) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
end
|
||||||
|
vars = {
|
||||||
|
"LD" => "${CC}",
|
||||||
|
"_SOURCES" => "#{@work_dir}/cfgtest.c",
|
||||||
|
"_TARGET" => "#{@work_dir}/cfgtest.exe",
|
||||||
|
}
|
||||||
|
command = @env.build_command("${LDCMD}", vars)
|
||||||
|
_, _, status = log_and_test_command(command)
|
||||||
|
common_config_checks(status, options)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# Test a C compiler.
|
# Test a C compiler.
|
||||||
@ -234,5 +255,31 @@ module Rscons
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Perform processing common to several configure checks.
|
||||||
|
#
|
||||||
|
# @param status [Process::Status, Integer]
|
||||||
|
# Process exit code.
|
||||||
|
# @param options [Hash]
|
||||||
|
# Common check options.
|
||||||
|
# @option options [Boolean] :fail
|
||||||
|
# Whether to fail configuration if the requested item is not found.
|
||||||
|
# @option options [String] :set_define
|
||||||
|
# A define to set (in CPPDEFINES) if the requested item is found.
|
||||||
|
def common_config_checks(status, options)
|
||||||
|
if status == 0
|
||||||
|
Ansi.write($stdout, :green, "found\n")
|
||||||
|
else
|
||||||
|
if options.has_key?(:fail) and not options[:fail]
|
||||||
|
Ansi.write($stdout, :yellow, "not found\n")
|
||||||
|
else
|
||||||
|
Ansi.write($stdout, :red, "not found\n")
|
||||||
|
raise ConfigureFailure.new
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if options[:set_define]
|
||||||
|
@env["CPPDEFINES"] << options[:set_define]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1620,6 +1620,32 @@ EOF
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "check_c_header" do
|
||||||
|
it "succeeds when the requested header is found" do
|
||||||
|
test_dir "configure"
|
||||||
|
result = run_rscons(rsconsfile: "check_c_header_success.rb", op: "configure")
|
||||||
|
expect(result.stderr).to eq ""
|
||||||
|
expect(result.status).to eq 0
|
||||||
|
expect(result.stdout).to match /Checking for C header 'string\.h'... found/
|
||||||
|
end
|
||||||
|
|
||||||
|
it "fails when the requested header is not found" do
|
||||||
|
test_dir "configure"
|
||||||
|
result = run_rscons(rsconsfile: "check_c_header_failure.rb", op: "configure")
|
||||||
|
expect(result.stderr).to eq ""
|
||||||
|
expect(result.status).to_not eq 0
|
||||||
|
expect(result.stdout).to match /Checking for C header 'not___found\.h'... not found/
|
||||||
|
end
|
||||||
|
|
||||||
|
it "succeeds when the requested header is not found but :fail is set to false" do
|
||||||
|
test_dir "configure"
|
||||||
|
result = run_rscons(rsconsfile: "check_c_header_no_fail.rb", op: "configure")
|
||||||
|
expect(result.stderr).to eq ""
|
||||||
|
expect(result.status).to eq 0
|
||||||
|
expect(result.stdout).to match /Checking for C header 'not___found\.h'... not found/
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user