Environment#print_builder_run_message should support string commands - close #44

This commit is contained in:
Josh Holtrop 2017-08-03 14:10:53 -04:00
parent a9aeaf2356
commit 89562c584a
6 changed files with 43 additions and 5 deletions

View File

@ -0,0 +1,5 @@
Rscons::Environment.new do |env|
env.echo = :command
env.Install("inst.exe", "install.rb")
end

View File

@ -0,0 +1,13 @@
class MyBuilder < Rscons::Builder
def run(options)
env, target = options.values_at(:env, :target)
env.print_builder_run_message("MyBuilder #{target}", "MyBuilder #{target} command")
target
end
end
Rscons::Environment.new do |env|
env.echo = :command
env.add_builder(MyBuilder.new)
env.MyBuilder("foo")
end

View File

@ -20,8 +20,7 @@ module Rscons
Ansi.write($stderr, :red, "Error: `#{target}' already exists and is not a directory", :reset, "\n")
false
else
desc = "Directory #{target}"
env.print_builder_run_message(desc, desc)
env.print_builder_run_message("Directory #{target}", nil)
cache.mkdir_p(target)
target
end

View File

@ -43,8 +43,7 @@ module Rscons
# Check the cache and copy if necessary
unless cache.up_to_date?(dest, :Copy, [src], env)
unless printed_message
desc = "#{name} #{target}"
env.print_builder_run_message(desc, desc)
env.print_builder_run_message("#{name} #{target}", nil)
printed_message = true
end
cache.mkdir_p(File.dirname(dest))

View File

@ -885,7 +885,13 @@ module Rscons
def print_builder_run_message(short_description, command)
case @echo
when :command
message = command_to_s(command) if command
if command.is_a?(Array)
message = command_to_s(command)
elsif command.is_a?(String)
message = command
elsif short_description.is_a?(String)
message = short_description
end
when :short
message = short_description if short_description
end

View File

@ -769,6 +769,22 @@ EOF
expect(lines(result.stdout)).to eq ["165"]
end
it "prints a builder's short description with 'command' echo mode if there is no command" do
test_dir("build_dir")
result = run_test(rsconsfile: "echo_command_ruby_builder.rb")
expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq ["Install inst.exe"]
end
it "supports a string for a builder's echoed 'command' with Environment#print_builder_run_message" do
test_dir("build_dir")
result = run_test(rsconsfile: "echo_command_string.rb")
expect(result.stderr).to eq ""
expect(lines(result.stdout)).to eq ["MyBuilder foo command"]
end
context "colored output" do
it "does not output in color with --color=off" do
test_dir("simple")