From 7eeb6312ba7bac832cdc1e62beee8dc9b02fa420 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 6 Nov 2018 22:16:38 -0500 Subject: [PATCH] check_c_compiler: print output; add a integration test --- .../configure/check_c_compiler_find_first.rb | 3 ++ lib/rscons/configure_op.rb | 31 +++++++++++++++---- spec/build_tests_spec.rb | 10 ++++++ 3 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 build_tests/configure/check_c_compiler_find_first.rb diff --git a/build_tests/configure/check_c_compiler_find_first.rb b/build_tests/configure/check_c_compiler_find_first.rb new file mode 100644 index 0000000..16360f4 --- /dev/null +++ b/build_tests/configure/check_c_compiler_find_first.rb @@ -0,0 +1,3 @@ +configure do + check_c_compiler "gcc", "clang" +end diff --git a/lib/rscons/configure_op.rb b/lib/rscons/configure_op.rb index f82896f..8643421 100644 --- a/lib/rscons/configure_op.rb +++ b/lib/rscons/configure_op.rb @@ -33,6 +33,7 @@ module Rscons # # @return [void] def check_c_compiler(ccc) + $stdout.write("Checking for C compiler... ") if ccc.empty? # Default C compiler search array. ccc = %w[gcc clang] @@ -40,6 +41,12 @@ module Rscons cc = ccc.find do |cc| test_c_compiler(cc) end + if cc + Ansi.write($stdout, :green, cc, "\n") + else + Ansi.write($stdout, :red, "not found\n") + raise ConfigureFailure.new + end end private @@ -67,13 +74,25 @@ module Rscons when "clang" command = %W[clang -o #{@work_dir}/cfgtest.exe #{@work_dir}/cfgtest.c] else - raise ConfigureFailure.new("Unknown C compiler (#{cc})") + $stderr.puts "Unknown C compiler (#{cc})" + 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 + @log_fh.puts("Command: #{command.join(" ")}") + stdout, stderr, status = Open3.capture3(*command) + @log_fh.puts("Exit status: #{status.to_i}") + @log_fh.write(stdout) + @log_fh.write(stderr) + [stdout, stderr, status] + rescue Errno::ENOENT + ["", "", 127] end - @log_fh.puts("Command: #{command.join(" ")}") - stdout, stderr, status = Open3.capture3(*command) - @log_fh.write(stdout) - @log_fh.write(stderr) - status != 0 end end diff --git a/spec/build_tests_spec.rb b/spec/build_tests_spec.rb index 60752e7..2e90cd2 100644 --- a/spec/build_tests_spec.rb +++ b/spec/build_tests_spec.rb @@ -1489,6 +1489,16 @@ EOF expect(result.stderr).to match /NoMethodError/ expect(result.status).to_not eq 0 end + + context "check_c_compiler" do + it "finds the first listed C compiler" do + test_dir "configure" + result = run_rscons(rsconsfile: "check_c_compiler_find_first.rb", op: "configure") + expect(result.stderr).to eq "" + expect(result.status).to eq 0 + expect(result.stdout).to match /Checking for C compiler\.\.\. gcc/ + end + end end end