show build progress - close #98
This commit is contained in:
1 parent
59a3cb4e10
commit
a4fead7dc6
8 files changed
+395
-219
No files matched your search
@@ -26,6 +26,7 @@ module Rscons
|
||||
@n_threads = Util.determine_n_threads
|
||||
@vars = VarSet.new
|
||||
@operations = Set.new
|
||||
@build_step = 0
|
||||
end
|
||||
|
||||
# Check whether a requested operation is active.
|
||||
@@ -97,6 +98,25 @@ module Rscons
|
||||
rv
|
||||
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
|
||||
|
||||
private
|
||||
|
||||
# Build the project.
|
||||
|
||||
@@ -47,6 +47,10 @@ module Rscons
|
||||
# Construction variables used to perform the build operation.
|
||||
attr_accessor :vars
|
||||
|
||||
# @return [Integer]
|
||||
# Build step.
|
||||
attr_accessor :build_step
|
||||
|
||||
# Create an instance of the Builder to build a target.
|
||||
#
|
||||
# @param options [Hash]
|
||||
@@ -78,6 +82,14 @@ module Rscons
|
||||
self.class.name
|
||||
end
|
||||
|
||||
# Return whether the builder is a no-op.
|
||||
#
|
||||
# @return [Boolean]
|
||||
# Whether the builder is a no-op.
|
||||
def nop?
|
||||
false
|
||||
end
|
||||
|
||||
# Manually record a given build target as depending on the specified files.
|
||||
#
|
||||
# @param user_deps [Array<String>]
|
||||
|
||||
@@ -31,6 +31,16 @@ module Rscons
|
||||
self[builder.target] << builder
|
||||
end
|
||||
|
||||
# Return the number of remaining build steps.
|
||||
#
|
||||
# @return [Integer]
|
||||
# The number of remaining build steps.
|
||||
def build_steps_remaining
|
||||
self.reduce(0) do |result, (target, builders)|
|
||||
result + builders.select {|b| not b.nop?}.size
|
||||
end
|
||||
end
|
||||
|
||||
# Get the next builder that is ready to run from the BuilderSet.
|
||||
#
|
||||
# This method will remove the builder from the BuilderSet.
|
||||
|
||||
@@ -5,10 +5,26 @@ module Rscons
|
||||
# The Copy builder copies files/directories to new locations.
|
||||
class Copy < Builder
|
||||
|
||||
# Construct builder.
|
||||
def initialize(*args)
|
||||
super
|
||||
@install_builder = self.class.name == "Install"
|
||||
@nop = @install_builder && !Rscons.application.operation("install")
|
||||
end
|
||||
|
||||
# Return whether the builder is a no-op.
|
||||
#
|
||||
# @return [Boolean]
|
||||
# Whether the builder is a no-op.
|
||||
def nop?
|
||||
@nop
|
||||
end
|
||||
|
||||
# Run the builder to produce a build target.
|
||||
def run(options)
|
||||
install_builder = self.class.name == "Install"
|
||||
if (not install_builder) or Rscons.application.operation("install")
|
||||
if @nop
|
||||
true
|
||||
else
|
||||
target_is_dir = (@sources.length > 1) ||
|
||||
Dir.exists?(@sources.first) ||
|
||||
Dir.exists?(@target)
|
||||
@@ -40,14 +56,12 @@ module Rscons
|
||||
print_run_message(message, nil)
|
||||
printed_message = true
|
||||
end
|
||||
@cache.mkdir_p(File.dirname(dest), install: install_builder)
|
||||
@cache.mkdir_p(File.dirname(dest), install: @install_builder)
|
||||
FileUtils.cp(src, dest, :preserve => true)
|
||||
end
|
||||
@cache.register_build(dest, :Copy, [src], @env, install: install_builder)
|
||||
@cache.register_build(dest, :Copy, [src], @env, install: @install_builder)
|
||||
end
|
||||
(target_is_dir ? Dir.exists?(@target) : File.exists?(@target)) ? true : false
|
||||
else
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -4,10 +4,26 @@ module Rscons
|
||||
# The Directory builder creates a directory.
|
||||
class Directory < Builder
|
||||
|
||||
# Construct builder.
|
||||
def initialize(*args)
|
||||
super
|
||||
@install_builder = self.class.name == "InstallDirectory"
|
||||
@nop = @install_builder && !Rscons.application.operation("install")
|
||||
end
|
||||
|
||||
# Return whether the builder is a no-op.
|
||||
#
|
||||
# @return [Boolean]
|
||||
# Whether the builder is a no-op.
|
||||
def nop?
|
||||
@nop
|
||||
end
|
||||
|
||||
# Run the builder to produce a build target.
|
||||
def run(options)
|
||||
install_builder = self.class.name == "InstallDirectory"
|
||||
if (not install_builder) or Rscons.application.operation("install")
|
||||
if @nop
|
||||
true
|
||||
else
|
||||
if File.directory?(@target)
|
||||
true
|
||||
elsif File.exists?(@target)
|
||||
@@ -15,11 +31,9 @@ module Rscons
|
||||
false
|
||||
else
|
||||
print_run_message("Creating directory => #{@target}", nil)
|
||||
@cache.mkdir_p(@target, install: install_builder)
|
||||
@cache.mkdir_p(@target, install: @install_builder)
|
||||
true
|
||||
end
|
||||
else
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -526,7 +526,10 @@ module Rscons
|
||||
when :short
|
||||
message = short_description if short_description
|
||||
end
|
||||
Ansi.write($stdout, :cyan, message, :reset, "\n") if message
|
||||
total_build_steps = Rscons.application.get_total_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, :cyan, "#{progress} #{message}", :reset, "\n") if message
|
||||
end
|
||||
|
||||
# Get the Builder for a target.
|
||||
@@ -547,6 +550,16 @@ 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.
|
||||
@@ -567,6 +580,9 @@ module Rscons
|
||||
# TODO: have Cache determine when checksums may be invalid based on
|
||||
# file size and/or timestamp.
|
||||
Cache.instance.clear_checksum_cache!
|
||||
unless builder.nop?
|
||||
builder.build_step ||= Rscons.application.get_next_build_step
|
||||
end
|
||||
case result = builder.run({})
|
||||
when Array
|
||||
result.each do |waititem|
|
||||
|
||||
Reference in new issue
Block a user