From c48526fd97af261a54183e3aa9418d2ebf3c6323 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Thu, 11 Aug 2022 14:41:29 -0400 Subject: [PATCH] Improve configuration error messages - close #162 --- lib/rscons/configure_op.rb | 19 ++++++++++++++----- spec/build_tests_spec.rb | 20 ++++++++++++-------- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/lib/rscons/configure_op.rb b/lib/rscons/configure_op.rb index 9395747..9d3e7b4 100644 --- a/lib/rscons/configure_op.rb +++ b/lib/rscons/configure_op.rb @@ -12,7 +12,8 @@ module Rscons def initialize(script) @work_dir = "#{Rscons.application.build_dir}/_configure" FileUtils.mkdir_p(@work_dir) - @log_fh = File.open("#{@work_dir}/config.log", "wb") + @log_file_name = "#{@work_dir}/config.log" + @log_fh = File.open(@log_file_name, "wb") cache = Cache.instance cache["failed_commands"] = [] cache["configuration_data"] = {} @@ -64,7 +65,9 @@ module Rscons cc = ccc.find do |cc| test_c_compiler(cc, options) end - complete(cc ? 0 : 1, options.merge(success_message: cc)) + complete(cc ? 0 : 1, options.merge( + success_message: cc, + fail_message: "not found (checked #{ccc.join(", ")})")) end # Check for a working C++ compiler. @@ -86,7 +89,9 @@ module Rscons cc = ccc.find do |cc| test_cxx_compiler(cc, options) end - complete(cc ? 0 : 1, options.merge(success_message: cc)) + complete(cc ? 0 : 1, options.merge( + success_message: cc, + fail_message: "not found (checked #{ccc.join(", ")})")) end # Check for a working D compiler. @@ -108,7 +113,9 @@ module Rscons dc = cdc.find do |dc| test_d_compiler(dc, options) end - complete(dc ? 0 : 1, options.merge(success_message: dc)) + complete(dc ? 0 : 1, options.merge( + success_message: dc, + fail_message: "not found (checked #{cdc.join(", ")})")) end # Check for a package or configure program output. @@ -375,6 +382,8 @@ module Rscons # A define to set (in CPPDEFINES) if the requested item is found. # @option options [String] :success_message # Message to print on success (default "found"). + # @option options [String] :fail_message + # Message to print on failure (default "not found"). def complete(status, options) success_message = options[:success_message] || "found" fail_message = options[:fail_message] || "not found" @@ -398,7 +407,7 @@ module Rscons options[:on_fail].call end if should_fail - raise RsconsError.new("Configuration failed") + raise RsconsError.new("Configuration failed; log file written to #{@log_file_name}") end end end diff --git a/spec/build_tests_spec.rb b/spec/build_tests_spec.rb index 8d728f3..3896722 100644 --- a/spec/build_tests_spec.rb +++ b/spec/build_tests_spec.rb @@ -43,7 +43,11 @@ describe Rscons do Dir.chdir(@owd) if example.exception @statics[:keep_test_run_dir] = true - puts "Leaving #{@build_test_run_dir} for inspection due to test failure" + message = "Leaving #{@build_test_run_dir} for inspection due to test failure" + if example.exception.backtrace.find {|e| e =~ %r{^(.*/#{File.basename(__FILE__)}:\d+)}} + message += " (#{$1})" + end + puts "\n#{message}" else rm_rf(@build_test_run_dir) end @@ -1933,9 +1937,9 @@ EOF create_exe "gcc", "exit 1" create_exe "clang", "exit 1" result = run_rscons(args: %W[-f #{rsconscript} configure]) - expect(result.stderr).to match /Configuration failed/ + expect(result.stderr).to match %r{Configuration failed; log file written to build/_configure/config.log} expect(result.status).to_not eq 0 - expect(result.stdout).to match /Checking for C compiler\.\.\. not found/ + expect(result.stdout).to match /Checking for C compiler\.\.\. not found \(checked gcc, clang\)/ end end end @@ -1987,9 +1991,9 @@ EOF create_exe "g++", "exit 1" create_exe "clang++", "exit 1" result = run_rscons(args: %W[-f #{rsconscript} configure]) - expect(result.stderr).to match /Configuration failed/ + expect(result.stderr).to match %r{Configuration failed; log file written to build/_configure/config.log} expect(result.status).to_not eq 0 - expect(result.stdout).to match /Checking for C\+\+ compiler\.\.\. not found/ + expect(result.stdout).to match /Checking for C\+\+ compiler\.\.\. not found \(checked g\+\+, clang\+\+\)/ end end end @@ -2043,9 +2047,9 @@ EOF create_exe "gdc", "exit 1" create_exe "ldc2", "exit 1" result = run_rscons(args: %W[-f #{rsconscript} configure]) - expect(result.stderr).to match /Configuration failed/ + expect(result.stderr).to match %r{Configuration failed; log file written to build/_configure/config.log} expect(result.status).to_not eq 0 - expect(result.stdout).to match /Checking for D compiler\.\.\. not found/ + expect(result.stdout).to match /Checking for D compiler\.\.\. not found \(checked gdc, ldc2\)/ end end end @@ -2514,7 +2518,7 @@ EOF expect(result.stdout).to match /Checking for C compiler\.\.\. not found/ expect(result.status).to_not eq 0 expect(result.stderr).to_not match /from\s/ - expect(lines(result.stderr).last).to eq "Configuration failed" + expect(lines(result.stderr).last).to match /Configuration failed/ end it "does not rebuild after building with auto-configuration" do