summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorHiroshi SHIBATA <[email protected]>2022-10-18 15:24:42 +0900
committerHiroshi SHIBATA <[email protected]>2022-10-18 16:33:15 +0900
commitf5df47d1f3ec403d057f823375f1dfeea711caa6 (patch)
tree36e71c46bedd695fe96ab2ff12a0e6c046e836a2 /lib
parent2ab7bb8969ca76d49a6c2043f423a3646b20d1f7 (diff)
Merge RubyGems/Bundler master
https://github.com/rubygems/rubygems/commit/6214d00b2315ed37c76b1fbc1c72f61f92ba5a65
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/6578
Diffstat (limited to 'lib')
-rw-r--r--lib/bundler.rb1
-rw-r--r--lib/bundler/definition.rb10
-rw-r--r--lib/bundler/dep_proxy.rb55
-rw-r--r--lib/bundler/endpoint_specification.rb4
-rw-r--r--lib/bundler/index.rb1
-rw-r--r--lib/bundler/lazy_specification.rb9
-rw-r--r--lib/bundler/remote_specification.rb8
-rw-r--r--lib/bundler/resolver.rb76
-rw-r--r--lib/bundler/resolver/base.rb2
-rw-r--r--lib/bundler/resolver/spec_group.rb52
10 files changed, 54 insertions, 164 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb
index dc88bbdcb9..1a94e0c963 100644
--- a/lib/bundler.rb
+++ b/lib/bundler.rb
@@ -41,7 +41,6 @@ module Bundler
autoload :Definition, File.expand_path("bundler/definition", __dir__)
autoload :Dependency, File.expand_path("bundler/dependency", __dir__)
- autoload :DepProxy, File.expand_path("bundler/dep_proxy", __dir__)
autoload :Deprecate, File.expand_path("bundler/deprecate", __dir__)
autoload :Digest, File.expand_path("bundler/digest", __dir__)
autoload :Dsl, File.expand_path("bundler/dsl", __dir__)
diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb
index a3042e06a3..95be7a7e27 100644
--- a/lib/bundler/definition.rb
+++ b/lib/bundler/definition.rb
@@ -479,7 +479,7 @@ module Bundler
end
def expanded_dependencies
- @expanded_dependencies ||= expand_dependencies(dependencies + metadata_dependencies)
+ @expanded_dependencies ||= dependencies + metadata_dependencies
end
def filter_specs(specs, deps)
@@ -791,14 +791,6 @@ module Bundler
]
end
- def expand_dependencies(dependencies)
- dependencies.flat_map do |dep|
- dep.gem_platforms(@platforms).map do |p|
- DepProxy.get_proxy(dep, p)
- end
- end
- end
-
def source_requirements
# Record the specs available in each gem's source, so that those
# specs will be available later when the resolver knows where to
diff --git a/lib/bundler/dep_proxy.rb b/lib/bundler/dep_proxy.rb
deleted file mode 100644
index a32dc37b49..0000000000
--- a/lib/bundler/dep_proxy.rb
+++ /dev/null
@@ -1,55 +0,0 @@
-# frozen_string_literal: true
-
-module Bundler
- class DepProxy
- attr_reader :__platform, :dep
-
- @proxies = {}
-
- def self.get_proxy(dep, platform)
- @proxies[[dep, platform]] ||= new(dep, platform).freeze
- end
-
- def initialize(dep, platform)
- @dep = dep
- @__platform = platform
- end
-
- private_class_method :new
-
- alias_method :eql?, :==
-
- def type
- @dep.type
- end
-
- def name
- @dep.name
- end
-
- def requirement
- @dep.requirement
- end
-
- def to_s
- s = name.dup
- s << " (#{requirement})" unless requirement == Gem::Requirement.default
- s << " #{__platform}" unless __platform == Gem::Platform::RUBY
- s
- end
-
- def dup
- raise NoMethodError.new("DepProxy cannot be duplicated")
- end
-
- def clone
- raise NoMethodError.new("DepProxy cannot be cloned")
- end
-
- private
-
- def method_missing(*args, &blk)
- @dep.send(*args, &blk)
- end
- end
-end
diff --git a/lib/bundler/endpoint_specification.rb b/lib/bundler/endpoint_specification.rb
index 863544b1f9..d315d1cc68 100644
--- a/lib/bundler/endpoint_specification.rb
+++ b/lib/bundler/endpoint_specification.rb
@@ -26,6 +26,10 @@ module Bundler
@platform
end
+ def identifier
+ @__identifier ||= [name, version, platform.to_s]
+ end
+
# needed for standalone, load required_paths from local gemspec
# after the gem is installed
def require_paths
diff --git a/lib/bundler/index.rb b/lib/bundler/index.rb
index d3743adb68..ed16c90a3a 100644
--- a/lib/bundler/index.rb
+++ b/lib/bundler/index.rb
@@ -71,7 +71,6 @@ module Bundler
when Gem::Specification, RemoteSpecification, LazySpecification, EndpointSpecification then search_by_spec(query)
when String then specs_by_name(query)
when Gem::Dependency then search_by_dependency(query)
- when DepProxy then search_by_dependency(query.dep)
else
raise "You can't search for a #{query.inspect}."
end
diff --git a/lib/bundler/lazy_specification.rb b/lib/bundler/lazy_specification.rb
index 7100d822b4..f5fe2e64ae 100644
--- a/lib/bundler/lazy_specification.rb
+++ b/lib/bundler/lazy_specification.rb
@@ -120,7 +120,7 @@ module Bundler
end
def identifier
- @__identifier ||= [name, version, platform_string]
+ @__identifier ||= [name, version, platform.to_s]
end
def git_version
@@ -128,13 +128,6 @@ module Bundler
" #{source.revision[0..6]}"
end
- protected
-
- def platform_string
- platform_string = platform.to_s
- platform_string == Index::RUBY ? Index::NULL : platform_string
- end
-
private
def to_ary
diff --git a/lib/bundler/remote_specification.rb b/lib/bundler/remote_specification.rb
index 601957746f..34d7fd116c 100644
--- a/lib/bundler/remote_specification.rb
+++ b/lib/bundler/remote_specification.rb
@@ -29,11 +29,15 @@ module Bundler
@platform = _remote_specification.platform
end
+ def identifier
+ @__identifier ||= [name, version, @platform.to_s]
+ end
+
def full_name
- if @original_platform == Gem::Platform::RUBY
+ if @platform == Gem::Platform::RUBY
"#{@name}-#{@version}"
else
- "#{@name}-#{@version}-#{@original_platform}"
+ "#{@name}-#{@version}-#{@platform}"
end
end
diff --git a/lib/bundler/resolver.rb b/lib/bundler/resolver.rb
index 80ad39e896..115c5cfcc4 100644
--- a/lib/bundler/resolver.rb
+++ b/lib/bundler/resolver.rb
@@ -8,22 +8,6 @@ module Bundler
include GemHelpers
- # Figures out the best possible configuration of gems that satisfies
- # the list of passed dependencies and any child dependencies without
- # causing any gem activation errors.
- #
- # ==== Parameters
- # *dependencies<Gem::Dependency>:: The list of dependencies to resolve
- #
- # ==== Returns
- # <GemBundle>,nil:: If the list of dependencies can be resolved, a
- # collection of gemspecs is returned. Otherwise, nil is returned.
- def self.resolve(requirements, source_requirements = {}, base = [], gem_version_promoter = GemVersionPromoter.new, additional_base_requirements = [], platforms = nil)
- base = SpecSet.new(base) unless base.is_a?(SpecSet)
- resolver = new(source_requirements, base, gem_version_promoter, additional_base_requirements, platforms)
- resolver.start(requirements)
- end
-
def initialize(source_requirements, base, gem_version_promoter, additional_base_requirements, platforms)
@source_requirements = source_requirements
@base = Resolver::Base.new(base, additional_base_requirements)
@@ -116,41 +100,35 @@ module Bundler
specification.dependencies_for_activated_platforms
end
- def search_for(dependency_proxy)
- platform = dependency_proxy.__platform
- dependency = dependency_proxy.dep
- name = dependency.name
- @search_for[dependency_proxy] ||= begin
+ def search_for(dependency)
+ @search_for[dependency] ||= begin
+ name = dependency.name
locked_results = @base[name].select {|spec| requirement_satisfied_by?(dependency, nil, spec) }
locked_requirement = base_requirements[name]
results = results_for(dependency) + locked_results
results = results.select {|spec| requirement_satisfied_by?(locked_requirement, nil, spec) } if locked_requirement
+ dep_platforms = dependency.gem_platforms(@platforms)
- if results.any?
- results = @gem_version_promoter.sort_versions(dependency, results)
+ @gem_version_promoter.sort_versions(dependency, results).group_by(&:version).reduce([]) do |groups, (_, specs)|
+ relevant_platforms = dep_platforms.select {|platform| specs.any? {|spec| spec.match_platform(platform) } }
+ next groups unless relevant_platforms.any?
- results.group_by(&:version).reduce([]) do |groups, (_, specs)|
- next groups unless specs.any? {|spec| spec.match_platform(platform) }
-
- specs_by_platform = Hash.new do |current_specs, current_platform|
- current_specs[current_platform] = select_best_platform_match(specs, current_platform)
- end
+ ruby_specs = select_best_platform_match(specs, Gem::Platform::RUBY)
+ if ruby_specs.any?
+ spec_group_ruby = SpecGroup.new(ruby_specs, [Gem::Platform::RUBY])
+ spec_group_ruby.force_ruby_platform = dependency.force_ruby_platform
+ groups << spec_group_ruby
+ end
- if specs_by_platform[Gem::Platform::RUBY].any?
- spec_group_ruby = SpecGroup.create_for(specs_by_platform, [Gem::Platform::RUBY])
- spec_group_ruby.force_ruby_platform = dependency.force_ruby_platform
- groups << spec_group_ruby
- end
+ next groups if @resolving_only_for_ruby || dependency.force_ruby_platform
- next groups if @resolving_only_for_ruby || dependency.force_ruby_platform
+ platform_specs = relevant_platforms.flat_map {|platform| select_best_platform_match(specs, platform) }
+ next groups if platform_specs == ruby_specs
- spec_group = SpecGroup.create_for(specs_by_platform, @platforms)
- groups << spec_group
+ spec_group = SpecGroup.new(platform_specs, relevant_platforms)
+ groups << spec_group
- groups
- end
- else
- []
+ groups
end
end
end
@@ -181,10 +159,6 @@ module Bundler
requirement.matches_spec?(spec) || spec.source.is_a?(Source::Gemspec)
end
- def dependencies_equal?(dependencies, other_dependencies)
- dependencies.map(&:dep) == other_dependencies.map(&:dep)
- end
-
def sort_dependencies(dependencies, activated, conflicts)
dependencies.sort_by do |dependency|
name = name_for(dependency)
@@ -196,17 +170,10 @@ module Bundler
amount_constrained(dependency),
conflicts[name] ? 0 : 1,
vertex.payload ? 0 : search_for(dependency).count,
- self.class.platform_sort_key(dependency.__platform),
]
end
end
- def self.platform_sort_key(platform)
- # Prefer specific platform to not specific platform
- return ["99-LAST", "", "", ""] if Gem::Platform::RUBY == platform
- ["00", *platform.to_a.map {|part| part || "" }]
- end
-
private
def base_requirements
@@ -261,6 +228,7 @@ module Bundler
requirements.map! do |requirement|
name = requirement.name
next requirement if name == "bundler"
+ next if requirement.gem_platforms(@platforms).empty?
next requirement unless search_for(requirement).empty?
next unless requirement.current_platform?
@@ -282,7 +250,9 @@ module Bundler
if specs_matching_requirement.any?
specs = specs_matching_requirement
matching_part = requirement_label
- requirement_label = "#{requirement_label}' with platform '#{requirement.__platform}"
+ platforms = requirement.gem_platforms(@platforms)
+ platform_label = platforms.size == 1 ? "platform '#{platforms.first}" : "platforms '#{platforms.join("', '")}"
+ requirement_label = "#{requirement_label}' with #{platform_label}"
end
message = String.new("Could not find gem '#{requirement_label}'#{extra_message} in #{source}#{cache_message}.\n")
diff --git a/lib/bundler/resolver/base.rb b/lib/bundler/resolver/base.rb
index 84e087b0ae..a8f42dc994 100644
--- a/lib/bundler/resolver/base.rb
+++ b/lib/bundler/resolver/base.rb
@@ -40,7 +40,7 @@ module Bundler
base_requirements = {}
@base.each do |ls|
dep = Dependency.new(ls.name, ls.version)
- base_requirements[ls.name] = DepProxy.get_proxy(dep, ls.platform)
+ base_requirements[ls.name] = dep
end
@additional_base_requirements.each {|d| base_requirements[d.name] = d }
base_requirements
diff --git a/lib/bundler/resolver/spec_group.rb b/lib/bundler/resolver/spec_group.rb
index 2c00af3b84..ac32c3c119 100644
--- a/lib/bundler/resolver/spec_group.rb
+++ b/lib/bundler/resolver/spec_group.rb
@@ -6,14 +6,8 @@ module Bundler
attr_accessor :name, :version, :source
attr_accessor :activated_platforms, :force_ruby_platform
- def self.create_for(specs, all_platforms)
- platforms = all_platforms.select {|p| specs[p].any? }
-
- new(specs, platforms)
- end
-
def initialize(specs, relevant_platforms)
- @exemplary_spec = specs[relevant_platforms.first].first
+ @exemplary_spec = specs.first
@name = @exemplary_spec.name
@version = @exemplary_spec.version
@source = @exemplary_spec.source
@@ -23,17 +17,12 @@ module Bundler
end
def to_specs
- activated_platforms.map do |p|
- specs = @specs[p]
- next unless specs.any?
-
- specs.map do |s|
- lazy_spec = LazySpecification.new(name, version, s.platform, source)
- lazy_spec.force_ruby_platform = force_ruby_platform
- lazy_spec.dependencies.replace s.dependencies
- lazy_spec
- end
- end.flatten.compact.uniq
+ @specs.map do |s|
+ lazy_spec = LazySpecification.new(name, version, s.platform, source)
+ lazy_spec.force_ruby_platform = force_ruby_platform
+ lazy_spec.dependencies.replace s.dependencies
+ lazy_spec
+ end
end
def to_s
@@ -42,7 +31,9 @@ module Bundler
end
def dependencies_for_activated_platforms
- @dependencies_for_activated_platforms ||= dependencies_for(activated_platforms)
+ @dependencies_for_activated_platforms ||= @specs.map do |spec|
+ __dependencies(spec) + metadata_dependencies(spec)
+ end.flatten.uniq
end
def ==(other)
@@ -73,35 +64,28 @@ module Bundler
private
- def dependencies_for(platforms)
- platforms.map do |platform|
- __dependencies(platform) + metadata_dependencies(platform)
- end.flatten
- end
-
- def __dependencies(platform)
+ def __dependencies(spec)
dependencies = []
- @specs[platform].first.dependencies.each do |dep|
+ spec.dependencies.each do |dep|
next if dep.type == :development
- dependencies << DepProxy.get_proxy(Dependency.new(dep.name, dep.requirement), platform)
+ dependencies << Dependency.new(dep.name, dep.requirement)
end
dependencies
end
- def metadata_dependencies(platform)
- spec = @specs[platform].first
+ def metadata_dependencies(spec)
return [] if spec.is_a?(LazySpecification)
[
- metadata_dependency("Ruby", spec.required_ruby_version, platform),
- metadata_dependency("RubyGems", spec.required_rubygems_version, platform),
+ metadata_dependency("Ruby", spec.required_ruby_version),
+ metadata_dependency("RubyGems", spec.required_rubygems_version),
].compact
end
- def metadata_dependency(name, requirement, platform)
+ def metadata_dependency(name, requirement)
return if requirement.nil? || requirement.none?
- DepProxy.get_proxy(Dependency.new("#{name}\0", requirement), platform)
+ Dependency.new("#{name}\0", requirement)
end
end
end