From 1e5f1043d5efd9e20b69bee3e44e63eb8c8e36f1 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Wed, 26 Jan 2022 19:43:01 -0500 Subject: [PATCH] Update build step accounting to only count within one environment process run --- lib/rscons/application.rb | 20 -------------------- lib/rscons/environment.rb | 28 ++++++++++++++++------------ spec/build_tests_spec.rb | 22 +++++++++++----------- 3 files changed, 27 insertions(+), 43 deletions(-) diff --git a/lib/rscons/application.rb b/lib/rscons/application.rb index 5f13658..ba6e959 100644 --- a/lib/rscons/application.rb +++ b/lib/rscons/application.rb @@ -31,7 +31,6 @@ module Rscons @build_dir = ENV["RSCONS_BUILD_DIR"] || "build" ENV.delete("RSCONS_BUILD_DIR") @n_threads = Util.determine_n_threads - @build_step = 0 end # Run the application. @@ -71,25 +70,6 @@ module Rscons end end - # Get the next build step number. - # - # This is used internally by the {Environment} class. - # - # @api private - def get_next_build_step - @build_step += 1 - end - - # Get the total number of build steps. - # - # @return [Integer] - # The total number of build steps. - def get_total_build_steps - Environment.environments.reduce(@build_step) do |result, env| - result + env.build_steps_remaining - end - end - # Remove all generated files. # # @api private diff --git a/lib/rscons/environment.rb b/lib/rscons/environment.rb index 3c1dcb4..aba5988 100644 --- a/lib/rscons/environment.rb +++ b/lib/rscons/environment.rb @@ -285,6 +285,10 @@ module Rscons @process_commands_waiting_to_run = [] @process_builder_waits = {} @process_builders_to_run = [] + @build_step = 0 + @build_steps = @builder_sets.reduce(0) do |result, builder_set| + result + builder_set.build_steps_remaining + end begin while @builder_sets.size > 0 or @threads.size > 0 or @process_commands_waiting_to_run.size > 0 process_step @@ -535,7 +539,7 @@ module Rscons message = short_description if short_description end if message - total_build_steps = Rscons.application.get_total_build_steps.to_s + total_build_steps = @build_steps.to_s this_build_step = sprintf("%#{total_build_steps.size}d", builder.build_step) progress = "[#{this_build_step}/#{total_build_steps}]" Ansi.write($stdout, *Util.colorize_markup("#{progress} #{message}"), "\n") @@ -560,16 +564,6 @@ module Rscons @builder_sets << build_builder_set end - # Get the number of build steps remaining. - # - # @return [Integer] - # The number of build steps remaining. - def build_steps_remaining - @builder_sets.reduce(0) do |result, builder_set| - result + builder_set.build_steps_remaining - end - end - private # Build a BuilderSet. @@ -580,6 +574,16 @@ module Rscons BuilderSet.new(@registered_build_dependencies, @side_effects) end + # Get the next build step number. + # + # @api private + # + # @return [Integer] + # Next build step number. + def get_next_build_step + @build_step += 1 + end + # Run a builder and process its return value. # # @param builder [Builder] @@ -587,7 +591,7 @@ module Rscons # # @return [void] def run_builder(builder) - builder.build_step ||= Rscons.application.get_next_build_step + builder.build_step ||= get_next_build_step case result = builder.run({}) when Array result.each do |waititem| diff --git a/spec/build_tests_spec.rb b/spec/build_tests_spec.rb index 30a51e5..8b61993 100644 --- a/spec/build_tests_spec.rb +++ b/spec/build_tests_spec.rb @@ -2641,7 +2641,7 @@ EOF ]) end - it "does include install targets in build progress when doing an install" do + it "counts install task targets separately from build task targets" do test_dir "typical" Dir.mktmpdir do |prefix| @@ -2651,25 +2651,25 @@ EOF result = run_rscons(args: %w[-f install.rb install]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [ - %r{\[1/9\] Compiling}, - %r{\[2/9\] Compiling}, - %r{\[\d/9\] Install}, + %r{\[1/3\] Compiling}, + %r{\[2/3\] Compiling}, + %r{\[\d/6\] Install}, ]) end end - it "includes build steps from all environments when showing build progress" do + it "separates build steps from each environment when showing build progress" do test_dir "typical" result = run_rscons(args: %w[-f multiple_environments.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [ - %r{\[1/6\] Compiling}, - %r{\[2/6\] Compiling}, - %r{\[3/6\] Linking}, - %r{\[4/6\] Compiling}, - %r{\[5/6\] Compiling}, - %r{\[6/6\] Linking}, + %r{\[1/3\] Compiling}, + %r{\[2/3\] Compiling}, + %r{\[3/3\] Linking}, + %r{\[1/3\] Compiling}, + %r{\[2/3\] Compiling}, + %r{\[3/3\] Linking}, ]) end end