diff options
author | David RodrÃguez <deivid.rodriguez@riseup.net> | 2022-07-13 19:10:47 +0200 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2022-07-14 04:47:58 +0900 |
commit | 8c74eaa08d25355560550787e38da079f1929abf (patch) | |
tree | 3d636f9d3dd809210981f6922f4eb259cae169bd /lib/rubygems/commands/setup_command.rb | |
parent | 664c23db79dd0d500a834ef0ec8da443d95ddfd6 (diff) |
[rubygems/rubygems] Fix `gem update --system` crash while regenerating binstubs
Since a few commits ago, we no longer call `Gem::Specification.reset`
after each invocation of `Gem::Installer#install`. This means we don't
call it when the default Bundler is installed during `gem update
--system`. This causes no issues until the end of the upgrade process
when:
* The previous default Bundler spec is removed from disk.
* All specification stubs are turned into real specifications by loading
them from disk. But the one for Bundler no longer exists so
materializes to `nil` and regenerating binstubs crashes like this:
```
Bundler 2.4.0.dev installed
RubyGems 3.4.0.dev installed
Regenerating binstubs
ERROR: While executing gem ... (NoMethodError)
undefined method `platform' for nil:NilClass
/Users/deivid/Code/rubygems/rubygems/lib/rubygems/commands/pristine_command.rb:116:in `block in execute'
/Users/deivid/Code/rubygems/rubygems/lib/rubygems/specification.rb:981:in `block in each'
/Users/deivid/Code/rubygems/rubygems/lib/rubygems/specification.rb:980:in `each'
/Users/deivid/Code/rubygems/rubygems/lib/rubygems/specification.rb:980:in `each'
/Users/deivid/Code/rubygems/rubygems/lib/rubygems/commands/pristine_command.rb:116:in `map'
/Users/deivid/Code/rubygems/rubygems/lib/rubygems/commands/pristine_command.rb:116:in `each'
/Users/deivid/Code/rubygems/rubygems/lib/rubygems/commands/pristine_command.rb:116:in `select'
/Users/deivid/Code/rubygems/rubygems/lib/rubygems/commands/pristine_command.rb:116:in `execute'
/Users/deivid/Code/rubygems/rubygems/lib/rubygems/command.rb:323:in `invoke_with_build_args'
/Users/deivid/Code/rubygems/rubygems/lib/rubygems/command.rb:301:in `invoke'
/Users/deivid/Code/rubygems/rubygems/lib/rubygems/commands/setup_command.rb:604:in `regenerate_binstubs'
/Users/deivid/Code/rubygems/rubygems/lib/rubygems/commands/setup_command.rb:183:in `execute'
/Users/deivid/Code/rubygems/rubygems/lib/rubygems/command.rb:323:in `invoke_with_build_args'
/Users/deivid/Code/rubygems/rubygems/lib/rubygems/command_manager.rb:185:in `process_args'
/Users/deivid/Code/rubygems/rubygems/lib/rubygems/command_manager.rb:149:in `run'
/Users/deivid/Code/rubygems/rubygems/lib/rubygems/gem_runner.rb:51:in `run'
setup.rb:33:in `<main>'
```
We fix it by more carefully managing the removal of the previous default
Bundler gem.
https://github.com/rubygems/rubygems/commit/9989f6d5af
Diffstat (limited to 'lib/rubygems/commands/setup_command.rb')
-rw-r--r-- | lib/rubygems/commands/setup_command.rb | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/rubygems/commands/setup_command.rb b/lib/rubygems/commands/setup_command.rb index 84e9210cfb..35b500936d 100644 --- a/lib/rubygems/commands/setup_command.rb +++ b/lib/rubygems/commands/setup_command.rb @@ -365,10 +365,11 @@ By default, this RubyGems will install gem as: bundler_spec = Dir.chdir("bundler") { Gem::Specification.load("bundler.gemspec") } - # Remove bundler-*.gemspec in default specification directory. - Dir.entries(specs_dir). - select {|gs| gs.start_with?("bundler-") }. - each {|gs| File.delete(File.join(specs_dir, gs)) } + current_default_spec = Gem::Specification.default_stubs.find {|s| s.name == "bundler" } + if current_default_spec + File.delete(current_default_spec.loaded_from) + Gem::Specification.remove_spec current_default_spec + end default_spec_path = File.join(specs_dir, "#{bundler_spec.full_name}.gemspec") Gem.write_binary(default_spec_path, bundler_spec.to_ruby) |