From 6e590b62a69837f414ea4353580a2e62e3ab6364 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 9 Jul 2019 23:53:17 -0400 Subject: [PATCH] add :check_cpppath option to check_c_header and check_cxx_header configuration methods add :check_d_import_path option to check_d_import configuration method - #107 --- .../configure/check_c_header_cpppath.rb | 10 ++++ .../configure/check_cxx_header_cpppath.rb | 10 ++++ .../configure/check_d_import_d_import_path.rb | 10 ++++ lib/rscons/configure_op.rb | 54 ++++++++++++++++--- spec/build_tests_spec.rb | 45 ++++++++++++++++ 5 files changed, 123 insertions(+), 6 deletions(-) create mode 100644 build_tests/configure/check_c_header_cpppath.rb create mode 100644 build_tests/configure/check_cxx_header_cpppath.rb create mode 100644 build_tests/configure/check_d_import_d_import_path.rb diff --git a/build_tests/configure/check_c_header_cpppath.rb b/build_tests/configure/check_c_header_cpppath.rb new file mode 100644 index 0000000..c3fd28c --- /dev/null +++ b/build_tests/configure/check_c_header_cpppath.rb @@ -0,0 +1,10 @@ +configure do + check_c_header "string.h", check_cpppath: ["./usr1"] + check_c_header "frobulous.h", check_cpppath: ["./usr2"] +end + +build do + Environment.new do |env| + env.Object("test.o", "test.c") + end +end diff --git a/build_tests/configure/check_cxx_header_cpppath.rb b/build_tests/configure/check_cxx_header_cpppath.rb new file mode 100644 index 0000000..242e919 --- /dev/null +++ b/build_tests/configure/check_cxx_header_cpppath.rb @@ -0,0 +1,10 @@ +configure do + check_cxx_header "string.h", check_cpppath: ["./usr1"] + check_cxx_header "frobulous.h", check_cpppath: ["./usr2"] +end + +build do + Environment.new do |env| + env.Object("test.o", "test.cc") + end +end diff --git a/build_tests/configure/check_d_import_d_import_path.rb b/build_tests/configure/check_d_import_d_import_path.rb new file mode 100644 index 0000000..2b86dd1 --- /dev/null +++ b/build_tests/configure/check_d_import_d_import_path.rb @@ -0,0 +1,10 @@ +configure do + check_d_import "std.stdio", check_d_import_path: ["./usr1"] + check_d_import "frobulous", check_d_import_path: ["./usr2"] +end + +build do + Environment.new do |env| + env.Object("test.o", "test.d") + end +end diff --git a/lib/rscons/configure_op.rb b/lib/rscons/configure_op.rb index 5f67437..ac3fa10 100644 --- a/lib/rscons/configure_op.rb +++ b/lib/rscons/configure_op.rb @@ -127,6 +127,7 @@ module Rscons # Check for a C header. def check_c_header(header_name, options = {}) + check_cpppath = [nil] + (options[:check_cpppath] || []) Ansi.write($stdout, "Checking for C header '", :cyan, header_name, :reset, "'... ") File.open("#{@work_dir}/cfgtest.c", "wb") do |fh| fh.puts <<-EOF @@ -142,13 +143,27 @@ module Rscons "_TARGET" => "#{@work_dir}/cfgtest.o", "_DEPFILE" => "#{@work_dir}/cfgtest.mf", } - command = BasicEnvironment.new.build_command("${CCCMD}", vars) - _, _, status = log_and_test_command(command) + status = 1 + check_cpppath.each do |cpppath| + env = BasicEnvironment.new + if cpppath + env["CPPPATH"] += Array(cpppath) + end + command = env.build_command("${CCCMD}", vars) + _, _, status = log_and_test_command(command) + if status == 0 + if cpppath + store_append({"CPPPATH" => Array(cpppath)}, options) + end + break + end + end common_config_checks(status, options) end # Check for a C++ header. def check_cxx_header(header_name, options = {}) + check_cpppath = [nil] + (options[:check_cpppath] || []) Ansi.write($stdout, "Checking for C++ header '", :cyan, header_name, :reset, "'... ") File.open("#{@work_dir}/cfgtest.cxx", "wb") do |fh| fh.puts <<-EOF @@ -164,13 +179,27 @@ module Rscons "_TARGET" => "#{@work_dir}/cfgtest.o", "_DEPFILE" => "#{@work_dir}/cfgtest.mf", } - command = BasicEnvironment.new.build_command("${CXXCMD}", vars) - _, _, status = log_and_test_command(command) + status = 1 + check_cpppath.each do |cpppath| + env = BasicEnvironment.new + if cpppath + env["CPPPATH"] += Array(cpppath) + end + command = env.build_command("${CXXCMD}", vars) + _, _, status = log_and_test_command(command) + if status == 0 + if cpppath + store_append({"CPPPATH" => Array(cpppath)}, options) + end + break + end + end common_config_checks(status, options) end # Check for a D import. def check_d_import(d_import, options = {}) + check_d_import_path = [nil] + (options[:check_d_import_path] || []) Ansi.write($stdout, "Checking for D import '", :cyan, d_import, :reset, "'... ") File.open("#{@work_dir}/cfgtest.d", "wb") do |fh| fh.puts <<-EOF @@ -186,8 +215,21 @@ module Rscons "_TARGET" => "#{@work_dir}/cfgtest.o", "_DEPFILE" => "#{@work_dir}/cfgtest.mf", } - command = BasicEnvironment.new.build_command("${DCCMD}", vars) - _, _, status = log_and_test_command(command) + status = 1 + check_d_import_path.each do |d_import_path| + env = BasicEnvironment.new + if d_import_path + env["D_IMPORT_PATH"] += Array(d_import_path) + end + command = env.build_command("${DCCMD}", vars) + _, _, status = log_and_test_command(command) + if status == 0 + if d_import_path + store_append({"D_IMPORT_PATH" => Array(d_import_path)}, options) + end + break + end + end common_config_checks(status, options) end diff --git a/spec/build_tests_spec.rb b/spec/build_tests_spec.rb index 9428216..3c51917 100644 --- a/spec/build_tests_spec.rb +++ b/spec/build_tests_spec.rb @@ -1835,6 +1835,21 @@ EOF expect(result.status).to eq 0 expect(result.stdout).to_not match /-DHAVE_/ end + + it "modifies CPPPATH based on check_cpppath" do + test_dir "configure" + FileUtils.mkdir_p("usr1") + FileUtils.mkdir_p("usr2") + File.open("usr2/frobulous.h", "wb") do |fh| + fh.puts("#define FOO 42") + end + result = run_rscons(rsconscript: "check_c_header_cpppath.rb", op: "configure") + expect(result.stderr).to eq "" + expect(result.status).to eq 0 + result = run_rscons(rsconscript: "check_c_header_cpppath.rb", rscons_args: %w[-v]) + expect(result.stdout).to_not match %r{-I./usr1} + expect(result.stdout).to match %r{-I./usr2} + end end context "check_cxx_header" do @@ -1861,6 +1876,21 @@ EOF expect(result.status).to eq 0 expect(result.stdout).to match /Checking for C\+\+ header 'not___found\.h'... not found/ end + + it "modifies CPPPATH based on check_cpppath" do + test_dir "configure" + FileUtils.mkdir_p("usr1") + FileUtils.mkdir_p("usr2") + File.open("usr2/frobulous.h", "wb") do |fh| + fh.puts("#define FOO 42") + end + result = run_rscons(rsconscript: "check_cxx_header_cpppath.rb", op: "configure") + expect(result.stderr).to eq "" + expect(result.status).to eq 0 + result = run_rscons(rsconscript: "check_cxx_header_cpppath.rb", rscons_args: %w[-v]) + expect(result.stdout).to_not match %r{-I./usr1} + expect(result.stdout).to match %r{-I./usr2} + end end context "check_d_import" do @@ -1887,6 +1917,21 @@ EOF expect(result.status).to eq 0 expect(result.stdout).to match /Checking for D import 'not\.found'... not found/ end + + it "modifies D_IMPORT_PATH based on check_d_import_path" do + test_dir "configure" + FileUtils.mkdir_p("usr1") + FileUtils.mkdir_p("usr2") + File.open("usr2/frobulous.d", "wb") do |fh| + fh.puts("int foo = 42;") + end + result = run_rscons(rsconscript: "check_d_import_d_import_path.rb", op: "configure") + expect(result.stderr).to eq "" + expect(result.status).to eq 0 + result = run_rscons(rsconscript: "check_d_import_d_import_path.rb", rscons_args: %w[-v]) + expect(result.stdout).to_not match %r{-I./usr1} + expect(result.stdout).to match %r{-I./usr2} + end end context "check_lib" do