Change Environment#execute() options Hash to contain :env and :options keys for Kernel#system()

This commit is contained in:
Josh Holtrop 2014-02-25 12:14:52 -05:00
parent 6aa5037234
commit e3aeb7f4d7
2 changed files with 10 additions and 6 deletions

View File

@ -224,7 +224,9 @@ module Rscons
# @param short_desc [String] Message to print if the Environment's echo # @param short_desc [String] Message to print if the Environment's echo
# mode is set to :short # mode is set to :short
# @param command [Array] The command to execute. # @param command [Array] The command to execute.
# @param options [Hash] Optional options to pass to Kernel#system. # @param options [Hash] Optional options, possible keys:
# - :env - environment Hash to pass to Kernel#system.
# - :options - options Hash to pass to Kernel#system.
def execute(short_desc, command, options = {}) def execute(short_desc, command, options = {})
print_command = proc do print_command = proc do
puts command.map { |c| c =~ /\s/ ? "'#{c}'" : c }.join(' ') puts command.map { |c| c =~ /\s/ ? "'#{c}'" : c }.join(' ')
@ -234,7 +236,9 @@ module Rscons
elsif @echo == :short elsif @echo == :short
puts short_desc puts short_desc
end end
system(*command, options).tap do |result| env_args = options[:env] ? [options[:env]] : []
options_args = options[:options] ? [options[:options]] : []
system(*env_args, *command, *options_args).tap do |result|
unless result or @echo == :command unless result or @echo == :command
$stdout.write "Failed command was: " $stdout.write "Failed command was: "
print_command.call print_command.call

View File

@ -219,7 +219,7 @@ module Rscons
it "prints the short description and executes the command" do it "prints the short description and executes the command" do
env = Environment.new(echo: :short) env = Environment.new(echo: :short)
env.should_receive(:puts).with("short desc") env.should_receive(:puts).with("short desc")
env.should_receive(:system).with("a", "command", {}).and_return(true) env.should_receive(:system).with("a", "command").and_return(true)
env.execute("short desc", ["a", "command"]) env.execute("short desc", ["a", "command"])
end end
end end
@ -228,7 +228,7 @@ module Rscons
it "prints the short description, executes the command, and prints the failed command line" do it "prints the short description, executes the command, and prints the failed command line" do
env = Environment.new(echo: :short) env = Environment.new(echo: :short)
env.should_receive(:puts).with("short desc") env.should_receive(:puts).with("short desc")
env.should_receive(:system).with("a", "command", {}).and_return(false) env.should_receive(:system).with("a", "command").and_return(false)
$stdout.should_receive(:write).with("Failed command was: ") $stdout.should_receive(:write).with("Failed command was: ")
env.should_receive(:puts).with("a command") env.should_receive(:puts).with("a command")
env.execute("short desc", ["a", "command"]) env.execute("short desc", ["a", "command"])
@ -240,8 +240,8 @@ module Rscons
it "prints the command executed and executes the command" do it "prints the command executed and executes the command" do
env = Environment.new(echo: :command) env = Environment.new(echo: :command)
env.should_receive(:puts).with("a command '--arg=val with spaces'") env.should_receive(:puts).with("a command '--arg=val with spaces'")
env.should_receive(:system).with("a", "command", "--arg=val with spaces", opt: :val).and_return(false) env.should_receive(:system).with({modified: :environment}, "a", "command", "--arg=val with spaces", {opt: :val}).and_return(false)
env.execute("short desc", ["a", "command", "--arg=val with spaces"], opt: :val) env.execute("short desc", ["a", "command", "--arg=val with spaces"], env: {modified: :environment}, options: {opt: :val})
end end
end end
end end