summaryrefslogtreecommitdiff
path: root/lib/rubygems
diff options
context:
space:
mode:
authorHiroshi SHIBATA <hsbt@ruby-lang.org>2021-02-09 22:53:57 +0900
committerGitHub <noreply@github.com>2021-02-09 22:53:57 +0900
commit09c681ab38df33468570534bef7609222e49c6f4 (patch)
tree52f9edbbb1d0c984e370d2ae35729a16e51890b8 /lib/rubygems
parent9aba46d8d80473594e567dff1652626e7b2a77b0 (diff)
Merge RubyGems 3.2.9 and Bundler 2.2.9 (#4158)
Diffstat (limited to 'lib/rubygems')
-rw-r--r--lib/rubygems/dependency.rb6
-rw-r--r--lib/rubygems/resolver/index_specification.rb5
-rw-r--r--lib/rubygems/resolver/molinillo/lib/molinillo/delegates/specification_provider.rb7
-rw-r--r--lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb1
-rw-r--r--lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb14
-rw-r--r--lib/rubygems/resolver/molinillo/lib/molinillo/errors.rb2
-rw-r--r--lib/rubygems/resolver/molinillo/lib/molinillo/modules/specification_provider.rb11
-rw-r--r--lib/rubygems/resolver/molinillo/lib/molinillo/resolution.rb18
-rw-r--r--lib/rubygems/specification.rb21
-rw-r--r--lib/rubygems/test_case.rb11
10 files changed, 64 insertions, 32 deletions
diff --git a/lib/rubygems/dependency.rb b/lib/rubygems/dependency.rb
index 68f3e3d991..3721204ab2 100644
--- a/lib/rubygems/dependency.rb
+++ b/lib/rubygems/dependency.rb
@@ -277,7 +277,7 @@ class Gem::Dependency
requirement.satisfied_by?(spec.version) && env_req.satisfied_by?(spec.version)
end.map(&:to_spec)
- Gem::BundlerVersionFinder.filter!(matches) if name == "bundler".freeze && !requirement.specific?
+ Gem::BundlerVersionFinder.filter!(matches) if filters_bundler?
if platform_only
matches.reject! do |spec|
@@ -295,6 +295,10 @@ class Gem::Dependency
@requirement.specific?
end
+ def filters_bundler?
+ name == "bundler".freeze && !specific?
+ end
+
def to_specs
matches = matching_specs true
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]))
diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb
index 4e1a3a3801..73062afe53 100644
--- a/lib/rubygems/specification.rb
+++ b/lib/rubygems/specification.rb
@@ -827,7 +827,9 @@ class Gem::Specification < Gem::BasicSpecification
if @@stubs
@@stubs_by_name[name] || []
else
- @@stubs_by_name[name] ||= stubs_for_pattern("#{name}-*.gemspec")
+ @@stubs_by_name[name] ||= stubs_for_pattern("#{name}-*.gemspec").select do |s|
+ s.name == name
+ end
end
end
@@ -848,7 +850,9 @@ class Gem::Specification < Gem::BasicSpecification
specs.sort! do |a, b|
names = a.name <=> b.name
next names if names.nonzero?
- b.version <=> a.version
+ versions = b.version <=> a.version
+ next versions if versions.nonzero?
+ b.platform == Gem::Platform::RUBY ? -1 : 1
end
end
@@ -1084,20 +1088,15 @@ class Gem::Specification < Gem::BasicSpecification
end
def self._latest_specs(specs, prerelease = false) # :nodoc:
- result = Hash.new {|h,k| h[k] = {} }
- native = {}
+ result = {}
specs.reverse_each do |spec|
next if spec.version.prerelease? unless prerelease
- native[spec.name] = spec.version if spec.platform == Gem::Platform::RUBY
- result[spec.name][spec.platform] = spec
+ result[spec.name] = spec
end
- result.map(&:last).map(&:values).flatten.reject do |spec|
- minimum = native[spec.name]
- minimum && spec.version < minimum
- end.sort_by{|tup| tup.name }
+ result.map(&:last).flatten.sort_by{|tup| tup.name }
end
##
@@ -2552,7 +2551,7 @@ class Gem::Specification < Gem::BasicSpecification
begin
dependencies.each do |dep|
next unless dep.runtime?
- dep.to_specs.each do |dep_spec|
+ dep.matching_specs(true).each do |dep_spec|
next if visited.has_key?(dep_spec)
visited[dep_spec] = true
trail.push(dep_spec)
diff --git a/lib/rubygems/test_case.rb b/lib/rubygems/test_case.rb
index 0f3791f03d..e2763561c6 100644
--- a/lib/rubygems/test_case.rb
+++ b/lib/rubygems/test_case.rb
@@ -311,7 +311,7 @@ class Gem::TestCase < Minitest::Test
ENV['XDG_CONFIG_HOME'] = nil
ENV['XDG_DATA_HOME'] = nil
ENV['SOURCE_DATE_EPOCH'] = nil
- ENV["TMPDIR"] = @tmp
+ ENV['BUNDLER_VERSION'] = nil
@current_dir = Dir.pwd
@fetcher = nil
@@ -322,13 +322,10 @@ class Gem::TestCase < Minitest::Test
# capture output
Gem::DefaultUserInteraction.ui = Gem::MockGemUi.new
- tmpdir = File.realpath Dir.tmpdir
- tmpdir.tap(&Gem::UNTAINT)
-
- @tempdir = File.join(tmpdir, "test_rubygems_#{$$}")
+ @tempdir = Dir.mktmpdir("test_rubygems_", @tmp)
@tempdir.tap(&Gem::UNTAINT)
- FileUtils.mkdir_p @tempdir
+ ENV["TMPDIR"] = @tempdir
@orig_SYSTEM_WIDE_CONFIG_FILE = Gem::ConfigFile::SYSTEM_WIDE_CONFIG_FILE
Gem::ConfigFile.send :remove_const, :SYSTEM_WIDE_CONFIG_FILE
@@ -367,7 +364,9 @@ class Gem::TestCase < Minitest::Test
Dir.chdir @tempdir
ENV['HOME'] = @userhome
+ Gem.instance_variable_set :@config_file, nil
Gem.instance_variable_set :@user_home, nil
+ Gem.instance_variable_set :@config_home, nil
Gem.instance_variable_set :@data_home, nil
Gem.instance_variable_set :@gemdeps, nil
Gem.instance_variable_set :@env_requirements_by_name, nil