update output coloring with highlighting for target and source filenames - close #104

This commit is contained in:
Josh Holtrop 2019-04-30 21:05:44 -04:00
parent a4fead7dc6
commit cd1c54bf0d
14 changed files with 83 additions and 49 deletions

View File

@ -171,7 +171,9 @@ module Rscons
cache = Cache.instance
build_dir = cache["configuration_data"]["build_dir"]
clean
FileUtils.rm_rf(build_dir)
if build_dir
FileUtils.rm_rf(build_dir)
end
cache.clear
0
end

View File

@ -26,7 +26,7 @@ module Rscons
raise "Unknown source file #{@sources.first.inspect} for CFile builder"
end
command = @env.build_command("${#{cmd}_CMD}", @vars)
standard_command("#{message} from #{Util.short_format_paths(@sources)} => #{@target}", command)
standard_command("#{message} from <source>#{Util.short_format_paths(@sources)}<reset> => <target>#{@target}<reset>", command)
end
end

View File

@ -23,7 +23,7 @@ module Rscons
if @vars["CMD_STDOUT"]
options[:stdout] = @env.expand_varref("${CMD_STDOUT}", @vars)
end
standard_command("#{cmd_desc} => #{@target}", command, options)
standard_command("#{cmd_desc} <target>#{@target}<reset>", command, options)
end
end

View File

@ -52,7 +52,7 @@ module Rscons
# Check the cache and copy if necessary
unless @cache.up_to_date?(dest, :Copy, [src], @env)
unless printed_message
message = "#{name} #{Util.short_format_paths(@sources)} => #{@target}"
message = "#{name} <source>#{Util.short_format_paths(@sources)}<reset> => <target>#{@target}<reset>"
print_run_message(message, nil)
printed_message = true
end

View File

@ -30,7 +30,7 @@ module Rscons
Ansi.write($stderr, :red, "Error: `#{@target}' already exists and is not a directory", :reset, "\n")
false
else
print_run_message("Creating directory => #{@target}", nil)
print_run_message("Creating directory <target>#{@target}<reset>", nil)
@cache.mkdir_p(@target, install: @install_builder)
true
end

View File

@ -10,7 +10,7 @@ module Rscons
else
@vars["_SOURCES"] = @sources
command = @env.build_command("${DISASM_CMD}", @vars)
standard_command("Disassembling #{Util.short_format_paths(@sources)} => #{target}", command, stdout: @target)
standard_command("Disassembling <source>#{Util.short_format_paths(@sources)}<reset> => <target>#{target}<reset>", command, stdout: @target)
end
end

View File

@ -20,7 +20,7 @@ module Rscons
@vars["_TARGET"] = @target
@vars["_SOURCES"] = @objects
command = @env.build_command("${ARCMD}", @vars)
standard_command("Building static library archive => #{@target}", command, sources: @objects)
standard_command("Building static library archive <target>#{@target}<reset>", command, sources: @objects)
end
end

View File

@ -83,9 +83,9 @@ module Rscons
command = @env.build_command(@command_template, @vars)
@env.produces(@target, @vars["_DEPFILE"])
if @vars[:direct]
message = "#{@short_description}/Linking #{Util.short_format_paths(@sources)} => #{@target}"
message = "#{@short_description}/Linking <source>#{Util.short_format_paths(@sources)}<reset> => <target>#{@target}<reset>"
else
message = "#{@short_description} #{Util.short_format_paths(@sources)}"
message = "#{@short_description} <source>#{Util.short_format_paths(@sources)}<reset>"
end
standard_command(message, command)
end

View File

@ -27,7 +27,7 @@ module Rscons
@vars["_SOURCES"] = @objects
@vars["#{ld_var}"] = ld
command = @env.build_command("${#{ld_var}CMD}", @vars)
standard_command("Linking => #{@target}", command, sources: @objects)
standard_command("Linking <target>#{@target}<reset>", command, sources: @objects)
end
end

View File

@ -26,7 +26,7 @@ module Rscons
@vars["_DEPFILE"] = Rscons.set_suffix(target, env.expand_varref("${DEPFILESUFFIX}", vars))
command = @env.build_command("${CPP_CMD}", @vars)
@env.produces(@target, @vars["_DEPFILE"])
standard_command("Preprocessing #{Util.short_format_paths(@sources)} => #{@target}", command)
standard_command("Preprocessing <source>#{Util.short_format_paths(@sources)}<reset> => <target>#{@target}<reset>", command)
end
end

View File

@ -526,10 +526,12 @@ module Rscons
when :short
message = short_description if short_description
end
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
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, *Util.colorize_markup("#{progress} #{message}"), "\n")
end
end
# Get the Builder for a target.

View File

@ -15,6 +15,30 @@ module Rscons
end
end
# Colorize a builder run message.
#
# @param message [String]
# Builder run message.
#
# @return [Array]
# Colorized message with color codes for {Ansi} module.
def colorize_markup(message)
if message =~ /^(.*?)(<[^>]+>)(.*)$/
prefix, code, suffix = $1, $2, $3
case code
when "<target>"
code = :magenta
when "<source>"
code = :cyan
when "<reset>"
code = :reset
end
[prefix, code, *colorize_markup(suffix)].delete_if {|v| v == ""}
else
[message]
end
end
# Return a string representation of a command.
#
# @param command [Array<String>]

View File

@ -216,7 +216,7 @@ EOF
expect(result.stderr).to eq ""
verify_lines(lines(result.stdout), [
%r{Compiling header.c},
%r{Linking => header.exe},
%r{Linking header.exe},
])
end
@ -245,7 +245,7 @@ EOF
expect(result.stderr).to eq ""
verify_lines(lines(result.stdout), [
%r{Compiling header.c},
%r{Linking => header.exe},
%r{Linking header.exe},
])
expect(`./header.exe`).to eq "The value is 2\n"
result = run_rscons
@ -259,7 +259,7 @@ EOF
expect(result.stderr).to eq ""
verify_lines(lines(result.stdout), [
%r{Compiling header.c},
%r{Linking => header.exe},
%r{Linking header.exe},
])
expect(`./header.exe`).to eq "The value is 2\n"
sleep 0.05
@ -398,7 +398,7 @@ EOF
expect(result.stderr).to eq ""
verify_lines(lines(result.stdout), [
%r{Compiling program.c},
%r{Linking => program.exe},
%r{Linking program.exe},
])
expect(File.exists?('inc.h')).to be_truthy
expect(`./program.exe`).to eq "The value is 5678\n"
@ -413,7 +413,7 @@ EOF
%r{CHGen inc.c},
%r{Compiling program.c},
%r{Compiling inc.c},
%r{Linking => program.exe},
%r{Linking program.exe},
])
expect(File.exists?("inc.c")).to be_truthy
expect(File.exists?("inc.h")).to be_truthy
@ -562,7 +562,7 @@ EOF
expect(result.stderr).to eq ""
verify_lines(lines(result.stdout), [
%r{Compiling simple.c},
%r{Linking => simple.exe},
%r{Linking simple.exe},
])
expect(File.exists?('build/e.1/simple.o')).to be_truthy
expect(`./simple.exe`).to eq "This is a simple C program\n"
@ -570,12 +570,12 @@ EOF
File.open("program.ld", "w") {|fh| fh.puts("2")}
result = run_rscons(rsconscript: "user_dependencies.rb")
expect(result.stderr).to eq ""
verify_lines(lines(result.stdout), [%r{Linking => simple.exe}])
verify_lines(lines(result.stdout), [%r{Linking simple.exe}])
File.unlink("program.ld")
result = run_rscons(rsconscript: "user_dependencies.rb")
expect(result.stderr).to eq ""
verify_lines(lines(result.stdout), [%r{Linking => simple.exe}])
verify_lines(lines(result.stdout), [%r{Linking simple.exe}])
result = run_rscons(rsconscript: "user_dependencies.rb")
expect(result.stderr).to eq ""
@ -634,9 +634,9 @@ EOF
#expect(result.stderr).to eq ""
slines = lines(result.stdout)
if RUBY_PLATFORM =~ /mingw/
verify_lines(slines, [%r{Linking => mine.dll}])
verify_lines(slines, [%r{Linking mine.dll}])
else
verify_lines(slines, [%r{Linking => libmine.so}])
verify_lines(slines, [%r{Linking libmine.so}])
end
end
end
@ -682,7 +682,7 @@ EOF
expect(result.stderr).to eq ""
verify_lines(lines(result.stdout), [
%r{Compiling program.c},
%r{Linking => program.exe},
%r{Linking program.exe},
])
expect(File.exists?('inc.h')).to be_truthy
expect(`./program.exe`).to eq "The value is 678\n"
@ -751,7 +751,7 @@ EOF
%r{Compiling two.c},
%r{Assembling one.ssss},
%r{Assembling two.sss},
%r{Linking => two_sources.exe},
%r{Linking two_sources.exe},
])
expect(File.exists?("two_sources.exe")).to be_truthy
expect(`./two_sources.exe`).to eq "This is a C program with two sources.\n"
@ -845,7 +845,7 @@ EOF
expect(result.stderr).to eq ""
verify_lines(lines(result.stdout), [
%r{Compiling simple.c},
%r{Linking => simple.out},
%r{Linking simple.out},
])
end
@ -855,7 +855,7 @@ EOF
expect(result.stderr).to eq ""
verify_lines(lines(result.stdout), [
%r{Compiling simple.c},
%r{Linking => simple.out},
%r{Linking simple.out},
])
end
@ -865,7 +865,7 @@ EOF
expect(result.stderr).to eq ""
verify_lines(lines(result.stdout), [
%r{Compiling simple.c},
%r{Linking => simple.xyz},
%r{Linking simple.xyz},
])
end
@ -885,10 +885,10 @@ EOF
expect(result.stderr).to eq ""
slines = lines(result.stdout)
if RUBY_PLATFORM =~ /mingw/
verify_lines(slines, [%r{Linking => mine.dll}])
verify_lines(slines, [%r{Linking mine.dll}])
expect(File.exists?("mine.dll")).to be_truthy
else
verify_lines(slines, [%r{Linking => libmine.so}])
verify_lines(slines, [%r{Linking libmine.so}])
expect(File.exists?("libmine.so")).to be_truthy
end
@ -916,9 +916,9 @@ EOF
expect(result.stderr).to eq ""
slines = lines(result.stdout)
if RUBY_PLATFORM =~ /mingw/
verify_lines(slines, [%r{Linking => mine.dll}])
verify_lines(slines, [%r{Linking mine.dll}])
else
verify_lines(slines, [%r{Linking => libmine.so}])
verify_lines(slines, [%r{Linking libmine.so}])
end
result = run_rscons(rsconscript: "shared_library_cxx.rb")
@ -1055,7 +1055,7 @@ EOF
result = run_rscons(rsconscript: "command_builder.rb")
expect(result.stderr).to eq ""
verify_lines(lines(result.stdout), [%r{BuildIt => simple.exe}])
verify_lines(lines(result.stdout), [%r{BuildIt simple.exe}])
expect(`./simple.exe`).to eq "This is a simple C program\n"
result = run_rscons(rsconscript: "command_builder.rb")
@ -1070,7 +1070,7 @@ EOF
expect(result.stderr).to eq ""
verify_lines(lines(result.stdout), [
%r{Compiling simple.c},
%r{My Disassemble => simple.txt},
%r{My Disassemble simple.txt},
])
expect(File.read("simple.txt")).to match /Disassembly of section .text:/
end
@ -1081,7 +1081,7 @@ EOF
test_dir("simple")
result = run_rscons(rsconscript: "directory.rb")
expect(result.stderr).to eq ""
verify_lines(lines(result.stdout), [%r{Creating directory => teh_dir}])
verify_lines(lines(result.stdout), [%r{Creating directory teh_dir}])
expect(File.directory?("teh_dir")).to be_truthy
end
@ -1189,7 +1189,7 @@ EOF
expect(result.stderr).to eq ""
verify_lines(lines(result.stdout), [
%r{Compiling simple.c},
%r{Linking => simple.exe},
%r{Linking simple.exe},
%r{Checker simple.exe},
])
@ -1269,13 +1269,13 @@ EOF
expect(result.stderr).to eq ""
verify_lines(lines(result.stdout), [
%r{Compiling simple.c},
%r{Linking => simple.exe},
%r{Linking simple.exe},
])
result = run_rscons(rsconscript: "cache_command_change.rb")
expect(result.stderr).to eq ""
verify_lines(lines(result.stdout), [
%r{Linking => simple.exe},
%r{Linking simple.exe},
])
end
@ -1286,13 +1286,13 @@ EOF
expect(result.stderr).to eq ""
verify_lines(lines(result.stdout), [
%r{Compiling simple.c},
%r{Linking => simple.exe},
%r{Linking simple.exe},
])
result = run_rscons(rsconscript: "cache_new_dep2.rb")
expect(result.stderr).to eq ""
verify_lines(lines(result.stdout), [
%r{Linking => simple.exe},
%r{Linking simple.exe},
])
end
@ -1342,14 +1342,14 @@ EOF
expect(result.stderr).to eq ""
verify_lines(lines(result.stdout), [
%r{Compiling simple.c},
%r{Linking => simple.exe},
%r{Linking simple.exe},
])
File.open("user_deps", "wb") {|fh| fh.write("foo")}
result = run_rscons(rsconscript: "cache_user_dep.rb")
expect(result.stderr).to eq ""
verify_lines(lines(result.stdout), [
%r{Linking => simple.exe},
%r{Linking simple.exe},
])
end
@ -1362,7 +1362,7 @@ EOF
expect(result.stderr).to eq ""
verify_lines(lines(result.stdout), [
%r{Compiling simple.c},
%r{Linking => simple.exe},
%r{Linking simple.exe},
])
result = run_rscons(rsconscript: "cache_user_dep.rb")
@ -1373,7 +1373,7 @@ EOF
result = run_rscons(rsconscript: "cache_user_dep.rb")
expect(result.stderr).to eq ""
verify_lines(lines(result.stdout), [
%r{Linking => simple.exe},
%r{Linking simple.exe},
])
end
@ -1514,7 +1514,7 @@ EOF
result = run_rscons(rsconscript: "library_from_object.rb")
expect(result.stderr).to eq ""
expect(File.exists?("two.o")).to be_truthy
verify_lines(lines(result.stdout), [%r{Building static library archive => lib.a}])
verify_lines(lines(result.stdout), [%r{Building static library archive lib.a}])
end
end
@ -1526,9 +1526,9 @@ EOF
expect(result.stderr).to eq ""
slines = lines(result.stdout)
if RUBY_PLATFORM =~ /mingw/
verify_lines(slines, [%r{Linking => mine.dll}])
verify_lines(slines, [%r{Linking mine.dll}])
else
verify_lines(slines, [%r{Linking => libmine.so}])
verify_lines(slines, [%r{Linking libmine.so}])
end
end

View File

@ -29,6 +29,12 @@ module Rscons
end
end
describe ".colorize_markup" do
it "turns a builder message string with markup into an Array for Ansi module" do
expect(Util.colorize_markup("[ 1/33] Generating <foo> lexer from <source>parser/lexer.l<reset> => <target>build/e.1/parser/lexer.cc<reset>")).to eq ["[ 1/33] Generating ", "<foo>", " lexer from ", :cyan, "parser/lexer.l", :reset, " => ", :magenta, "build/e.1/parser/lexer.cc", :reset]
end
end
describe ".determine_n_threads" do
context "when specified by environment variable" do
before(:each) do