diff options
author | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2022-07-26 13:43:48 +0900 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2022-07-26 14:38:17 +0900 |
commit | 9e6d07f3462d29f340114650da9f13a36b866d5f (patch) | |
tree | 1b347705d94dc8a6f2df99372d10e3f0946ef0c0 /lib/bundler/spec_set.rb | |
parent | b404a5f106d13e25708c163c91e117b2e106b70c (diff) |
Merge rubygems/bundler HEAD
Merge from https://github.com/rubygems/rubygems/commit/2af2520b4a7ab1c6eb1fdc3d2ef4d8c062d96ad7
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/6184
Diffstat (limited to 'lib/bundler/spec_set.rb')
-rw-r--r-- | lib/bundler/spec_set.rb | 52 |
1 files changed, 30 insertions, 22 deletions
diff --git a/lib/bundler/spec_set.rb b/lib/bundler/spec_set.rb index 06257ac93f..a7a95e49bc 100644 --- a/lib/bundler/spec_set.rb +++ b/lib/bundler/spec_set.rb @@ -11,30 +11,27 @@ module Bundler @specs = specs end - def for(dependencies, check = false, match_current_platform = false) - # dep.name => [list, of, deps] - handled = Hash.new {|h, k| h[k] = [] } - deps = dependencies.dup + def for(dependencies, check = false, platforms = [nil]) + handled = ["bundler"].product(platforms).map {|k| [k, true] }.to_h + deps = dependencies.product(platforms).map {|dep, platform| [dep.name, platform && dep.force_ruby_platform ? Gem::Platform::RUBY : platform] } specs = [] loop do break unless dep = deps.shift - next if handled[dep.name].any? {|d| match_current_platform || d.__platform == dep.__platform } || dep.name == "bundler" + next if handled.key?(dep) - # use a hash here to ensure constant lookup time in the `any?` call above - handled[dep.name] << dep + handled[dep] = true - specs_for_dep = specs_for_dependency(dep, match_current_platform) + specs_for_dep = specs_for_dependency(*dep) if specs_for_dep.any? specs.concat(specs_for_dep) specs_for_dep.first.dependencies.each do |d| next if d.type == :development - d = DepProxy.get_proxy(Dependency.new(d.name, d.requirement), dep.__platform) unless match_current_platform - deps << d + deps << [d.name, dep[1]] end elsif check - return false + specs << IncompleteSpecification.new(*dep) end end @@ -42,9 +39,7 @@ module Bundler specs << spec end - specs.uniq! unless match_current_platform - - check ? true : specs + specs end def [](key) @@ -71,12 +66,12 @@ module Bundler end def materialize(deps) - materialized = self.for(deps, false, true) + materialized = self.for(deps, true).uniq materialized.map! do |s| next s unless s.is_a?(LazySpecification) s.source.local! - s.__materialize__ || s + s.materialize_for_installation || s end SpecSet.new(materialized) end @@ -89,16 +84,29 @@ module Bundler next s unless s.is_a?(LazySpecification) s.source.local! s.source.remote! - spec = s.__materialize__ + spec = s.materialize_for_installation raise GemNotFound, "Could not find #{s.full_name} in any of the sources" unless spec spec end end + def materialized_for_resolution + materialized = @specs.map do |s| + spec = s.materialize_for_resolution + yield spec if spec + spec + end.compact + SpecSet.new(materialized) + end + def missing_specs @specs.select {|s| s.is_a?(LazySpecification) } end + def incomplete_specs + @specs.select {|s| s.is_a?(IncompleteSpecification) } + end + def merge(set) arr = sorted.dup set.each do |set_spec| @@ -173,12 +181,12 @@ module Bundler @specs.sort_by(&:name).each {|s| yield s } end - def specs_for_dependency(dep, match_current_platform) - specs_for_name = lookup[dep.name] - if match_current_platform - GemHelpers.select_best_platform_match(specs_for_name, Bundler.local_platform) + def specs_for_dependency(name, platform) + specs_for_name = lookup[name] + if platform.nil? + GemHelpers.select_best_platform_match(specs_for_name.select {|s| Gem::Platform.match_spec?(s) }, Bundler.local_platform) else - specs_for_name_and_platform = GemHelpers.select_best_platform_match(specs_for_name, dep.force_ruby_platform ? Gem::Platform::RUBY : dep.__platform) + specs_for_name_and_platform = GemHelpers.select_best_platform_match(specs_for_name, platform) specs_for_name_and_platform.any? ? specs_for_name_and_platform : specs_for_name end end |