diff options
| author | David RodrÃguez <deivid.rodriguez@riseup.net> | 2025-07-09 12:23:19 +0200 |
|---|---|---|
| committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2025-07-14 11:52:14 +0900 |
| commit | 7a03a02bee340897a3647190e6a5f9866efb31ce (patch) | |
| tree | dc5d6b228b9d9eb5464b2a8c1b7f2ad4d5101a3c | |
| parent | c3d41492e14929f8bbee26a276ee76b9a8c9d5b6 (diff) | |
[rubygems/rubygems] Fix more warnings when running old Bundler with latest RubyGems
Also fix platform warnings when Bundler's entrypoint is bundler's
binstub.
https://github.com/rubygems/rubygems/commit/4b1df58403
| -rw-r--r-- | lib/rubygems.rb | 46 | ||||
| -rw-r--r-- | lib/rubygems/installer.rb | 7 | ||||
| -rw-r--r-- | test/rubygems/test_gem_installer.rb | 6 |
3 files changed, 51 insertions, 8 deletions
diff --git a/lib/rubygems.rb b/lib/rubygems.rb index 7fcf03d855..6c104ae10b 100644 --- a/lib/rubygems.rb +++ b/lib/rubygems.rb @@ -249,6 +249,16 @@ module Gem find_spec_for_exe(name, exec_name, requirements).bin_file exec_name end + def self.find_and_activate_spec_for_exe(name, exec_name, requirements) + spec = find_spec_for_exe name, exec_name, requirements + Gem::LOADED_SPECS_MUTEX.synchronize do + spec.activate + finish_resolve + end + spec + end + private_class_method :find_and_activate_spec_for_exe + def self.find_spec_for_exe(name, exec_name, requirements) raise ArgumentError, "you must supply exec_name" unless exec_name @@ -274,6 +284,35 @@ module Gem private_class_method :find_spec_for_exe ## + # Find and load the full path to the executable for gem +name+. If the + # +exec_name+ is not given, an exception will be raised, otherwise the + # specified executable's path is returned. +requirements+ allows + # you to specify specific gem versions. + # + # A side effect of this method is that it will activate the gem that + # contains the executable. + # + # This method should *only* be used in bin stub files. + + def self.activate_and_load_bin_path(name, exec_name = nil, *requirements) + spec = find_and_activate_spec_for_exe name, exec_name, requirements + + if spec.name == "bundler" + # Make sure there's no version of Bundler in `$LOAD_PATH` that's different + # from the version we just activated. If that was the case (it happens + # when testing Bundler from ruby/ruby), we would load Bundler extensions + # to RubyGems from the copy in `$LOAD_PATH` but then load the binstub from + # an installed copy, causing those copies to be mixed and yet more + # redefinition warnings. + # + require_path = $LOAD_PATH.resolve_feature_path("bundler").last.delete_suffix("/bundler.rb") + Gem.load_bundler_extensions(spec.version) if spec.full_require_paths.include?(require_path) + end + + load spec.bin_file(exec_name) + end + + ## # Find the full path to the executable for gem +name+. If the +exec_name+ # is not given, an exception will be raised, otherwise the # specified executable's path is returned. +requirements+ allows @@ -285,12 +324,7 @@ module Gem # This method should *only* be used in bin stub files. def self.activate_bin_path(name, exec_name = nil, *requirements) # :nodoc: - spec = find_spec_for_exe name, exec_name, requirements - Gem::LOADED_SPECS_MUTEX.synchronize do - spec.activate - finish_resolve - end - spec.bin_file exec_name + find_and_activate_spec_for_exe(name, exec_name, requirements).bin_file exec_name end ## diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb index 62381ba63d..2b3200223a 100644 --- a/lib/rubygems/installer.rb +++ b/lib/rubygems/installer.rb @@ -228,6 +228,7 @@ class Gem::Installer ruby_executable = true existing = io.read.slice(/ ^\s*( + Gem\.activate_and_load_bin_path\( | load \s Gem\.activate_bin_path\( ) (['"])(.*?)(\2), @@ -769,7 +770,11 @@ class Gem::Installer end end - load Gem.activate_bin_path('#{spec.name}', '#{bin_file_name}', version) + if Gem.respond_to?(:activate_and_load_bin_path) + Gem.activate_and_load_bin_path('#{spec.name}', '#{bin_file_name}', version) + else + load Gem.activate_bin_path('#{spec.name}', '#{bin_file_name}', version) + end TEXT end diff --git a/test/rubygems/test_gem_installer.rb b/test/rubygems/test_gem_installer.rb index fb5e77f358..34415aa7dd 100644 --- a/test/rubygems/test_gem_installer.rb +++ b/test/rubygems/test_gem_installer.rb @@ -48,7 +48,11 @@ class TestGemInstaller < Gem::InstallerTestCase end end - load Gem.activate_bin_path('a', 'executable', version) + if Gem.respond_to?(:activate_and_load_bin_path) + Gem.activate_and_load_bin_path('a', 'executable', version) + else + load Gem.activate_bin_path('a', 'executable', version) + end EOF wrapper = installer.app_script_text "executable" |
