[rubygems/rubygems] Share gem not found logic with transitive dependencies too

https://github.com/rubygems/rubygems/commit/e4a1a9663d
This commit is contained in:
David Rodríguez 2021-12-15 12:41:28 +01:00 коммит произвёл git
Родитель f3b50507c7
Коммит 1537471871
2 изменённых файлов: 53 добавлений и 30 удалений

Просмотреть файл

@ -263,30 +263,34 @@ module Bundler
"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
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])}',"
end
o << " "
o << if metadata_requirement
"is not available in #{relevant_source}"
extra_message = if conflict.requirement_trees.first.size > 1
", which is required by gem '#{SharedHelpers.pretty_dependency(conflict.requirement_trees.first[-2])}',"
else
"in #{relevant_source}.\n"
""
end
if metadata_requirement
o << "#{SharedHelpers.pretty_dependency(conflict.requirement)}#{extra_message} is not available in #{relevant_source}"
else
o << gem_not_found_message(name, conflict.requirement, relevant_source, extra_message)
end
end
end,

Просмотреть файл

@ -302,6 +302,27 @@ RSpec.describe "bundle install with specific platforms" do
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