win32.rb 1.5 KB

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