diff --git a/build_tests/configure/check_c_compiler_use.rb b/build_tests/configure/check_c_compiler_use.rb new file mode 100644 index 0000000..42e49e2 --- /dev/null +++ b/build_tests/configure/check_c_compiler_use.rb @@ -0,0 +1,12 @@ +configure do + check_c_compiler "clang", use: "clang" + check_c_compiler +end + +env "t1" do |env| + env.Program("test_gcc.exe", "simple.c") +end + +env "t2", use: "clang" do |env| + env.Program("test_clang.exe", "simple.c") +end diff --git a/build_tests/configure/check_cxx_compiler_use.rb b/build_tests/configure/check_cxx_compiler_use.rb new file mode 100644 index 0000000..dddc3bf --- /dev/null +++ b/build_tests/configure/check_cxx_compiler_use.rb @@ -0,0 +1,12 @@ +configure do + check_cxx_compiler "clang++", use: "clang" + check_cxx_compiler +end + +env "t1" do |env| + env.Program("test_gcc.exe", "simple.cc") +end + +env "t2", use: "clang" do |env| + env.Program("test_clang.exe", "simple.cc") +end diff --git a/build_tests/configure/check_d_compiler_use.rb b/build_tests/configure/check_d_compiler_use.rb new file mode 100644 index 0000000..4c55193 --- /dev/null +++ b/build_tests/configure/check_d_compiler_use.rb @@ -0,0 +1,12 @@ +configure do + check_d_compiler "ldc2", use: "ldc2" + check_d_compiler +end + +env "t1" do |env| + env.Program("test_gcc.exe", "simple.d") +end + +env "t2", use: "ldc2" do |env| + env.Program("test_ldc2.exe", "simple.d") +end diff --git a/build_tests/configure/simple.cc b/build_tests/configure/simple.cc new file mode 100644 index 0000000..1407682 --- /dev/null +++ b/build_tests/configure/simple.cc @@ -0,0 +1,6 @@ +#include + +int main(int argc, char *argv[]) +{ + std::cout << "Hi" << std::endl; +} diff --git a/build_tests/configure/simple.d b/build_tests/configure/simple.d new file mode 100644 index 0000000..3917184 --- /dev/null +++ b/build_tests/configure/simple.d @@ -0,0 +1,7 @@ +import std.stdio; + +int main() +{ + writeln("Hello"); + return 0; +} diff --git a/lib/rscons/configure_op.rb b/lib/rscons/configure_op.rb index 294565c..ba89f37 100644 --- a/lib/rscons/configure_op.rb +++ b/lib/rscons/configure_op.rb @@ -65,7 +65,7 @@ module Rscons ccc = %w[gcc clang] end cc = ccc.find do |cc| - test_c_compiler(cc) + test_c_compiler(cc, options) end complete(cc ? 0 : 1, options.merge(success_message: cc)) end @@ -87,7 +87,7 @@ module Rscons ccc = %w[g++ clang++] end cc = ccc.find do |cc| - test_cxx_compiler(cc) + test_cxx_compiler(cc, options) end complete(cc ? 0 : 1, options.merge(success_message: cc)) end @@ -109,7 +109,7 @@ module Rscons cdc = %w[gdc ldc2] end dc = cdc.find do |dc| - test_d_compiler(dc) + test_d_compiler(dc, options) end complete(dc ? 0 : 1, options.merge(success_message: dc)) end @@ -415,7 +415,7 @@ module Rscons # # @return [Boolean] # Whether the C compiler tested successfully. - def test_c_compiler(cc) + def test_c_compiler(cc, options) File.open("#{@work_dir}/cfgtest.c", "wb") do |fh| fh.puts <<-EOF int fun(int val) { @@ -427,7 +427,7 @@ module Rscons merge = {"CC" => cc} _, _, status = log_and_test_command(command) if status == 0 - store_merge(merge) + store_merge(merge, options) true end end @@ -439,7 +439,7 @@ module Rscons # # @return [Boolean] # Whether the C++ compiler tested successfully. - def test_cxx_compiler(cc) + def test_cxx_compiler(cc, options) File.open("#{@work_dir}/cfgtest.cxx", "wb") do |fh| fh.puts <<-EOF template @@ -452,7 +452,7 @@ module Rscons merge = {"CXX" => cc} _, _, status = log_and_test_command(command) if status == 0 - store_merge(merge) + store_merge(merge, options) true end end @@ -464,7 +464,7 @@ module Rscons # # @return [Boolean] # Whether the D compiler tested successfully. - def test_d_compiler(dc) + def test_d_compiler(dc, options) File.open("#{@work_dir}/cfgtest.d", "wb") do |fh| fh.puts <<-EOF import core.math; @@ -493,7 +493,7 @@ module Rscons end _, _, status = log_and_test_command(command) if status == 0 - store_merge(merge) + store_merge(merge, options) true end end diff --git a/spec/build_tests_spec.rb b/spec/build_tests_spec.rb index e487715..9f9e49a 100644 --- a/spec/build_tests_spec.rb +++ b/spec/build_tests_spec.rb @@ -1940,6 +1940,17 @@ EOF end end + it "respects use flag" do + test_dir "configure" + result = run_rscons(args: %w[-f check_c_compiler_use.rb -v]) + expect(result.stderr).to eq "" + expect(result.status).to eq 0 + expect(result.stdout).to match %r{\bgcc .*/t1/} + expect(result.stdout).to_not match %r{\bclang .*/t1/} + expect(result.stdout).to match %r{\bclang .*/t2/} + expect(result.stdout).to_not match %r{\bgcc .*/t2/} + end + it "successfully tests a compiler with an unknown name" do test_dir "configure" create_exe "mycompiler", %[exec gcc "$@"] @@ -1983,6 +1994,17 @@ EOF end end + it "respects use flag" do + test_dir "configure" + result = run_rscons(args: %w[-f check_cxx_compiler_use.rb -v]) + expect(result.stderr).to eq "" + expect(result.status).to eq 0 + expect(result.stdout).to match %r{\bg\+\+ .*/t1/} + expect(result.stdout).to_not match %r{\bclang\+\+ .*/t1/} + expect(result.stdout).to match %r{\bclang\+\+ .*/t2/} + expect(result.stdout).to_not match %r{\bg\+\+ .*/t2/} + end + it "successfully tests a compiler with an unknown name" do test_dir "configure" create_exe "mycompiler", %[exec clang++ "$@"] @@ -2028,6 +2050,17 @@ EOF end end + it "respects use flag" do + test_dir "configure" + result = run_rscons(args: %w[-f check_d_compiler_use.rb -v]) + expect(result.stderr).to eq "" + expect(result.status).to eq 0 + expect(result.stdout).to match %r{\bgdc .*/t1/} + expect(result.stdout).to_not match %r{\bldc2 .*/t1/} + expect(result.stdout).to match %r{\bldc2 .*/t2/} + expect(result.stdout).to_not match %r{\bgdc .*/t2/} + end + unless RUBY_PLATFORM =~ /mingw|msys/ it "successfully tests a compiler with an unknown name that uses gdc-compatible options" do test_dir "configure"