diff options
Diffstat (limited to 'lib/rubygems/resolver.rb')
-rw-r--r-- | lib/rubygems/resolver.rb | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/lib/rubygems/resolver.rb b/lib/rubygems/resolver.rb index 50a547e1be..a7b11179c8 100644 --- a/lib/rubygems/resolver.rb +++ b/lib/rubygems/resolver.rb @@ -4,9 +4,6 @@ require 'rubygems/exceptions' require 'rubygems/util' require 'rubygems/util/list' -require 'uri' -require 'net/http' - ## # Given a set of Gem::Dependency objects as +needed+ and a way to query the # set of available specs via +set+, calculates a set of ActivationRequest @@ -256,6 +253,44 @@ class Gem::Resolver @soft_missing end + def sort_dependencies(dependencies, activated, conflicts) + dependencies.sort_by do |dependency| + name = name_for(dependency) + [ + activated.vertex_named(name).payload ? 0 : 1, + amount_constrained(dependency), + conflicts[name] ? 0 : 1, + activated.vertex_named(name).payload ? 0 : search_for(dependency).count, + ] + end + end + + SINGLE_POSSIBILITY_CONSTRAINT_PENALTY = 1_000_000 + private_constant :SINGLE_POSSIBILITY_CONSTRAINT_PENALTY if defined?(private_constant) + + # returns an integer \in (-\infty, 0] + # a number closer to 0 means the dependency is less constraining + # + # dependencies w/ 0 or 1 possibilities (ignoring version requirements) + # are given very negative values, so they _always_ sort first, + # before dependencies that are unconstrained + def amount_constrained(dependency) + @amount_constrained ||= {} + @amount_constrained[dependency.name] ||= begin + name_dependency = Gem::Dependency.new(dependency.name) + dependency_request_for_name = Gem::Resolver::DependencyRequest.new(name_dependency, dependency.requester) + all = @set.find_all(dependency_request_for_name).size + + if all <= 1 + all - SINGLE_POSSIBILITY_CONSTRAINT_PENALTY + else + search = search_for(dependency).size + search - all + end + end + end + private :amount_constrained + end ## |