You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildr.apache.org by dj...@apache.org on 2009/06/23 02:00:37 UTC
svn commit: r787452 - /buildr/trunk/lib/buildr/core/util.rb
Author: djspiewak
Date: Tue Jun 23 00:00:36 2009
New Revision: 787452
URL: http://svn.apache.org/viewvc?rev=787452&view=rev
Log:
Should be overwriting Rake's `sh` rather than `system`
Modified:
buildr/trunk/lib/buildr/core/util.rb
Modified: buildr/trunk/lib/buildr/core/util.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/core/util.rb?rev=787452&r1=787451&r2=787452&view=diff
==============================================================================
--- buildr/trunk/lib/buildr/core/util.rb (original)
+++ buildr/trunk/lib/buildr/core/util.rb Tue Jun 23 00:00:36 2009
@@ -336,18 +336,43 @@
end
end
- module Kernel
+ module FileUtils
extend extend FFI::Library
attach_function :system, [:string], :int
alias_method :__native_system__, :system
- def system(cmd, *args)
- arg_str = args.map { |a| "'#{a}'" }
- cd = "cd '#{Dir.pwd}' && "
- back = __native_system__(cd + cmd + ' ' + arg_str.join(' ')) == 0
-
- $? = Buildr::ProcessStatus.new(0, back) # KLUDGE
- back
+ # code "borrowed" directly from Rake
+ def sh(*cmd, &block)
+ options = (Hash === cmd.last) ? cmd.pop : {}
+ unless block_given?
+ show_command = cmd.join(" ")
+ show_command = show_command[0,42] + "..."
+
+ block = lambda { |ok, status|
+ ok or fail "Command failed with status (#{status.exitstatus}): [#{show_command}]"
+ }
+ end
+ if RakeFileUtils.verbose_flag == :default
+ options[:verbose] = false
+ else
+ options[:verbose] ||= RakeFileUtils.verbose_flag
+ end
+ options[:noop] ||= RakeFileUtils.nowrite_flag
+ rake_check_options options, :noop, :verbose
+ rake_output_message cmd.join(" ") if options[:verbose]
+ unless options[:noop]
+ cd = "cd '#{Dir.pwd}' && "
+ res = if windows_os? && cmd.size == 1
+ __native_system__("#{cd} call #{cmd.first}") == 0
+ else
+ arg_str = args.map { |a| "'#{a}'" }
+ __native_system__(cd + cmd + ' ' + arg_str.join(' ')) == 0
+ end
+ $? = Buildr::ProcessStatus.new(0, res) # KLUDGE
+
+ block.call(res, $?)
+ end
end
+
end
end
\ No newline at end of file