From c9de4f37e6832cec37adcdd3d02a433ad0c9376a Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 6 Nov 2018 15:42:10 -0500 Subject: [PATCH] allow configure to fail; application should return error code from operation --- lib/rscons/application.rb | 19 ++++++++++++++++--- lib/rscons/configure_op.rb | 12 ++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/lib/rscons/application.rb b/lib/rscons/application.rb index bdb97e5..2cb9786 100644 --- a/lib/rscons/application.rb +++ b/lib/rscons/application.rb @@ -43,12 +43,17 @@ module Rscons def run(operation, script) @script = script case operation + when "build" + # TODO + 0 when "clean" clean when "configure" configure + else + $stderr.puts "Unknown operation: #{operation}" + 1 end - 0 end private @@ -70,16 +75,24 @@ module Rscons end end cache.clear + 0 end # Configure the project. # # @return [void] def configure + rv = 0 co = ConfigureOp.new("#{@build_dir}/configure") - if ccc = @script.check_c_compiler - co.check_c_compiler(ccc) + begin + if ccc = @script.check_c_compiler + co.check_c_compiler(ccc) + end + rescue ConfigureOp::ConfigFailure + rv = 1 end + co.close + rv end # Determine the number of threads to use by default. diff --git a/lib/rscons/configure_op.rb b/lib/rscons/configure_op.rb index 89d36a7..3c13b74 100644 --- a/lib/rscons/configure_op.rb +++ b/lib/rscons/configure_op.rb @@ -4,6 +4,9 @@ module Rscons # Class to manage a configure operation. class ConfigureOp + # Exception raised when a configuration error occurs. + class ConfigFailure < Exception; end + # Create a ConfigureOp. # # @param work_dir [String] @@ -11,6 +14,15 @@ module Rscons def initialize(work_dir) @work_dir = work_dir FileUtils.mkdir_p(@work_dir) + @log_fh = File.open("#{@work_dir}/config.log", "wb") + end + + # Close the log file handle. + # + # @return [void] + def close + @log_fh.close + @log_fh = nil end # Check for a working C compiler.