Skip to content
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

rbenv: use opt bin symlink in rehash script #75996

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion Formula/rbenv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def install
s.gsub! ":/usr/local/etc/rbenv.d", ":#{HOMEBREW_PREFIX}/etc/rbenv.d\\0" if HOMEBREW_PREFIX.to_s != "/usr/local"
end

inreplace "libexec/rbenv-rehash", "$(command -v rbenv)", opt_bin/"rbenv"
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

This works, but it feels brittle. If the expression command -v rbenv changes even slightly within rbenv source, this workaround silently breaks.

Copy link
Member

Choose a reason for hiding this comment

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

There are two potential sources of breakage:

  1. The line we want to change stops using $(command -v rbenv).
  2. libexec/rbenv-rehash starts using $(command -v rbenv) somewhere else we may not want to change.

Both seem sufficiently unlikely to me, but you'd know more about this than I do, of course. libexec/rbenv-rehash hasn't changed in years, and the relevant line we want to change has been there for even longer.

I'm not sure 2 is such a problem either, as I think I'm comfortable with using opt_bin/"rbenv" everywhere rbenv wants to do command -v rbenv.

1 should not be a problem as long as it doesn't happen simultaneously with 2, as the inreplace will error out when it is unable to do a replacement. We can avoid that by tightening the inreplace with more context from the line we actually want to replace.

Copy link
Sponsor Contributor

@mislav mislav May 10, 2021

Choose a reason for hiding this comment

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

Thanks for elaborating. I'm not opposed to this being merged. But I do not feel like the fix is ideal in the long term. The main problem is that Homebrew aggressively prunes old versions of software after upgrades. This breaks not just rbenv, but also ruby gems linked to removed versions of Homebrew software that got updated in the meantime. I have fixed my own Ruby development environment with export HOMEBREW_NO_INSTALL_CLEANUP=true

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hopefully such a change wouldn't break silently and would be picked up by the test.


# Compile optional bash extension.
system "src/configure"
system "make", "-C", "src"
Expand All @@ -41,6 +43,22 @@ def install
end

test do
shell_output("eval \"$(#{bin}/rbenv init -)\" && rbenv versions")
# Create a fake ruby version and executable.
rbenv_root = Pathname(shell_output("rbenv root").strip)
ruby_bin = rbenv_root/"versions/1.2.3/bin"
foo_script = ruby_bin/"foo"
foo_script.write "echo hello"
chmod "+x", foo_script

# Test versions.
versions = shell_output("eval \"$(#{bin}/rbenv init -)\" && rbenv versions").split("\n")
assert_equal 2, versions.length
assert_match(/\* system/, versions[0])
assert_equal(" 1.2.3", versions[1])

# Test rehash.
system "rbenv", "rehash"
refute_match "Cellar", (rbenv_root/"shims/foo").read
assert_equal "hello", shell_output("eval \"$(#{bin}/rbenv init -)\" && rbenv shell 1.2.3 && foo").chomp
end
end