Update build step accounting to only count within one environment process run

This commit is contained in:
Josh Holtrop 2022-01-26 19:43:01 -05:00
parent 9d14cc7eb0
commit 1e5f1043d5
3 changed files with 27 additions and 43 deletions

View File

@ -31,7 +31,6 @@ module Rscons
@build_dir = ENV["RSCONS_BUILD_DIR"] || "build" @build_dir = ENV["RSCONS_BUILD_DIR"] || "build"
ENV.delete("RSCONS_BUILD_DIR") ENV.delete("RSCONS_BUILD_DIR")
@n_threads = Util.determine_n_threads @n_threads = Util.determine_n_threads
@build_step = 0
end end
# Run the application. # Run the application.
@ -71,25 +70,6 @@ module Rscons
end end
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. # Remove all generated files.
# #
# @api private # @api private

View File

@ -285,6 +285,10 @@ module Rscons
@process_commands_waiting_to_run = [] @process_commands_waiting_to_run = []
@process_builder_waits = {} @process_builder_waits = {}
@process_builders_to_run = [] @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 begin
while @builder_sets.size > 0 or @threads.size > 0 or @process_commands_waiting_to_run.size > 0 while @builder_sets.size > 0 or @threads.size > 0 or @process_commands_waiting_to_run.size > 0
process_step process_step
@ -535,7 +539,7 @@ module Rscons
message = short_description if short_description message = short_description if short_description
end end
if message 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) this_build_step = sprintf("%#{total_build_steps.size}d", builder.build_step)
progress = "[#{this_build_step}/#{total_build_steps}]" progress = "[#{this_build_step}/#{total_build_steps}]"
Ansi.write($stdout, *Util.colorize_markup("#{progress} #{message}"), "\n") Ansi.write($stdout, *Util.colorize_markup("#{progress} #{message}"), "\n")
@ -560,16 +564,6 @@ module Rscons
@builder_sets << build_builder_set @builder_sets << build_builder_set
end 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 private
# Build a BuilderSet. # Build a BuilderSet.
@ -580,6 +574,16 @@ module Rscons
BuilderSet.new(@registered_build_dependencies, @side_effects) BuilderSet.new(@registered_build_dependencies, @side_effects)
end 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. # Run a builder and process its return value.
# #
# @param builder [Builder] # @param builder [Builder]
@ -587,7 +591,7 @@ module Rscons
# #
# @return [void] # @return [void]
def run_builder(builder) def run_builder(builder)
builder.build_step ||= Rscons.application.get_next_build_step builder.build_step ||= get_next_build_step
case result = builder.run({}) case result = builder.run({})
when Array when Array
result.each do |waititem| result.each do |waititem|

View File

@ -2641,7 +2641,7 @@ EOF
]) ])
end 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" test_dir "typical"
Dir.mktmpdir do |prefix| Dir.mktmpdir do |prefix|
@ -2651,25 +2651,25 @@ EOF
result = run_rscons(args: %w[-f install.rb install]) result = run_rscons(args: %w[-f install.rb install])
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
verify_lines(lines(result.stdout), [ verify_lines(lines(result.stdout), [
%r{\[1/9\] Compiling}, %r{\[1/3\] Compiling},
%r{\[2/9\] Compiling}, %r{\[2/3\] Compiling},
%r{\[\d/9\] Install}, %r{\[\d/6\] Install},
]) ])
end end
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" test_dir "typical"
result = run_rscons(args: %w[-f multiple_environments.rb]) result = run_rscons(args: %w[-f multiple_environments.rb])
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
verify_lines(lines(result.stdout), [ verify_lines(lines(result.stdout), [
%r{\[1/6\] Compiling}, %r{\[1/3\] Compiling},
%r{\[2/6\] Compiling}, %r{\[2/3\] Compiling},
%r{\[3/6\] Linking}, %r{\[3/3\] Linking},
%r{\[4/6\] Compiling}, %r{\[1/3\] Compiling},
%r{\[5/6\] Compiling}, %r{\[2/3\] Compiling},
%r{\[6/6\] Linking}, %r{\[3/3\] Linking},
]) ])
end end
end end