[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:
parent
13a9597c7c
commit
4e7e057692
@ -143,7 +143,7 @@ module Bundler
|
|||||||
@dependency_changes = converge_dependencies
|
@dependency_changes = converge_dependencies
|
||||||
@local_changes = converge_locals
|
@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
|
@requires = compute_requires
|
||||||
end
|
end
|
||||||
@ -239,16 +239,17 @@ module Bundler
|
|||||||
end
|
end
|
||||||
|
|
||||||
def specs_for(groups)
|
def specs_for(groups)
|
||||||
groups = requested_groups if groups.empty?
|
return specs if groups.empty?
|
||||||
deps = dependencies_for(groups)
|
deps = dependencies_for(groups)
|
||||||
materialize(expand_dependencies(deps))
|
materialize(deps)
|
||||||
end
|
end
|
||||||
|
|
||||||
def dependencies_for(groups)
|
def dependencies_for(groups)
|
||||||
groups.map!(&:to_sym)
|
groups.map!(&:to_sym)
|
||||||
current_dependencies.reject do |d|
|
deps = current_dependencies.reject do |d|
|
||||||
(d.groups & groups).empty?
|
(d.groups & groups).empty?
|
||||||
end
|
end
|
||||||
|
expand_dependencies(deps)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Resolve all the dependencies specified in Gemfile. It ensures that
|
# Resolve all the dependencies specified in Gemfile. It ensures that
|
||||||
|
@ -1468,5 +1468,21 @@ end
|
|||||||
|
|
||||||
expect(last_command.stdboth).to eq("true")
|
expect(last_command.stdboth).to eq("true")
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user