From ea94d40f4a44bef1801faf147c469220d1259d4c Mon Sep 17 00:00:00 2001 From: jim Date: Thu, 25 Sep 2008 07:01:07 +0000 Subject: updated to rake code to rake-0.8.3 source code base git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19542 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 8 ++++++ lib/rake.rb | 81 +++++++++++++++++++------------------------------------ lib/rake/win32.rb | 54 +++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 53 deletions(-) create mode 100644 lib/rake/win32.rb diff --git a/ChangeLog b/ChangeLog index b375213ba0..270a8a0716 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2008-09-25 Jim Weirich + + * lib/rake.rb: Update rake source to version 0.8.3. This + version includes some fixes for running Rake on windows. (1) + better APPDATA/HOMExxx/USERPROFILE integration for system + rakefiles, (2) Better handling of the :ruby command when + installed in directory containing spaces. + Thu Sep 25 11:22:51 2008 * lib/rdoc*: Update to RDoc 2.2.1 r185. diff --git a/lib/rake.rb b/lib/rake.rb index caafa5caf0..313e169feb 100755 --- a/lib/rake.rb +++ b/lib/rake.rb @@ -29,7 +29,7 @@ # as a library via a require statement, but it can be distributed # independently as an application. -RAKEVERSION = '0.8.2' +RAKEVERSION = '0.8.3' require 'rbconfig' require 'fileutils' @@ -38,6 +38,8 @@ require 'monitor' require 'optparse' require 'ostruct' +require 'rake/win32' + ###################################################################### # Rake extensions to Module. # @@ -72,7 +74,7 @@ end # module Module # class String rake_extension("ext") do - # Replace the file extension with +newext+. If there is no extension on + # Replace the file extension with +newext+. If there is no extenson on # the string, append the new extension to the end. If the new extension # is not given, or is the empty string, remove any existing extension. # @@ -145,7 +147,7 @@ class String # * %x -- The file extension of the path. An empty string if there # is no extension. # * %X -- Everything *but* the file extension. - # * %s -- The alternate file separator if defined, otherwise use + # * %s -- The alternate file separater if defined, otherwise use # the standard file separator. # * %% -- A percent sign. # @@ -160,8 +162,8 @@ class String # 'a/b/c/d/file.txt'.pathmap("%-2d") => 'c/d' # # Also the %d, %p, $f, $n, %x, and %X operators can take a - # pattern/replacement argument to perform simple string substitutions on a - # particular part of the path. The pattern and replacement are separated + # pattern/replacement argument to perform simple string substititions on a + # particular part of the path. The pattern and replacement are speparated # by a comma and are enclosed by curly braces. The replacement spec comes # after the % character but before the operator letter. (e.g. # "%{old,new}d"). Muliple replacement specs should be separated by @@ -261,11 +263,6 @@ module Rake end end - # Error indicating a problem in locating the home directory on a - # Win32 system. - class Win32HomeError < RuntimeError - end - # -------------------------------------------------------------------------- # Rake module singleton methods. # @@ -942,7 +939,8 @@ end # added to the FileUtils utility functions. # module FileUtils - RUBY = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']) + RUBY = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']). + sub(/.*\s.*/m, '"\&"') OPT_TABLE['sh'] = %w(noop verbose) OPT_TABLE['ruby'] = %w(noop verbose) @@ -988,23 +986,14 @@ module FileUtils end def rake_system(*cmd) - if Rake.application.windows? - rake_win32_system(*cmd) + if Rake::Win32.windows? + Rake::Win32.rake_system(*cmd) else system(*cmd) end end private :rake_system - def rake_win32_system(*cmd) - if cmd.size == 1 - system("call #{cmd}") - else - system(*cmd) - end - end - private :rake_win32_system - # Run a Ruby interpreter with the given arguments. # # Example: @@ -2047,10 +2036,10 @@ module Rake yield rescue SystemExit => ex # Exit silently with current status - raise - rescue OptionParser::InvalidOption => ex + exit(ex.status) + rescue SystemExit, OptionParser::InvalidOption => ex # Exit silently - exit(false) + exit(1) rescue Exception => ex # Exit with error message $stderr.puts "rake aborted!" @@ -2061,7 +2050,7 @@ module Rake $stderr.puts ex.backtrace.find {|str| str =~ /#{@rakefile}/ } || "" $stderr.puts "(See full trace by running task with --trace)" end - exit(false) + exit(1) end end @@ -2144,7 +2133,7 @@ module Rake end def windows? - Config::CONFIG['host_os'] =~ /mswin/ + Win32.windows? end def truncate(string, width) @@ -2345,7 +2334,7 @@ module Rake rakefile, location = find_rakefile_location if (! options.ignore_system) && (options.load_system || rakefile.nil?) && - directory?(system_dir) + system_dir && File.directory?(system_dir) puts "(in #{Dir.pwd})" unless options.silent glob("#{system_dir}/*.rake") do |name| add_import name @@ -2374,38 +2363,24 @@ module Rake # The directory path containing the system wide rakefiles. def system_dir - if ENV['RAKE_SYSTEM'] - ENV['RAKE_SYSTEM'] - elsif windows? - win32_system_dir - else - standard_system_dir - end + @system_dir ||= + begin + if ENV['RAKE_SYSTEM'] + ENV['RAKE_SYSTEM'] + elsif Win32.windows? + Win32.win32_system_dir + else + standard_system_dir + end + end end - + # The standard directory containing system wide rake files. def standard_system_dir #:nodoc: File.join(File.expand_path('~'), '.rake') end private :standard_system_dir - # The standard directory containing system wide rake files on Win - # 32 systems. - def win32_system_dir #:nodoc: - win32home = File.join(ENV['APPDATA'], 'Rake') - unless directory?(win32home) - raise Win32HomeError, "Unable to determine home path environment variable." - else - win32home - end - end - private :win32_system_dir - - def directory?(path) - File.directory?(path) - end - private :directory? - # Collect the list of tasks on the command line. If no tasks are # given, return a list containing only the default task. # Environmental assignments are processed at this time as well. diff --git a/lib/rake/win32.rb b/lib/rake/win32.rb new file mode 100644 index 0000000000..eadc585a3f --- /dev/null +++ b/lib/rake/win32.rb @@ -0,0 +1,54 @@ +module Rake + + # Win 32 interface methods for Rake. Windows specific functionality + # will be placed here to collect that knowledge in one spot. + module Win32 + + # Error indicating a problem in locating the home directory on a + # Win32 system. + class Win32HomeError < RuntimeError + end + + class << self + # True if running on a windows system. + def windows? + Config::CONFIG['host_os'] =~ /mswin/ + end + + # Run a command line on windows. + def rake_system(*cmd) + if cmd.size == 1 + system("call #{cmd}") + else + system(*cmd) + end + end + + # The standard directory containing system wide rake files on + # Win 32 systems. Try the following environment variables (in + # order): + # + # * APPDATA + # * HOMEDRIVE + HOMEPATH + # * USERPROFILE + # + # If the above are not defined, the return nil. + def win32_system_dir #:nodoc: + win32_shared_path = ENV['APPDATA'] + if win32_shared_path.nil? && ENV['HOMEDRIVE'] && ENV['HOMEPATH'] + win32_shared_path = ENV['HOMEDRIVE'] + ENV['HOMEPATH'] + end + win32_shared_path ||= ENV['USERPROFILE'] + raise Win32HomeError, "Unable to determine home path environment variable." if + win32_shared_path.nil? or win32_shared_path.empty? + normalize(File.join(win32_shared_path, 'Rake')) + end + + # Normalize a win32 path so that the slashes are all forward slashes. + def normalize(path) + path.gsub(/\\/, '/') + end + + end + end +end -- cgit v1.2.3