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

Have shims survive upgrades via Homebrew #1350

Merged
merged 1 commit into from
Sep 29, 2021
Merged

Conversation

mislav
Copy link
Member

@mislav mislav commented Sep 29, 2021

Homebrew places the rbenv executable in a location such as /usr/local/bin/rbenv, which is in PATH. However, that is a symlink to /usr/local/Cellar/rbenv/<VERSION>/bin/rbenv, which is itself a symlink to /usr/local/Cellar/rbenv/<VERSION>/libexec/rbenv. Upon executing, rbenv will add its own directory to PATH so that it can easily invoke its subcommands.

When generating shims during rbenv rehash, rbenv will try to put the absolute path to itself inside each shim so that shims would work even if rbenv itself isn't in PATH. Under Homebrew, rbenv's directory will be the versioned directory in Homebrew's Cellar. However, due to Homebrew's auto-cleanup functionality, shims generated this way will be broken after upgrading rbenv because of the versioned Cellar path.

This changes how rbenv discovers itself in PATH: it will look at the original PATH, not in the one modified by rbenv, with the intention of excluding results under rbenv's own libexec/. If rbenv wasn't found in PATH, return the absolute path to rbenv's own bin/rbenv.

Homebrew places the rbenv executable in a location such as
`/usr/local/bin/rbenv`, which is in PATH. However, that is a symlink to
`/usr/local/Cellar/rbenv/<VERSION>/bin/rbenv`, which is itself a symlink to
`/usr/local/Cellar/rbenv/<VERSION>/libexec/rbenv`. Upon executing, rbenv
will add its own directory to PATH so that it can easily invoke its
subcommands.

When generating shims during `rbenv rehash`, rbenv will try to put the
absolute path to itself inside each shim so that shims would work even
if rbenv itself isn't in PATH. Under Homebrew, rbenv's directory will be
the versioned directory in Homebrew's Cellar. However, due to Homebrew's
auto-cleanup functionality, shims generated this way will be broken
after upgrading rbenv because of the versioned Cellar path.

This changes how rbenv discovers itself in PATH: it will look at the
original PATH, not in the one modified by rbenv, with the intention of
excluding results under rbenv's own `libexec/`. If rbenv wasn't found in
PATH, return the absolute path to rbenv's own `bin/rbenv`.
@mislav mislav merged commit 0767d64 into master Sep 29, 2021
@mislav mislav deleted the rehash-path-to-rbenv branch September 29, 2021 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant