| Module | FileUtils |
| In: |
lib/rake.rb
|
| RUBY | = | File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']) |
| LN_SUPPORTED | = | [true] |
Run a Ruby interpreter with the given arguments.
Example:
ruby %{-pe '$_.upcase!' <README}
# File lib/rake.rb, line 735
735: def ruby(*args,&block)
736: options = (Hash === args.last) ? args.pop : {}
737: if args.length > 1 then
738: sh(*([RUBY] + args + [options]), &block)
739: else
740: sh("#{RUBY} #{args}", options, &block)
741: end
742: end
Attempt to do a normal file link, but fall back to a copy if the link fails.
# File lib/rake.rb, line 748
748: def safe_ln(*args)
749: unless LN_SUPPORTED[0]
750: cp(*args)
751: else
752: begin
753: ln(*args)
754: rescue StandardError, NotImplementedError => ex
755: LN_SUPPORTED[0] = false
756: cp(*args)
757: end
758: end
759: end
Run the system command cmd. If multiple arguments are given the command is not run with the shell (same semantics as Kernel::exec and Kernel::system).
Example:
sh %{ls -ltr}
sh 'ls', 'file with spaces'
# check exit status after command runs
sh %{grep pattern file} do |ok, res|
if ! ok
puts "pattern not found (status = #{res.exitstatus})"
end
end
# File lib/rake.rb, line 712
712: def sh(*cmd, &block)
713: options = (Hash === cmd.last) ? cmd.pop : {}
714: unless block_given?
715: show_command = cmd.join(" ")
716: show_command = show_command[0,42] + "..."
717: # TODO code application logic heref show_command.length > 45
718: block = lambda { |ok, status|
719: ok or fail "Command failed with status (#{status.exitstatus}): [#{show_command}]"
720: }
721: end
722: rake_check_options options, :noop, :verbose
723: rake_output_message cmd.join(" ") if options[:verbose]
724: unless options[:noop]
725: res = system(*cmd)
726: block.call(res, $?)
727: end
728: end
Split a file path into individual directory names.
Example:
split_all("a/b/c") => ['a', 'b', 'c']
# File lib/rake.rb, line 766
766: def split_all(path)
767: head, tail = File.split(path)
768: return [tail] if head == '.' || tail == '/'
769: return [head, tail] if head == '/'
770: return split_all(head) + [tail]
771: end