From e2e0f420eae4d324f00577aae20262c9caa80119 Mon Sep 17 00:00:00 2001 From: Peter Vandenberk Date: Sat, 11 Jan 2025 17:16:34 +0000 Subject: [PATCH 1/3] Use Ruby's built-in & correct home dir on Windows --- lib/rake/application.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rake/application.rb b/lib/rake/application.rb index 87ae47b32..40d998707 100644 --- a/lib/rake/application.rb +++ b/lib/rake/application.rb @@ -761,7 +761,7 @@ def system_dir # :nodoc: # The standard directory containing system wide rake files. if Win32.windows? def standard_system_dir #:nodoc: - Win32.win32_system_dir + File.join(Dir.home, "Rake") end else def standard_system_dir #:nodoc: From 60d64652f3b48e92f3f57160933134900728493c Mon Sep 17 00:00:00 2001 From: Peter Vandenberk Date: Sat, 11 Jan 2025 17:26:53 +0000 Subject: [PATCH 2/3] Remove superfluous Win32 tests --- test/test_rake_win32.rb | 49 ----------------------------------------- 1 file changed, 49 deletions(-) diff --git a/test/test_rake_win32.rb b/test/test_rake_win32.rb index 474bf50e9..9508354b6 100644 --- a/test/test_rake_win32.rb +++ b/test/test_rake_win32.rb @@ -3,55 +3,6 @@ class TestRakeWin32 < Rake::TestCase # :nodoc: - Win32 = Rake::Win32 # :nodoc: - - def test_win32_system_dir_uses_home_if_defined - ENV["HOME"] = 'C:\\HP' - - assert_equal "C:/HP/Rake", Win32.win32_system_dir - end - - def test_win32_system_dir_uses_homedrive_homepath_when_no_home_defined - ENV["HOME"] = nil - ENV["HOMEDRIVE"] = "C:" - ENV["HOMEPATH"] = '\\HP' - - assert_equal "C:/HP/Rake", Win32.win32_system_dir - end - - def test_win32_system_dir_uses_appdata_when_no_home_or_home_combo - ENV["APPDATA"] = "C:\\Documents and Settings\\HP\\Application Data" - ENV["HOME"] = nil - ENV["HOMEDRIVE"] = nil - ENV["HOMEPATH"] = nil - - assert_equal "C:/Documents and Settings/HP/Application Data/Rake", - Win32.win32_system_dir - end - - def test_win32_system_dir_fallback_to_userprofile_otherwise - ENV["HOME"] = nil - ENV["HOMEDRIVE"] = nil - ENV["HOMEPATH"] = nil - ENV["APPDATA"] = nil - ENV["USERPROFILE"] = "C:\\Documents and Settings\\HP" - - assert_equal "C:/Documents and Settings/HP/Rake", Win32.win32_system_dir - end - - def test_win32_system_dir_nil_of_no_env_vars - ENV["APPDATA"] = nil - ENV["HOME"] = nil - ENV["HOMEDRIVE"] = nil - ENV["HOMEPATH"] = nil - ENV["RAKE_SYSTEM"] = nil - ENV["USERPROFILE"] = nil - - assert_raises(Rake::Win32::Win32HomeError) do - Win32.win32_system_dir - end - end - def test_win32_backtrace_with_different_case ex = nil begin From 6e63e0028c6e2d2bbd1346e0e6568f565ba4ba69 Mon Sep 17 00:00:00 2001 From: Peter Vandenberk Date: Sat, 11 Jan 2025 17:29:41 +0000 Subject: [PATCH 3/3] Remove superfluous Win32 code --- lib/rake/win32.rb | 36 +----------------------------------- 1 file changed, 1 insertion(+), 35 deletions(-) diff --git a/lib/rake/win32.rb b/lib/rake/win32.rb index 6e6203181..5cccbde93 100644 --- a/lib/rake/win32.rb +++ b/lib/rake/win32.rb @@ -6,46 +6,12 @@ module Rake # will be placed here to collect that knowledge in one spot. module Win32 # :nodoc: all - # 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? RbConfig::CONFIG["host_os"] =~ %r!(msdos|mswin|djgpp|mingw|[Ww]indows)! end - - # The standard directory containing system wide rake files on - # Win 32 systems. Try the following environment variables (in - # order): - # - # * HOME - # * HOMEDRIVE + HOMEPATH - # * APPDATA - # * USERPROFILE - # - # If the above are not defined, the return nil. - def win32_system_dir #:nodoc: - win32_shared_path = ENV["HOME"] - if win32_shared_path.nil? && ENV["HOMEDRIVE"] && ENV["HOMEPATH"] - win32_shared_path = ENV["HOMEDRIVE"] + ENV["HOMEPATH"] - end - - win32_shared_path ||= ENV["APPDATA"] - 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