Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Replace Rake's Win32-specific logic with a 100% equivalent, pure-Ruby implementation #669

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
pvdb wants to merge 3 commits into ruby:master
base: master
Choose a base branch
Loading
from pvdb:remove_win32_system_dir

Conversation

@pvdb
Copy link
Contributor

@pvdb pvdb commented Nov 22, 2025
edited
Loading

tl;dr - replace some Win32-specific Rake logic for Windows home directory detection logic with Ruby's built-in Dir.home method

Rake's custom Windows-specific implementation (Rake::Win32::win32_system_dir) produces identical results to Ruby's standard library approach (File.join(Dir.home, "Rake")) for all possible scenarios it caters for, so this PR removes a whole bunch of superfluous code and corresponding tests.

It is replaced with a much simpler, pure stdlib-based implementation. in a low-risk manner: Ruby's cross-platform Dir.home has been available since Ruby 1.9 and is the standard way to get the home directory; this change simply stops reinventing the wheel. 😃

  1. Simpler code — Removes ~85 lines of custom Win32 path handling code, tests, and a custom exception class
  2. More correct — Dir.home is Ruby's official, well-tested cross-platform solution that handles edge cases properly. The old implementation had a hand-rolled fallback chain (HOME → HOMEDRIVE+HOMEPATH → APPDATA → USERPROFILE) that Ruby already handles correctly internally
  3. Less maintenance burden — No need to maintain Windows-specific path normalization or environment variable logic that duplicates Ruby stdlib functionality
  4. Consistent behavior — Aligns Rake's behavior with how other Ruby tools determine the home directory on Windows

Because it's hard to use and test something that isn't there anymore 😄 I've raised an accompanying DRAFT pull request #670 that explicitly tests the equivalency of both versions against the master branch (for a variety of different scenarios) thereby demonstrating that the Rake-specific patch is superfluous and can be safely removed.

Comment on lines -38 to -40
raise Win32HomeError,
"Unable to determine home path environment variable." if
win32_shared_path.nil? or win32_shared_path.empty?
Copy link
Contributor Author

@pvdb pvdb Nov 22, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is worth noting that the Win32HomeError exception is never thrown IRL, because Ruby will always set the HOME environment variable in its environment, even if it isn't set in the Windows environment the Ruby process is running in.

It has done so since Ruby 1.9.x in 2004: ruby/ruby@c41cefd492

Comment on lines -50 to -52
assert_raises(Rake::Win32::Win32HomeError) do
Win32.win32_system_dir
end
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per the above comment, this test is superfluous, as the exception will never be thrown IRL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

1 participant

AltStyle によって変換されたページ (->オリジナル) /