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

ruby-changes:70275

From: David <ko1@a...>
Date: Fri, 17 Dec 2021 16:35:39 +0900 (JST)
Subject: [ruby-changes:70275] 1537471871 (master): [rubygems/rubygems] Share gem not found logic with transitive dependencies too

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

From 1537471871f9a06624689b55be222f0ea601d140 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?David=20Rodr=C3=ADguez?= <deivid.rodriguez@r...>
Date: Wed, 15 Dec 2021 12:41:28 +0100
Subject: [rubygems/rubygems] Share gem not found logic with transitive
 dependencies too

https://github.com/rubygems/rubygems/commit/e4a1a9663d
---
 lib/bundler/resolver.rb                            | 58 +++++++++++-----------
 .../install/gemfile/specific_platform_spec.rb      | 21 ++++++++
 2 files changed, 51 insertions(+), 28 deletions(-)

diff --git a/lib/bundler/resolver.rb b/lib/bundler/resolver.rb
index bccc374e9f2..37c27f213d0 100644
--- a/lib/bundler/resolver.rb
+++ b/lib/bundler/resolver.rb
@@ -263,30 +263,34 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/resolver.rb#L263
             "If you are updating multiple gems in your Gemfile at once,\n" \
             "try passing them all to `bundle update`"
         else
-          source = source_for(name)
-          specs = source.specs.search(name)
-          matching_part = name
-          requirement_label = SharedHelpers.pretty_dependency(requirement)
-          cache_message = begin
-                              " or in gems cached in #{Bundler.settings.app_cache_path}" if Bundler.app_cache.exist?
-                            rescue GemfileNotFound
-                              nil
-                            end
-          specs_matching_requirement = specs.select {| spec| requirement.matches_spec?(spec) }
-
-          if specs_matching_requirement.any?
-            specs = specs_matching_requirement
-            matching_part = requirement_label
-            requirement_label = "#{requirement_label} #{requirement.__platform}"
-          end
-
-          message = String.new("Could not find gem '#{requirement_label}' in #{source}#{cache_message}.\n")
-          message << "The source contains the following gems matching '#{matching_part}': #{specs.map(&:full_name).join(", ")}" if specs.any?
+          message = gem_not_found_message(name, requirement, source_for(name))
         end
         raise GemNotFound, message
       end
     end
 
+    def gem_not_found_message(name, requirement, source, extra_message = "")
+      specs = source.specs.search(name)
+      matching_part = name
+      requirement_label = SharedHelpers.pretty_dependency(requirement)
+      cache_message = begin
+                          " or in gems cached in #{Bundler.settings.app_cache_path}" if Bundler.app_cache.exist?
+                        rescue GemfileNotFound
+                          nil
+                        end
+      specs_matching_requirement = specs.select {| spec| requirement.matches_spec?(spec) }
+
+      if specs_matching_requirement.any?
+        specs = specs_matching_requirement
+        matching_part = requirement_label
+        requirement_label = "#{requirement_label} #{requirement.__platform}"
+      end
+
+      message = String.new("Could not find gem '#{requirement_label}'#{extra_message} in #{source}#{cache_message}.\n")
+      message << "The source contains the following gems matching '#{matching_part}': #{specs.map(&:full_name).join(", ")}" if specs.any?
+      message
+    end
+
     def version_conflict_message(e)
       # only show essential conflicts, if possible
       conflicts = e.conflicts.dup
@@ -356,18 +360,16 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/resolver.rb#L360
 
             metadata_requirement = name.end_with?("\0")
 
-            o << "Could not find gem '" unless metadata_requirement
-            o << SharedHelpers.pretty_dependency(conflict.requirement)
-            o << "'" unless metadata_requirement
-            if conflict.requirement_trees.first.size > 1
-              o << ", which is required by gem '#{SharedHelpers.pretty_dependency(conflict.requirement_trees.first[-2])}',"
+            extra_message = if conflict.requirement_trees.first.size > 1
+              ", which is required by gem '#{SharedHelpers.pretty_dependency(conflict.requirement_trees.first[-2])}',"
+            else
+              ""
             end
-            o << " "
 
-            o << if metadata_requirement
-              "is not available in #{relevant_source}"
+            if metadata_requirement
+              o << "#{SharedHelpers.pretty_dependency(conflict.requirement)}#{extra_message} is not available in #{relevant_source}"
             else
-              "in #{relevant_source}.\n"
+              o << gem_not_found_message(name, conflict.requirement, relevant_source, extra_message)
             end
           end
         end,
diff --git a/spec/bundler/install/gemfile/specific_platform_spec.rb b/spec/bundler/install/gemfile/specific_platform_spec.rb
index 3acc29041e3..6035f55ef27 100644
--- a/spec/bundler/install/gemfile/specific_platform_spec.rb
+++ b/spec/bundler/install/gemfile/specific_platform_spec.rb
@@ -302,6 +302,27 @@ RSpec.describe "bundle install with specific platforms" do https://github.com/ruby/ruby/blob/trunk/spec/bundler/install/gemfile/specific_platform_spec.rb#L302
     expect(err).to include("The source contains the following gems matching 'sorbet-static (= 0.5.6433)': sorbet-static-0.5.6433-universal-darwin-20, sorbet-static-0.5.6433-x86_64-linux")
   end
 
+  it "does not resolve if the current platform does not match any of available platform specific variants for a transitive dependency" do
+    build_repo2 do
+      build_gem("sorbet", "0.5.6433") {|s| s.add_dependency "sorbet-static", "= 0.5.6433" }
+      build_gem("sorbet-static", "0.5.6433") {|s| s.platform = "x86_64-linux" }
+      build_gem("sorbet-static", "0.5.6433") {|s| s.platform = "universal-darwin-20" }
+    end
+
+    gemfile <<~G
+      source "#{file_uri_for(gem_repo2)}"
+
+      gem "sorbet", "0.5.6433"
+    G
+
+    simulate_platform "arm64-darwin-21" do
+      bundle "install", :raise_on_error => false
+    end
+
+    expect(err).to include("Could not find gem 'sorbet-static (= 0.5.6433) arm64-darwin-21', which is required by gem 'sorbet (= 0.5.6433)', in rubygems repository #{file_uri_for(gem_repo2)}/ or installed locally.")
+    expect(err).to include("The source contains the following gems matching 'sorbet-static (= 0.5.6433)': sorbet-static-0.5.6433-universal-darwin-20, sorbet-static-0.5.6433-x86_64-linux")
+  end
+
   private
 
   def setup_multiplatform_gem
-- 
cgit v1.2.1


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

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