verbose mode should list operations and their execution times - close #103

This commit is contained in:
Josh Holtrop 2019-04-27 22:29:18 -04:00
parent 785e8e18fd
commit 59a3cb4e10
4 changed files with 86 additions and 27 deletions

View File

@ -47,40 +47,54 @@ module Rscons
# The script. # The script.
# @param operation_options [Hash] # @param operation_options [Hash]
# Option values from the CLI for the operation. # Option values from the CLI for the operation.
# @param options [Hash]
# Optional parameters.
# @option sub_op [Boolean]
# Whether this operation is not the top-level operation.
# #
# @return [Integer] # @return [Integer]
# Process exit code (0 on success). # Process exit code (0 on success).
def run(operation, script, operation_options) def run(operation, script, operation_options, options = {})
@operations << operation @start_time = Time.new
@script = script @script = script
case operation @operations << operation
when "build" puts "Starting '#{operation}' at #{Time.new}" if verbose
unless Cache.instance["configuration_data"]["configured"] rv =
if @script.autoconf case operation
rv = run("configure", script, operation_options) when "build"
if rv != 0 rv = 0
return rv unless Cache.instance["configuration_data"]["configured"]
end rv =
else if @script.autoconf
$stderr.puts "Project must be configured first, and autoconf is disabled" run("configure", script, operation_options, sub_op: false)
return 1 else
$stderr.puts "Project must be configured first, and autoconf is disabled"
1
end
end end
if rv == 0
build(operation_options)
end
when "clean"
clean
when "configure"
configure(operation_options)
when "distclean"
distclean
when "install"
run("build", script, operation_options, sub_op: false)
when "uninstall"
uninstall
else
$stderr.puts "Unknown operation: #{operation}"
1
end end
build(operation_options) if verbose and options[:sub_op].nil?
when "clean" time = Time.new
clean elapsed = time - @start_time
when "configure" puts "'#{operation}' complete at #{time} (#{Util.format_elapsed_time(elapsed)})"
configure(operation_options)
when "distclean"
distclean
when "install"
run("build", script, operation_options)
when "uninstall"
uninstall
else
$stderr.puts "Unknown operation: #{operation}"
1
end end
rv
end end
private private

View File

@ -95,6 +95,27 @@ module Rscons
end end
end end
# Format an elapsed time in human-readable format.
#
# @return [String]
# Elapsed time in human-readable format.
def format_elapsed_time(elapsed)
hours = (elapsed / (60 * 60)).to_i
elapsed -= hours * 60 * 60
minutes = (elapsed / 60).to_i
elapsed -= minutes * 60
seconds = elapsed.ceil
result = ""
if hours > 0
result += "#{hours}h "
end
if hours > 0 || minutes > 0
result += "#{minutes}m "
end
result += "#{seconds}s"
result
end
# Make a relative path corresponding to a possibly absolute one. # Make a relative path corresponding to a possibly absolute one.
# #
# @param path [String] # @param path [String]

View File

@ -2089,6 +2089,16 @@ EOF
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(result.stdout).to match /gcc.*-o.*simple/ expect(result.stdout).to match /gcc.*-o.*simple/
end end
it "prints operation start time" do
test_dir("simple")
result = run_rscons(rscons_args: %w[-v])
expect(result.stderr).to eq ""
expect(result.stdout).to match /Starting 'configure' at/
expect(result.stdout).to match /Starting 'build' at/
expect(result.stdout).to match /'build' complete at/
expect(result.stdout).to_not match /'configure' complete at/
end
end end
context "direct mode" do context "direct mode" do

View File

@ -151,6 +151,20 @@ EOF
end end
end end
describe ".format_elapsed_time" do
it "includes minutes when hours is nonzero and minutes is zero" do
expect(Util.format_elapsed_time(60 * 60 + 4)).to eq "1h 0m 4s"
end
it "only includes minutes and seconds when hours is zero and minutes is nonzero" do
expect(Util.format_elapsed_time(3 * 60 + 33)).to eq "3m 33s"
end
it "only includes seconds when hours and minutes are zero" do
expect(Util.format_elapsed_time(7.84)).to eq "8s"
end
end
describe ".make_relative_path" do describe ".make_relative_path" do
context "when passed a relative path" do context "when passed a relative path" do
it "returns the path itself" do it "returns the path itself" do