Skip to content

Commit

Permalink
[rubygems/rubygems] Simplify selecting specs with `force_ruby_platfor…
Browse files Browse the repository at this point in the history
…m` set

rubygems/rubygems@5f90a43635

Co-authored-by: Martin Emde <martin.emde@gmail.com>
  • Loading branch information
2 people authored and hsbt committed Nov 8, 2023
1 parent a131ea3 commit 9f67118
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
7 changes: 7 additions & 0 deletions lib/bundler/gem_helpers.rb
Expand Up @@ -48,6 +48,13 @@ def select_best_platform_match(specs, platform)
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?
Expand Down
4 changes: 4 additions & 0 deletions lib/bundler/lazy_specification.rb
Expand Up @@ -133,6 +133,10 @@ def git_version
" #{source.revision[0..6]}"
end

def force_ruby_platform!
@force_ruby_platform = true
end

private

def use_exact_resolved_specifications?
Expand Down
8 changes: 5 additions & 3 deletions lib/bundler/spec_set.rb
Expand Up @@ -200,9 +200,11 @@ def tsort_each_node

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
Expand Down

0 comments on commit 9f67118

Please sign in to comment.