summaryrefslogtreecommitdiff
path: root/lib/bundler
diff options
context:
space:
mode:
authorHiroshi SHIBATA <hsbt@ruby-lang.org>2022-11-22 20:31:40 +0900
committernagachika <nagachika@ruby-lang.org>2022-11-22 21:50:22 +0900
commit6f59f0bebc5fe1ae84028832cc777160d853e302 (patch)
tree0feb32969611b220f1aef178c0cc1a3ecbfee754 /lib/bundler
parent8f2586f1985041b8be33358052fa647d02bf2aea (diff)
Merge RubyGems-3.3.24 and Bundler-2.3.24
Diffstat (limited to 'lib/bundler')
-rw-r--r--lib/bundler/definition.rb38
-rw-r--r--lib/bundler/dep_proxy.rb55
-rw-r--r--lib/bundler/endpoint_specification.rb4
-rw-r--r--lib/bundler/gem_helpers.rb1
-rw-r--r--lib/bundler/index.rb1
-rw-r--r--lib/bundler/injector.rb2
-rw-r--r--lib/bundler/lazy_specification.rb18
-rw-r--r--lib/bundler/remote_specification.rb8
-rw-r--r--lib/bundler/resolver.rb89
-rw-r--r--lib/bundler/resolver/base.rb2
-rw-r--r--lib/bundler/resolver/spec_group.rb66
-rw-r--r--lib/bundler/shared_helpers.rb3
-rw-r--r--lib/bundler/version.rb2
13 files changed, 77 insertions, 212 deletions
diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb
index a46d7387de..95be7a7e27 100644
--- a/lib/bundler/definition.rb
+++ b/lib/bundler/definition.rb
@@ -139,8 +139,8 @@ module Bundler
if @unlock[:conservative]
@unlock[:gems] ||= @dependencies.map(&:name)
else
- eager_unlock = expand_dependencies(@unlock[:gems] || [], true)
- @unlock[:gems] = @locked_specs.for(eager_unlock, false, platforms).map(&:name)
+ eager_unlock = (@unlock[:gems] || []).map {|name| Dependency.new(name, ">= 0") }
+ @unlock[:gems] = @locked_specs.for(eager_unlock, false, platforms).map(&:name).uniq
end
@dependency_changes = converge_dependencies
@@ -224,7 +224,7 @@ module Bundler
def current_dependencies
dependencies.select do |d|
- d.should_include? && !d.gem_platforms(@platforms).empty?
+ d.should_include? && !d.gem_platforms([generic_local_platform]).empty?
end
end
@@ -248,10 +248,9 @@ module Bundler
def dependencies_for(groups)
groups.map!(&:to_sym)
- deps = current_dependencies.reject do |d|
+ current_dependencies.reject do |d|
(d.groups & groups).empty?
end
- expand_dependencies(deps)
end
# Resolve all the dependencies specified in Gemfile. It ensures that
@@ -474,17 +473,17 @@ module Bundler
def resolver
@resolver ||= begin
last_resolve = converge_locked_specs
- remove_ruby_from_platforms_if_necessary!(dependencies)
+ remove_ruby_from_platforms_if_necessary!(current_dependencies)
Resolver.new(source_requirements, last_resolve, gem_version_promoter, additional_base_requirements_for_resolve(last_resolve), platforms)
end
end
def expanded_dependencies
- @expanded_dependencies ||= expand_dependencies(dependencies + metadata_dependencies, true)
+ @expanded_dependencies ||= dependencies + metadata_dependencies
end
def filter_specs(specs, deps)
- SpecSet.new(specs).for(expand_dependencies(deps, true), false, platforms)
+ SpecSet.new(specs).for(deps, false, platforms)
end
def materialize(dependencies)
@@ -578,8 +577,8 @@ module Bundler
].select(&:first).map(&:last).join(", ")
end
- def pretty_dep(dep, source = false)
- SharedHelpers.pretty_dependency(dep, source)
+ def pretty_dep(dep)
+ SharedHelpers.pretty_dependency(dep)
end
# Check if the specs of the given source changed
@@ -792,23 +791,6 @@ module Bundler
]
end
- def expand_dependencies(dependencies, remote = false)
- deps = []
- dependencies.each do |dep|
- dep = Dependency.new(dep, ">= 0") unless dep.respond_to?(:name)
- next unless remote || dep.current_platform?
- target_platforms = dep.gem_platforms(remote ? @platforms : [generic_local_platform])
- deps += expand_dependency_with_platforms(dep, target_platforms)
- end
- deps
- end
-
- def expand_dependency_with_platforms(dep, platforms)
- platforms.map do |p|
- DepProxy.get_proxy(dep, p)
- 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
@@ -880,7 +862,7 @@ module Bundler
Bundler.local_platform == Gem::Platform::RUBY ||
!platforms.include?(Gem::Platform::RUBY) ||
(@new_platform && platforms.last == Gem::Platform::RUBY) ||
- !@originally_locked_specs.incomplete_ruby_specs?(expand_dependencies(dependencies))
+ !@originally_locked_specs.incomplete_ruby_specs?(dependencies)
remove_platform(Gem::Platform::RUBY)
add_current_platform
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/gem_helpers.rb b/lib/bundler/gem_helpers.rb
index 0d50d8687b..2e6d788f9c 100644
--- a/lib/bundler/gem_helpers.rb
+++ b/lib/bundler/gem_helpers.rb
@@ -5,7 +5,6 @@ module Bundler
GENERIC_CACHE = { Gem::Platform::RUBY => Gem::Platform::RUBY } # rubocop:disable Style/MutableConstant
GENERICS = [
[Gem::Platform.new("java"), Gem::Platform.new("java")],
- [Gem::Platform.new("universal-java"), Gem::Platform.new("java")],
[Gem::Platform.new("mswin32"), Gem::Platform.new("mswin32")],
[Gem::Platform.new("mswin64"), Gem::Platform.new("mswin64")],
[Gem::Platform.new("universal-mingw32"), Gem::Platform.new("universal-mingw32")],
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/injector.rb b/lib/bundler/injector.rb
index 82d5bd5880..81465cec19 100644
--- a/lib/bundler/injector.rb
+++ b/lib/bundler/injector.rb
@@ -70,7 +70,7 @@ module Bundler
show_warning("No gems were removed from the gemfile.") if deps.empty?
- deps.each {|dep| Bundler.ui.confirm "#{SharedHelpers.pretty_dependency(dep, false)} was removed." }
+ deps.each {|dep| Bundler.ui.confirm "#{SharedHelpers.pretty_dependency(dep)} was removed." }
end
# Invalidate the cached Bundler.definition.
diff --git a/lib/bundler/lazy_specification.rb b/lib/bundler/lazy_specification.rb
index ec141cfa27..f5fe2e64ae 100644
--- a/lib/bundler/lazy_specification.rb
+++ b/lib/bundler/lazy_specification.rb
@@ -77,7 +77,7 @@ module Bundler
source.local!
candidates = if source.is_a?(Source::Path) || !ruby_platform_materializes_to_ruby_platform?
- target_platform = ruby_platform_materializes_to_ruby_platform? ? platform : Bundler.local_platform
+ target_platform = ruby_platform_materializes_to_ruby_platform? ? platform : local_platform
source.specs.search(Dependency.new(name, version)).select do |spec|
MatchPlatform.platforms_match?(spec.platform, target_platform)
@@ -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
@@ -151,7 +144,8 @@ module Bundler
#
# For backwards compatibility with existing lockfiles, if the most specific
- # locked platform is RUBY, we keep the previous behaviour of resolving the
+ # locked platform is not a specific platform like x86_64-linux or
+ # universal-java-11, then we keep the previous behaviour of resolving the
# best platform variant at materiliazation time. For previous bundler
# versions (before 2.2.0) this was always the case (except when the lockfile
# only included non-ruby platforms), but we're also keeping this behaviour
@@ -159,7 +153,9 @@ module Bundler
# explicitly add a more specific platform.
#
def ruby_platform_materializes_to_ruby_platform?
- !Bundler.most_specific_locked_platform?(generic_local_platform) || force_ruby_platform || Bundler.settings[:force_ruby_platform]
+ generic_platform = generic_local_platform == Gem::Platform::JAVA ? Gem::Platform::JAVA : Gem::Platform::RUBY
+
+ !Bundler.most_specific_locked_platform?(generic_platform) || force_ruby_platform || Bundler.settings[:force_ruby_platform]
end
end
end
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 161a3c0518..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
- spec_group_ruby = SpecGroup.create_for(specs_by_platform, [Gem::Platform::RUBY], Gem::Platform::RUBY)
- if spec_group_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, platform)
- 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,21 +228,11 @@ 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?
- if (base = @base[name]) && !base.empty?
- version = base.first.version
- message = "You have requested:\n" \
- " #{name} #{requirement.requirement}\n\n" \
- "The bundle currently has #{name} locked at #{version}.\n" \
- "Try running `bundle update #{name}`\n\n" \
- "If you are updating multiple gems in your Gemfile at once,\n" \
- "try passing them all to `bundle update`"
- else
- message = gem_not_found_message(name, requirement, source_for(name))
- end
- raise GemNotFound, message
+ raise GemNotFound, gem_not_found_message(name, requirement, source_for(name))
end.compact!
end
@@ -293,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 4e5b0082d3..ac32c3c119 100644
--- a/lib/bundler/resolver/spec_group.rb
+++ b/lib/bundler/resolver/spec_group.rb
@@ -6,40 +6,23 @@ module Bundler
attr_accessor :name, :version, :source
attr_accessor :activated_platforms, :force_ruby_platform
- def self.create_for(specs, all_platforms, specific_platform)
- specific_platform_specs = specs[specific_platform]
- return unless specific_platform_specs.any?
-
- platforms = all_platforms.select {|p| specs[p].any? }
-
- new(specific_platform_specs.first, specs, platforms)
- end
-
- def initialize(exemplary_spec, specs, relevant_platforms)
- @exemplary_spec = exemplary_spec
- @name = exemplary_spec.name
- @version = exemplary_spec.version
- @source = exemplary_spec.source
+ def initialize(specs, relevant_platforms)
+ @exemplary_spec = specs.first
+ @name = @exemplary_spec.name
+ @version = @exemplary_spec.version
+ @source = @exemplary_spec.source
@activated_platforms = relevant_platforms
- @dependencies = Hash.new do |dependencies, platforms|
- dependencies[platforms] = dependencies_for(platforms)
- end
@specs = specs
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
@@ -48,7 +31,9 @@ module Bundler
end
def dependencies_for_activated_platforms
- @dependencies[activated_platforms]
+ @dependencies_for_activated_platforms ||= @specs.map do |spec|
+ __dependencies(spec) + metadata_dependencies(spec)
+ end.flatten.uniq
end
def ==(other)
@@ -79,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
diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb
index 8c4e26f074..899eb68e0a 100644
--- a/lib/bundler/shared_helpers.rb
+++ b/lib/bundler/shared_helpers.rb
@@ -163,7 +163,7 @@ module Bundler
"\nEither installing with `--full-index` or running `bundle update #{spec.name}` should fix the problem."
end
- def pretty_dependency(dep, print_source = false)
+ def pretty_dependency(dep)
msg = String.new(dep.name)
msg << " (#{dep.requirement})" unless dep.requirement == Gem::Requirement.default
@@ -172,7 +172,6 @@ module Bundler
msg << " " << platform_string if !platform_string.empty? && platform_string != Gem::Platform::RUBY
end
- msg << " from the `#{dep.source}` source" if print_source && dep.source
msg
end
diff --git a/lib/bundler/version.rb b/lib/bundler/version.rb
index 22ce7daab9..c355277d7a 100644
--- a/lib/bundler/version.rb
+++ b/lib/bundler/version.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: false
module Bundler
- VERSION = "2.3.23".freeze
+ VERSION = "2.3.24".freeze
def self.bundler_major_version
@bundler_major_version ||= VERSION.split(".").first.to_i