diff options
author | Samuel Giddins <[email protected]> | 2025-06-05 11:26:17 -0700 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2025-06-11 08:48:56 +0900 |
commit | 7e3d271f765b6e2b2372b6af2f974d448cbfd1e0 (patch) | |
tree | 3166510c7bdaf8419e057b1eb572260555b15d6a | |
parent | b5beb1982502c46aeaac2f29888763df3272b568 (diff) |
[rubygems/rubygems] Install the best matching gem for the current platform in gem install
Instead of picking essentially a random matching platform
Signed-off-by: Samuel Giddins <[email protected]>
https://github.com/rubygems/rubygems/commit/3727096297
-rw-r--r-- | lib/rubygems/resolver.rb | 2 | ||||
-rw-r--r-- | test/rubygems/test_gem_commands_install_command.rb | 32 |
2 files changed, 33 insertions, 1 deletions
diff --git a/lib/rubygems/resolver.rb b/lib/rubygems/resolver.rb index 35d83abd2d..9bf5f80930 100644 --- a/lib/rubygems/resolver.rb +++ b/lib/rubygems/resolver.rb @@ -241,7 +241,7 @@ class Gem::Resolver sources.each do |source| groups[source]. - sort_by {|spec| [spec.version, spec.platform =~ Gem::Platform.local ? 1 : 0] }. # rubocop:disable Performance/RegexpMatch + sort_by {|spec| [spec.version, -Gem::Platform.platform_specificity_match(spec.platform, Gem::Platform.local)] }. map {|spec| ActivationRequest.new spec, dependency }. each {|activation_request| activation_requests << activation_request } end diff --git a/test/rubygems/test_gem_commands_install_command.rb b/test/rubygems/test_gem_commands_install_command.rb index 468aecde56..77525aed2c 100644 --- a/test/rubygems/test_gem_commands_install_command.rb +++ b/test/rubygems/test_gem_commands_install_command.rb @@ -1005,6 +1005,38 @@ ERROR: Possible alternatives: non_existent_with_hint assert_equal %W[a-3-#{local}], @cmd.installed_specs.map(&:full_name) end + def test_install_gem_platform_specificity_match + util_set_arch "arm64-darwin-20" + + spec_fetcher do |fetcher| + %w[ruby universal-darwin universal-darwin-20 x64-darwin-20 arm64-darwin-20].each do |platform| + fetcher.download "a", 3 do |s| + s.platform = platform + end + end + end + + @cmd.install_gem "a", ">= 0" + + assert_equal %w[a-3-arm64-darwin-20], @cmd.installed_specs.map(&:full_name) + end + + def test_install_gem_platform_specificity_match_reverse_order + util_set_arch "arm64-darwin-20" + + spec_fetcher do |fetcher| + %w[ruby universal-darwin universal-darwin-20 x64-darwin-20 arm64-darwin-20].reverse_each do |platform| + fetcher.download "a", 3 do |s| + s.platform = platform + end + end + end + + @cmd.install_gem "a", ">= 0" + + assert_equal %w[a-3-arm64-darwin-20], @cmd.installed_specs.map(&:full_name) + end + def test_install_gem_ignore_dependencies_specific_file spec = util_spec "a", 2 |