implement ConfigureOp#check_d_compiler
This commit is contained in:
parent
d54d363a25
commit
d656df5407
3
build_tests/configure/check_d_compiler.rb
Normal file
3
build_tests/configure/check_d_compiler.rb
Normal file
@ -0,0 +1,3 @@
|
||||
configure do
|
||||
check_d_compiler
|
||||
end
|
3
build_tests/configure/check_d_compiler_find_first.rb
Normal file
3
build_tests/configure/check_d_compiler_find_first.rb
Normal file
@ -0,0 +1,3 @@
|
||||
configure do
|
||||
check_d_compiler "gdc", "ldc2"
|
||||
end
|
@ -91,6 +91,9 @@ module Rscons
|
||||
if ccc = @script.check_cxx_compiler
|
||||
co.check_cxx_compiler(ccc)
|
||||
end
|
||||
if cdc = @script.check_d_compiler
|
||||
co.check_d_compiler(cdc)
|
||||
end
|
||||
rescue ConfigureOp::ConfigureFailure
|
||||
rv = 1
|
||||
end
|
||||
|
@ -72,6 +72,29 @@ module Rscons
|
||||
end
|
||||
end
|
||||
|
||||
# Check for a working D compiler.
|
||||
#
|
||||
# @param cdc [Array<String>]
|
||||
# D compiler(s) to check for.
|
||||
#
|
||||
# @return [void]
|
||||
def check_d_compiler(cdc)
|
||||
$stdout.write("Checking for D compiler... ")
|
||||
if cdc.empty?
|
||||
# Default D compiler search array.
|
||||
cdc = %w[gdc ldc2]
|
||||
end
|
||||
dc = cdc.find do |dc|
|
||||
test_d_compiler(dc)
|
||||
end
|
||||
if dc
|
||||
Ansi.write($stdout, :green, dc, "\n")
|
||||
else
|
||||
Ansi.write($stdout, :red, "not found\n")
|
||||
raise ConfigureFailure.new
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Test a C compiler.
|
||||
@ -135,6 +158,36 @@ module Rscons
|
||||
status == 0
|
||||
end
|
||||
|
||||
# Test a D compiler.
|
||||
#
|
||||
# @param dc [String]
|
||||
# D compiler to test.
|
||||
#
|
||||
# @return [Boolean]
|
||||
# Whether the D compiler tested successfully.
|
||||
def test_d_compiler(dc)
|
||||
File.open("#{@work_dir}/cfgtest.d", "wb") do |fh|
|
||||
fh.puts <<-EOF
|
||||
import std.stdio;
|
||||
int main() {
|
||||
writeln("Hello.");
|
||||
return 0;
|
||||
}
|
||||
EOF
|
||||
end
|
||||
case dc
|
||||
when "gdc"
|
||||
command = %W[gdc -o #{@work_dir}/cfgtest.exe #{@work_dir}/cfgtest.d]
|
||||
when "ldc2"
|
||||
command = %W[ldc2 -of=#{@work_dir}/cfgtest.exe #{@work_dir}/cfgtest.d]
|
||||
else
|
||||
$stderr.puts "Unknown D compiler (#{dc})"
|
||||
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
|
||||
|
@ -1568,6 +1568,40 @@ EOF
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "check_d_compiler" do
|
||||
{"check_d_compiler.rb" => "when no arguments are given",
|
||||
"check_d_compiler_find_first.rb" => "when arguments are given"}.each_pair do |rsconsfile, desc|
|
||||
context desc do
|
||||
it "finds the first listed D compiler" do
|
||||
test_dir "configure"
|
||||
result = run_rscons(rsconsfile: rsconsfile, op: "configure")
|
||||
expect(result.stderr).to eq ""
|
||||
expect(result.status).to eq 0
|
||||
expect(result.stdout).to match /Checking for D compiler\.\.\. gdc/
|
||||
end
|
||||
|
||||
it "finds the second listed D compiler" do
|
||||
test_dir "configure"
|
||||
create_exe "gdc", "exit 1"
|
||||
result = run_rscons(rsconsfile: rsconsfile, op: "configure")
|
||||
expect(result.stderr).to eq ""
|
||||
expect(result.status).to eq 0
|
||||
expect(result.stdout).to match /Checking for D compiler\.\.\. ldc2/
|
||||
end
|
||||
|
||||
it "fails to configure when it cannot find a D compiler" do
|
||||
test_dir "configure"
|
||||
create_exe "gdc", "exit 1"
|
||||
create_exe "ldc2", "exit 1"
|
||||
result = run_rscons(rsconsfile: rsconsfile, op: "configure")
|
||||
expect(result.stderr).to eq ""
|
||||
expect(result.status).to_not eq 0
|
||||
expect(result.stdout).to match /Checking for D compiler\.\.\. not found/
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user