| 1 |
|
| 2 |
module Rake |
| 3 |
require 'rake/alt_system' |
| 4 |
|
| 5 |
# Win 32 interface methods for Rake. Windows specific functionality |
| 6 |
# will be placed here to collect that knowledge in one spot. |
| 7 |
module Win32 |
| 8 |
|
| 9 |
# Error indicating a problem in locating the home directory on a |
| 10 |
# Win32 system. |
| 11 |
class Win32HomeError < RuntimeError |
| 12 |
end |
| 13 |
|
| 14 |
class << self |
| 15 |
# True if running on a windows system. |
| 16 |
def windows? |
| 17 |
AltSystem::WINDOWS |
| 18 |
end |
| 19 |
|
| 20 |
# Run a command line on windows. |
| 21 |
def rake_system(*cmd) |
| 22 |
AltSystem.system(*cmd) |
| 23 |
end |
| 24 |
|
| 25 |
# The standard directory containing system wide rake files on |
| 26 |
# Win 32 systems. Try the following environment variables (in |
| 27 |
# order): |
| 28 |
# |
| 29 |
# * HOME |
| 30 |
# * HOMEDRIVE + HOMEPATH |
| 31 |
# * APPDATA |
| 32 |
# * USERPROFILE |
| 33 |
# |
| 34 |
# If the above are not defined, the return nil. |
| 35 |
def win32_system_dir #:nodoc: |
| 36 |
win32_shared_path = ENV['HOME'] |
| 37 |
if win32_shared_path.nil? && ENV['HOMEDRIVE'] && ENV['HOMEPATH'] |
| 38 |
win32_shared_path = ENV['HOMEDRIVE'] + ENV['HOMEPATH'] |
| 39 |
end |
| 40 |
|
| 41 |
win32_shared_path ||= ENV['APPDATA'] |
| 42 |
win32_shared_path ||= ENV['USERPROFILE'] |
| 43 |
raise Win32HomeError, "Unable to determine home path environment variable." if |
| 44 |
win32_shared_path.nil? or win32_shared_path.empty? |
| 45 |
normalize(File.join(win32_shared_path, 'Rake')) |
| 46 |
end |
| 47 |
|
| 48 |
# Normalize a win32 path so that the slashes are all forward slashes. |
| 49 |
def normalize(path) |
| 50 |
path.gsub(/\\/, '/') |
| 51 |
end |
| 52 |
|
| 53 |
end |
| 54 |
end |
| 55 |
end |