While reading through RBENV's rubygems_plugin.rb file, I encountered the following line of code:
if defined?(Bundler::Installer) && Bundler::Installer.respond_to?(:install) && !Bundler::Installer.respond_to?(:install_without_rbenv_rehash)
Reviewing this line's git history, I saw that the original version of this line was added in this PR from 2015, and its goal was to ensure that rbenv rehash is only run once, at the end of the gem installation process. The goal of rbenv rehash, in turn, is to generate shim files inside ~/.rbenv/shims for any Ruby gem which includes a terminal command.
Based on the original PR and discussion, it appeared that this code would be executed when the bundle install command is run inside a project which includes a Gemfile. I wanted to step through this process as it happened, to learn more about Bundler, so I did the following:
- I installed a fresh version of Ruby (
v3.1.4) usingrbenv install 3.1.4. - I installed the
railsgem viagem install rails. - I generated a new Rails project via
rails new foobar. - To simplify things, I commented out all the invocations of
gemexcept for the first one (gem 'rails', '~> 5.2.8', '>= 5.2.8.1') and one that I added (gem 'wisper'). - I added a debugger statement just below the aforementioned
ifcheck insiderubygems_plugin.rb. - I ran
bundle install
However, I didn't hit my debugger statement. I also tried placing a 2nd debugger statement outside the if statement and re-running bundle install, but that debugger was also skipped.
My best guess is that I'm simply doing something wrong and my understanding is off somehow, and that this is preventing me from reaching my debugger statements. Failing that, I also thought there's a (small) chance that:
- Bundler used to run RubyGems plugins as part of its execution (hence the discussion from the PR), but that...
- ...this stopped being true sometime between the PR's date and today.
Can anyone spot where my thinking has gone awry?
It looks like this PR to the Bundler codebase introduced a change, such that
Gem.load_env_pluginswas replaced withGem.load_plugins. The latter searches for plugins in different directories than the former, which means that RBENV'srubygems_plugins.rbis no longer found or loaded.I confirmed this by adding
Gem.load_env_pluginsback into the source code of my Bundler installation'slib/bundler/cli/install.rbfile, and re-runningbundle install. This resulted in my successfully hitting the breakpoints I had added to RBENV'srubygems_plugin.rbfile.