diff options
author | David RodrÃguez <[email protected]> | 2021-02-01 16:17:16 +0100 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2021-03-08 13:47:35 +0900 |
commit | 53468cc11147b0d285fc376fc546b677dad600ca (patch) | |
tree | eb9c97f544d089be2d324126b025b11f41a22c90 /lib/rubygems/resolver | |
parent | 2ab6b7a7516e1b2c48a66ce513afabb62d101461 (diff) |
Sync latest development version of bundler & rubygems
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/4143
Diffstat (limited to 'lib/rubygems/resolver')
7 files changed, 44 insertions, 14 deletions
diff --git a/lib/rubygems/resolver/index_specification.rb b/lib/rubygems/resolver/index_specification.rb index 2aa6b419ba..9ea76f40ba 100644 --- a/lib/rubygems/resolver/index_specification.rb +++ b/lib/rubygems/resolver/index_specification.rb @@ -35,9 +35,12 @@ class Gem::Resolver::IndexSpecification < Gem::Resolver::Specification ## # The required_ruby_version constraint for this specification + # + # A fallback is included because when generated, some marshalled specs have it + # set to +nil+. def required_ruby_version - spec.required_ruby_version + spec.required_ruby_version || Gem::Requirement.default end ## diff --git a/lib/rubygems/resolver/molinillo/lib/molinillo/delegates/specification_provider.rb b/lib/rubygems/resolver/molinillo/lib/molinillo/delegates/specification_provider.rb index 2ddb0ac426..b765226fb0 100644 --- a/lib/rubygems/resolver/molinillo/lib/molinillo/delegates/specification_provider.rb +++ b/lib/rubygems/resolver/molinillo/lib/molinillo/delegates/specification_provider.rb @@ -26,6 +26,13 @@ module Gem::Resolver::Molinillo end end + # (see Gem::Resolver::Molinillo::SpecificationProvider#dependencies_equal?) + def dependencies_equal?(dependencies, other_dependencies) + with_no_such_dependency_error_handling do + specification_provider.dependencies_equal?(dependencies, other_dependencies) + end + end + # (see Gem::Resolver::Molinillo::SpecificationProvider#name_for) def name_for(dependency) with_no_such_dependency_error_handling do diff --git a/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb b/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb index 773bb3417f..16430a79f5 100644 --- a/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb +++ b/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true -require 'set' require 'tsort' require_relative 'dependency_graph/log' diff --git a/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb b/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb index f4cc333dd1..77114951b2 100644 --- a/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb +++ b/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb @@ -59,7 +59,7 @@ module Gem::Resolver::Molinillo # @param [Set<Vertex>] vertices the set to add the predecessors to # @return [Set<Vertex>] the vertices of {#graph} where `self` is a # {#descendent?} - def _recursive_predecessors(vertices = Set.new) + def _recursive_predecessors(vertices = new_vertex_set) incoming_edges.each do |edge| vertex = edge.origin next unless vertices.add?(vertex) @@ -85,7 +85,7 @@ module Gem::Resolver::Molinillo # @param [Set<Vertex>] vertices the set to add the successors to # @return [Set<Vertex>] the vertices of {#graph} where `self` is an # {#ancestor?} - def _recursive_successors(vertices = Set.new) + def _recursive_successors(vertices = new_vertex_set) outgoing_edges.each do |edge| vertex = edge.destination next unless vertices.add?(vertex) @@ -138,7 +138,7 @@ module Gem::Resolver::Molinillo # @param [Vertex] other the vertex to check if there's a path to # @param [Set<Vertex>] visited the vertices of {#graph} that have been visited # @return [Boolean] whether there is a path to `other` from `self` - def _path_to?(other, visited = Set.new) + def _path_to?(other, visited = new_vertex_set) return false unless visited.add?(self) return true if equal?(other) successors.any? { |v| v._path_to?(other, visited) } @@ -147,12 +147,18 @@ module Gem::Resolver::Molinillo # Is there a path from `other` to `self` following edges in the # dependency graph? - # @return true iff there is a path following edges within this {#graph} + # @return whether there is a path following edges within this {#graph} def ancestor?(other) other.path_to?(self) end alias is_reachable_from? ancestor? + + def new_vertex_set + require 'set' + Set.new + end + private :new_vertex_set end end end diff --git a/lib/rubygems/resolver/molinillo/lib/molinillo/errors.rb b/lib/rubygems/resolver/molinillo/lib/molinillo/errors.rb index a6e182e84d..ada03a901c 100644 --- a/lib/rubygems/resolver/molinillo/lib/molinillo/errors.rb +++ b/lib/rubygems/resolver/molinillo/lib/molinillo/errors.rb @@ -121,7 +121,7 @@ module Gem::Resolver::Molinillo t = ''.dup depth = 2 tree.each do |req| - t << ' ' * depth << req.to_s + t << ' ' * depth << printable_requirement.call(req) unless tree.last == req if spec = conflict.activated_by_name[name_for(req)] t << %( was resolved to #{version_for_spec.call(spec)}, which) diff --git a/lib/rubygems/resolver/molinillo/lib/molinillo/modules/specification_provider.rb b/lib/rubygems/resolver/molinillo/lib/molinillo/modules/specification_provider.rb index a44b9c0d5d..9448dc7bf3 100644 --- a/lib/rubygems/resolver/molinillo/lib/molinillo/modules/specification_provider.rb +++ b/lib/rubygems/resolver/molinillo/lib/molinillo/modules/specification_provider.rb @@ -45,6 +45,17 @@ module Gem::Resolver::Molinillo true end + # Determines whether two arrays of dependencies are equal, and thus can be + # grouped. + # + # @param [Array<Object>] dependencies + # @param [Array<Object>] other_dependencies + # @return [Boolean] whether `dependencies` and `other_dependencies` should + # be considered equal. + def dependencies_equal?(dependencies, other_dependencies) + dependencies == other_dependencies + end + # Returns the name for the given `dependency`. # @note This method should be 'pure', i.e. the return value should depend # only on the `dependency` parameter. diff --git a/lib/rubygems/resolver/molinillo/lib/molinillo/resolution.rb b/lib/rubygems/resolver/molinillo/lib/molinillo/resolution.rb index f1c60ec544..8b40e59e42 100644 --- a/lib/rubygems/resolver/molinillo/lib/molinillo/resolution.rb +++ b/lib/rubygems/resolver/molinillo/lib/molinillo/resolution.rb @@ -329,11 +329,11 @@ module Gem::Resolver::Molinillo # Look for past conflicts that could be unwound to affect the # requirement tree for the current conflict + all_reqs = last_detail_for_current_unwind.all_requirements + all_reqs_size = all_reqs.size relevant_unused_unwinds = unused_unwind_options.select do |alternative| - intersecting_requirements = - last_detail_for_current_unwind.all_requirements & - alternative.requirements_unwound_to_instead - next if intersecting_requirements.empty? + diff_reqs = all_reqs - alternative.requirements_unwound_to_instead + next if diff_reqs.size == all_reqs_size # Find the highest index unwind whilst looping through current_detail = alternative if alternative > current_detail alternative @@ -344,8 +344,12 @@ module Gem::Resolver::Molinillo state.unused_unwind_options += unwind_details.reject { |detail| detail.state_index == -1 } # Update the requirements_unwound_to_instead on any relevant unused unwinds - relevant_unused_unwinds.each { |d| d.requirements_unwound_to_instead << current_detail.state_requirement } - unwind_details.each { |d| d.requirements_unwound_to_instead << current_detail.state_requirement } + relevant_unused_unwinds.each do |d| + (d.requirements_unwound_to_instead << current_detail.state_requirement).uniq! + end + unwind_details.each do |d| + (d.requirements_unwound_to_instead << current_detail.state_requirement).uniq! + end current_detail end @@ -803,7 +807,7 @@ module Gem::Resolver::Molinillo possibilities.reverse_each do |possibility| dependencies = dependencies_for(possibility) - if current_possibility_set && current_possibility_set.dependencies == dependencies + if current_possibility_set && dependencies_equal?(current_possibility_set.dependencies, dependencies) current_possibility_set.possibilities.unshift(possibility) else possibility_sets.unshift(PossibilitySet.new(dependencies, [possibility])) |