From 6078cb097765b1644c1a6e022fe84568f2cfe260 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Wed, 7 Nov 2018 21:49:44 -0500 Subject: [PATCH] implement ConfigureOp#check_d_import --- .../configure/check_d_import_failure.rb | 3 +++ .../configure/check_d_import_no_fail.rb | 3 +++ .../configure/check_d_import_success.rb | 3 +++ lib/rscons/application.rb | 5 ++++ lib/rscons/configure_op.rb | 21 +++++++++++++++ spec/build_tests_spec.rb | 26 +++++++++++++++++++ 6 files changed, 61 insertions(+) create mode 100644 build_tests/configure/check_d_import_failure.rb create mode 100644 build_tests/configure/check_d_import_no_fail.rb create mode 100644 build_tests/configure/check_d_import_success.rb diff --git a/build_tests/configure/check_d_import_failure.rb b/build_tests/configure/check_d_import_failure.rb new file mode 100644 index 0000000..c8987b2 --- /dev/null +++ b/build_tests/configure/check_d_import_failure.rb @@ -0,0 +1,3 @@ +configure do + check_d_import "not.found" +end diff --git a/build_tests/configure/check_d_import_no_fail.rb b/build_tests/configure/check_d_import_no_fail.rb new file mode 100644 index 0000000..90bc6ab --- /dev/null +++ b/build_tests/configure/check_d_import_no_fail.rb @@ -0,0 +1,3 @@ +configure do + check_d_import "not.found", fail: false +end diff --git a/build_tests/configure/check_d_import_success.rb b/build_tests/configure/check_d_import_success.rb new file mode 100644 index 0000000..e2c2380 --- /dev/null +++ b/build_tests/configure/check_d_import_success.rb @@ -0,0 +1,3 @@ +configure do + check_d_import "std.stdio" +end diff --git a/lib/rscons/application.rb b/lib/rscons/application.rb index 07bcb32..37bbeed 100644 --- a/lib/rscons/application.rb +++ b/lib/rscons/application.rb @@ -104,6 +104,11 @@ module Rscons co.check_cxx_header(*cch) end end + if cdis = @script.check_d_imports + cdis.each do |cdi| + co.check_d_import(*cdi) + end + end rescue ConfigureOp::ConfigureFailure rv = 1 end diff --git a/lib/rscons/configure_op.rb b/lib/rscons/configure_op.rb index ca32f39..4844945 100644 --- a/lib/rscons/configure_op.rb +++ b/lib/rscons/configure_op.rb @@ -140,6 +140,27 @@ module Rscons common_config_checks(status, options) end + # Check for a D import. + def check_d_import(d_import, options = {}) + $stdout.write("Checking for D import '#{d_import}'... ") + File.open("#{@work_dir}/cfgtest.d", "wb") do |fh| + fh.puts <<-EOF + import #{d_import}; + int main() { + return 0; + } + EOF + end + vars = { + "LD" => "${DC}", + "_SOURCES" => "#{@work_dir}/cfgtest.d", + "_TARGET" => "#{@work_dir}/cfgtest.exe", + } + command = @env.build_command("${LDCMD}", vars) + _, _, status = log_and_test_command(command) + common_config_checks(status, options) + end + private # Test a C compiler. diff --git a/spec/build_tests_spec.rb b/spec/build_tests_spec.rb index 09c1118..0571dd4 100644 --- a/spec/build_tests_spec.rb +++ b/spec/build_tests_spec.rb @@ -1672,6 +1672,32 @@ EOF expect(result.stdout).to match /Checking for C\+\+ header 'not___found\.h'... not found/ end end + + context "check_d_import" do + it "succeeds when the requested import is found" do + test_dir "configure" + result = run_rscons(rsconsfile: "check_d_import_success.rb", op: "configure") + expect(result.stderr).to eq "" + expect(result.status).to eq 0 + expect(result.stdout).to match /Checking for D import 'std\.stdio'... found/ + end + + it "fails when the requested import is not found" do + test_dir "configure" + result = run_rscons(rsconsfile: "check_d_import_failure.rb", op: "configure") + expect(result.stderr).to eq "" + expect(result.status).to_not eq 0 + expect(result.stdout).to match /Checking for D import 'not\.found'... not found/ + end + + it "succeeds when the requested import is not found but :fail is set to false" do + test_dir "configure" + result = run_rscons(rsconsfile: "check_d_import_no_fail.rb", op: "configure") + expect(result.stderr).to eq "" + expect(result.status).to eq 0 + expect(result.stdout).to match /Checking for D import 'not\.found'... not found/ + end + end end end