lib/rscons/environment.rb in rscons-1.11.1 vs lib/rscons/environment.rb in rscons-1.12.0

- old
+ new

@@ -116,10 +116,11 @@ end @build_hooks[:post].each do |build_hook_block| env.add_post_build_hook(&build_hook_block) end end + env.instance_variable_set(:@n_threads, @n_threads) if block_given? yield env env.process end @@ -300,17 +301,23 @@ # called after the block returns. # # @return [void] def process cache = Cache.instance + failure = nil begin while @job_set.size > 0 or @threaded_commands.size > 0 - targets_still_building = @threaded_commands.map do |tc| - tc.build_operation[:target] + if failure + @job_set.clear! + job = nil + else + targets_still_building = @threaded_commands.map do |tc| + tc.build_operation[:target] + end + job = @job_set.get_next_job_to_run(targets_still_building) end - job = @job_set.get_next_job_to_run(targets_still_building) # TODO: have Cache determine when checksums may be invalid based on # file size and/or timestamp. cache.clear_checksum_cache! @@ -321,11 +328,13 @@ cache, job[:vars], allow_delayed_execution: true, setup_info: job[:setup_info]) unless result - raise BuildError.new("Failed to build #{job[:target]}") + failure = "Failed to build #{job[:target]}" + Ansi.write($stderr, :red, failure, :reset, "\n") + next end end completed_tcs = Set.new # First do a non-blocking wait to pick up any threads that have @@ -347,20 +356,25 @@ @build_hooks[:post].each do |build_hook_block| build_hook_block.call(tc.build_operation) end else unless @echo == :command - $stdout.puts "Failed command was: #{command_to_s(tc.command)}" + print_failed_command(tc.command) end - raise BuildError.new("Failed to build #{tc.build_operation[:target]}") + failure = "Failed to build #{tc.build_operation[:target]}" + Ansi.write($stderr, :red, failure, :reset, "\n") + break end end end ensure cache.write end + if failure + raise BuildError.new(failure) + end end # Clear all targets registered for the Environment. # # @return [void] @@ -396,20 +410,16 @@ # - :env - environment Hash to pass to Kernel#system. # - :options - options Hash to pass to Kernel#system. # # @return [true,false,nil] Return value from Kernel.system(). def execute(short_desc, command, options = {}) - if @echo == :command - puts command_to_s(command) - elsif @echo == :short - puts short_desc - end + print_builder_run_message(short_desc, command) env_args = options[:env] ? [options[:env]] : [] options_args = options[:options] ? [options[:options]] : [] system(*env_args, *Rscons.command_executer, *command, *options_args).tap do |result| unless result or @echo == :command - $stdout.puts "Failed command was: #{command_to_s(command)}" + print_failed_command(command) end end end # Define a build target. @@ -449,10 +459,11 @@ def depends(target, *user_deps) target = expand_varref(target.to_s) user_deps = user_deps.map {|ud| expand_varref(ud)} @user_deps[target] ||= [] @user_deps[target] = (@user_deps[target] + user_deps).uniq + build_after(target, user_deps) end # Manually record the given target(s) as needing to be built after the # given prerequisite(s). # @@ -640,11 +651,11 @@ rv = finalize_builder(tc) if rv call_build_hooks[:post] else unless @echo == :command - $stdout.puts "Failed command was: #{command_to_s(tc.command)}" + print_failed_command(tc.command) end end end else call_build_hooks[:post] if rv @@ -827,11 +838,11 @@ # Print the Environment's construction variables for debugging. def dump varset_hash = @varset.to_h varset_hash.keys.sort_by(&:to_s).each do |var| var_str = var.is_a?(Symbol) ? var.inspect : var - puts "#{var_str} => #{varset_hash[var].inspect}" + Ansi.write($stdout, :cyan, var_str, :reset, " => #{varset_hash[var].inspect}\n") end end # Get the number of threads to use for parallelized builds in this # Environment. @@ -840,10 +851,38 @@ # Number of threads to use for parallelized builds in this Environment. def n_threads @n_threads || Rscons.n_threads end + # Print the builder run message, depending on the Environment's echo mode. + # + # @param short_description [String] + # Builder short description, printed if the echo mode is :short. + # @param command [Array<String>] + # Builder command, printed if the echo mode is :command. + # + # @return [void] + def print_builder_run_message(short_description, command) + case @echo + when :command + message = command_to_s(command) if command + when :short + message = short_description if short_description + end + Ansi.write($stdout, :cyan, message, :reset, "\n") if message + end + + # Print a failed command. + # + # @param command [Array<String>] + # Builder command. + # + # @return [void] + def print_failed_command(command) + Ansi.write($stdout, :red, "Failed command was: #{command_to_s(command)}", :reset, "\n") + end + private # Add a build target. # # @param target [String] Build target file name. @@ -872,16 +911,10 @@ # @param tc [ThreadedCommand] # The ThreadedCommand to start. # # @return [void] def start_threaded_command(tc) - if @echo == :command - puts command_to_s(tc.command) - elsif @echo == :short - if tc.short_description - puts tc.short_description - end - end + print_builder_run_message(tc.short_description, tc.command) env_args = tc.system_env ? [tc.system_env] : [] options_args = tc.system_options ? [tc.system_options] : [] system_args = [*env_args, *Rscons.command_executer, *tc.command, *options_args]