From 9f67118d7bc790ee5c3449e28f76e428958bc5cb Mon Sep 17 00:00:00 2001 From: David Rodríguez Date: Thu, 26 Oct 2023 20:50:06 +0200 Subject: [rubygems/rubygems] Simplify selecting specs with `force_ruby_platform` set https://github.com/rubygems/rubygems/commit/5f90a43635 Co-authored-by: Martin Emde --- lib/bundler/gem_helpers.rb | 7 +++++++ lib/bundler/lazy_specification.rb | 4 ++++ lib/bundler/spec_set.rb | 8 +++++--- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/bundler/gem_helpers.rb b/lib/bundler/gem_helpers.rb index 2e6d788f9c..f0d5ce135a 100644 --- a/lib/bundler/gem_helpers.rb +++ b/lib/bundler/gem_helpers.rb @@ -48,6 +48,13 @@ module Bundler end module_function :select_best_platform_match + def force_ruby_platform(specs) + matching = specs.select {|spec| spec.match_platform(Gem::Platform::RUBY) && spec.force_ruby_platform! } + + sort_best_platform_match(matching, Gem::Platform::RUBY) + end + module_function :force_ruby_platform + def sort_best_platform_match(matching, platform) exact = matching.select {|spec| spec.platform == platform } return exact if exact.any? diff --git a/lib/bundler/lazy_specification.rb b/lib/bundler/lazy_specification.rb index 970869e084..4a5a7d3f66 100644 --- a/lib/bundler/lazy_specification.rb +++ b/lib/bundler/lazy_specification.rb @@ -133,6 +133,10 @@ module Bundler " #{source.revision[0..6]}" end + def force_ruby_platform! + @force_ruby_platform = true + end + private def use_exact_resolved_specifications? diff --git a/lib/bundler/spec_set.rb b/lib/bundler/spec_set.rb index 912ff8bf2e..cb8f0fd1b2 100644 --- a/lib/bundler/spec_set.rb +++ b/lib/bundler/spec_set.rb @@ -200,9 +200,11 @@ module Bundler def specs_for_dependency(dep, platform) specs_for_name = lookup[dep.name] - target_platform = dep.force_ruby_platform ? Gem::Platform::RUBY : (platform || Bundler.local_platform) - matching_specs = GemHelpers.select_best_platform_match(specs_for_name, target_platform) - matching_specs.each {|s| s.force_ruby_platform = true } if dep.force_ruby_platform + matching_specs = if dep.force_ruby_platform + GemHelpers.force_ruby_platform(specs_for_name) + else + GemHelpers.select_best_platform_match(specs_for_name, platform || Bundler.local_platform) + end matching_specs.map!(&:materialize_for_installation).compact! if platform.nil? matching_specs end -- cgit v1.2.3