[前][次][番号順一覧][スレッド一覧]

ruby-changes:69549

From: David <ko1@a...>
Date: Mon, 1 Nov 2021 02:02:03 +0900 (JST)
Subject: [ruby-changes:69549] 4e7e057692 (master): [rubygems/rubygems] Memoize materialized specs when requiring `bundler/setup`

https://git.ruby-lang.org/ruby.git/commit/?id=4e7e057692

From 4e7e057692578204a6fb2f7170bb8c5803f0f9e0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?David=20Rodr=C3=ADguez?= <deivid.rodriguez@r...>
Date: Thu, 28 Oct 2021 09:51:14 +0200
Subject: [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
---
 lib/bundler/definition.rb          |  9 +++++----
 spec/bundler/runtime/setup_spec.rb | 16 ++++++++++++++++
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb
index da180ce255d..1bb26b68783 100644
--- a/lib/bundler/definition.rb
+++ b/lib/bundler/definition.rb
@@ -143,7 +143,7 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/definition.rb#L143
       @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 https://github.com/ruby/ruby/blob/trunk/lib/bundler/definition.rb#L239
     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
diff --git a/spec/bundler/runtime/setup_spec.rb b/spec/bundler/runtime/setup_spec.rb
index b35b7a233ca..3cf373fe1ca 100644
--- a/spec/bundler/runtime/setup_spec.rb
+++ b/spec/bundler/runtime/setup_spec.rb
@@ -1468,5 +1468,21 @@ end https://github.com/ruby/ruby/blob/trunk/spec/bundler/runtime/setup_spec.rb#L1468
 
       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
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]