1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[rubygems/rubygems] Memoize materialized specs when requiring bundler/setup

Calling `Bundler.definition.specs` will memoize materialized specs.
However, requiring `bundler/setup` will end up materializing the same
set of specs, but not memoize them.

This change makes things consistent.

https://github.com/rubygems/rubygems/commit/e4c2b52824
This commit is contained in:
David Rodríguez 2021-10-28 09:51:14 +02:00 committed by git
parent 13a9597c7c
commit 4e7e057692
2 changed files with 21 additions and 4 deletions

View file

@ -143,7 +143,7 @@ module Bundler
@dependency_changes = converge_dependencies
@local_changes = converge_locals
@locked_specs_incomplete_for_platform = !@locked_specs.for(expand_dependencies(requested_dependencies & locked_dependencies), true, true)
@locked_specs_incomplete_for_platform = !@locked_specs.for(requested_dependencies & expand_dependencies(locked_dependencies), true, true)
@requires = compute_requires
end
@ -239,16 +239,17 @@ module Bundler
end
def specs_for(groups)
groups = requested_groups if groups.empty?
return specs if groups.empty?
deps = dependencies_for(groups)
materialize(expand_dependencies(deps))
materialize(deps)
end
def dependencies_for(groups)
groups.map!(&:to_sym)
current_dependencies.reject do |d|
deps = current_dependencies.reject do |d|
(d.groups & groups).empty?
end
expand_dependencies(deps)
end
# Resolve all the dependencies specified in Gemfile. It ensures that

View file

@ -1468,5 +1468,21 @@ end
expect(last_command.stdboth).to eq("true")
end
it "memoizes initial set of specs when requiring bundler/setup, so that even if further code mutates dependencies, Bundler.definition.specs is not affected" do
install_gemfile <<~G
source "#{file_uri_for(gem_repo1)}"
gem "yard"
gem "rack", :group => :test
G
ruby <<-RUBY, :raise_on_error => false
require "bundler/setup"
Bundler.require(:test).select! {|d| (d.groups & [:test]).any? }
puts Bundler.definition.specs.map(&:name).join(", ")
RUBY
expect(out).to include("rack, yard")
end
end
end