diff options
author | Vít Ondruch <vondruch@redhat.com> | 2019-04-02 10:52:44 +0200 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2020-05-08 14:13:29 +0900 |
commit | acc86570dd8cc1920d1c55da7836d6c60d98a6d5 (patch) | |
tree | 1ad418ef0e0c63eb073d37ce6edfaf5fd7350906 | |
parent | 15a4b7d7693891831cd956def7108481aa86ddb2 (diff) |
[rubygems/rubygems] Let `@@stubs_by_name` to be incrementally populated again.
Originally, the call to `.stubs_for` allowed to incrementally populate
the `@@stubs_by_name` (especially see the `"#{name}-*.gemspec"` pattern
in 4fa03bb7aac9f25f44394e818433fdda9962ae8d). Now it looks like it
expects that all stubs are loaded, but the `.stubs_for` still matches
the .gemspec files by the `name` pattern:
https://github.com/rubygems/rubygems/blob/6d45e0f7ac1caca22900e39f703e226c4cfdebf7/lib/rubygems/specification.rb#L845
I think this was done by mistake incrementally by PR #1239 and
4cee8ca9199ac7b3ab8647e0b78615f55d3eb02b. I think the best option is to
get back to the original implementation, to let RubyGems incrementally
populate the array. Other option would be to replace the logic in
`.stub_for` by call to `.stubs`, but the means the performance
improvement from the original commit was lost.
https://github.com/rubygems/rubygems/commit/4d0e18185a
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/3092
-rw-r--r-- | lib/rubygems/specification.rb | 4 | ||||
-rw-r--r-- | test/rubygems/test_gem_specification.rb | 19 |
2 files changed, 21 insertions, 2 deletions
diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb index 9f6cdea8ad..4f2b64e652 100644 --- a/lib/rubygems/specification.rb +++ b/lib/rubygems/specification.rb @@ -828,8 +828,8 @@ class Gem::Specification < Gem::BasicSpecification # only returns stubs that match Gem.platforms def self.stubs_for(name) - if @@stubs - @@stubs_by_name[name] || [] + if @@stubs_by_name[name] + @@stubs_by_name[name] else pattern = "#{name}-*.gemspec" stubs = Gem.loaded_specs.values + diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb index e0568506c5..f6caba896a 100644 --- a/test/rubygems/test_gem_specification.rb +++ b/test/rubygems/test_gem_specification.rb @@ -1179,6 +1179,25 @@ dependencies: [] Gem::Specification.class_variable_set(:@@stubs, nil) end + def test_self_stubs_for_lazy_loading + Gem.loaded_specs.clear + Gem::Specification.class_variable_set(:@@stubs, nil) + + dir_standard_specs = File.join Gem.dir, 'specifications' + + save_gemspec('a-1', '1', dir_standard_specs){|s| s.name = 'a' } + save_gemspec('b-1', '1', dir_standard_specs){|s| s.name = 'b' } + + assert_equal ['a-1'], Gem::Specification.stubs_for('a').map { |s| s.full_name } + assert_equal 1, Gem::Specification.class_variable_get(:@@stubs_by_name).length + assert_equal ['b-1'], Gem::Specification.stubs_for('b').map { |s| s.full_name } + assert_equal 2, Gem::Specification.class_variable_get(:@@stubs_by_name).length + + Gem.loaded_specs.delete 'a' + Gem.loaded_specs.delete 'b' + Gem::Specification.class_variable_set(:@@stubs, nil) + end + def test_self_stubs_for_mult_platforms # gems for two different platforms are installed with --user-install # the correct one should be returned in the array |