Skip to content

Commit e5ed95e

Browse files
Workaround RVM issue when using Bundler <= 2.5.22
Old versions of BUndler need a workaround to support nested `bundle exec` invocations by overriding `Gem.activate_bin_path`. However, RubyGems now uses this new `Gem.activate_and_load_bin_path` helper in binstubs, which is of course not overridden in those Bundler versions since it didn't exist at the time. So, include the override here to workaround that.
1 parent 5d331fa commit e5ed95e

File tree

4 files changed

+43
-9
lines changed

4 files changed

+43
-9
lines changed

.github/workflows/install-rubygems.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,40 @@ jobs:
204204

205205
timeout-minutes: 20
206206

207+
check_rvm_integration:
208+
name: Handling gems shipped by default with RVM
209+
runs-on: ubuntu-24.04
210+
strategy:
211+
fail-fast: false
212+
matrix:
213+
ruby:
214+
- { name: "3.2", value: 3.2.8 }
215+
- { name: "3.3", value: 3.3.8 }
216+
- { name: "3.4", value: 3.4.4 }
217+
218+
steps:
219+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
220+
with:
221+
persist-credentials: false
222+
- name: Setup ruby
223+
uses: ruby/setup-ruby@472790540115ce5bd69d399a020189a8c87d641f # v1.247.0
224+
with:
225+
ruby-version: ${{ matrix.ruby.value }}
226+
bundler: none
227+
- name: Install rubygems
228+
run: ruby setup.rb
229+
- name: Install RVM gems
230+
run: gem install rubygems-bundler
231+
- name: Check binstubs can run
232+
run: |
233+
gem install rake
234+
RUBYOPT=-Ibundler/lib rake -T
235+
- name: Check binstubs can handle nested bundle exec
236+
run: |
237+
echo "source 'https://rubygems.org'" > Gemfile
238+
gem install bundler:2.5.22
239+
bundle _2.5.22_ exec ruby -e 'system("bundle", "exec", "ruby", "-e1")' 2>&1 | grep -v LoadError
240+
207241
all-pass:
208242
name: All install-rubygems jobs pass
209243

@@ -213,6 +247,7 @@ jobs:
213247
- install_rubygems_ubuntu
214248
- install_rubygems_windows
215249
- shared_gem_home
250+
- check_rvm_integration
216251

217252
runs-on: ubuntu-latest
218253

.github/workflows/ubuntu-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ jobs:
9292
- name: Install & Check Dependencies
9393
run: bin/rake dev:frozen_deps
9494
- name: Misc checks
95-
run: bin/rake check_rvm_integration man:check vendor:check version:check check_rubygems_integration
95+
run: bin/rake man:check vendor:check version:check check_rubygems_integration
9696
if: matrix.ruby.name != 'jruby'
9797
timeout-minutes: 15
9898

Rakefile

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -563,14 +563,6 @@ namespace :spec do
563563
end
564564
end
565565

566-
desc "Check RVM integration"
567-
task :check_rvm_integration do
568-
# The rubygems-bundler gem is installed by RVM by default and it could easily
569-
# break when we change bundler. Make sure that binstubs still run with it
570-
# installed.
571-
sh("RUBYOPT=-Ilib gem install rubygems-bundler rake && RUBYOPT=-Ibundler/lib rake -T")
572-
end
573-
574566
desc "Check RubyGems integration"
575567
task :check_rubygems_integration do
576568
# Bundler monkeypatches RubyGems in some ways that could potentially break gem activation.

lib/rubygems.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,13 @@ def self.activate_and_load_bin_path(name, exec_name = nil, *requirements)
298298
spec = find_and_activate_spec_for_exe name, exec_name, requirements
299299

300300
if spec.name == "bundler"
301+
# Old versions of Bundler need a workaround to support nested `bundle
302+
# exec` invocations by overriding `Gem.activate_bin_path`. However,
303+
# RubyGems now uses this new `Gem.activate_and_load_bin_path` helper in
304+
# binstubs, which is of course not overridden in Bundler since it didn't
305+
# exist at the time. So, include the override here to workaround that.
306+
load ENV["BUNDLE_BIN_PATH"] if ENV["BUNDLE_BIN_PATH"] && spec.version <= "2.5.22"
307+
301308
# Make sure there's no version of Bundler in `$LOAD_PATH` that's different
302309
# from the version we just activated. If that was the case (it happens
303310
# when testing Bundler from ruby/ruby), we would load Bundler extensions

0 commit comments

Comments
 (0)