[rubygems/rubygems] Materializing specs for vendor/cache should not be strict

Platforms specific gems not compatible with the current Ruby should not
make `bundle cache` fail and should not get removed from the cache since
they still may be useful in other rubies.

717b43f565
This commit is contained in:
David Rodríguez 2025-02-03 17:37:11 +01:00 committed by Hiroshi SHIBATA
parent 5adbad731b
commit e7720ef8d7
No known key found for this signature in database
GPG key ID: F9CF13417264FAC2
2 changed files with 51 additions and 8 deletions

View file

@ -124,7 +124,7 @@ module Bundler
def materialize_for_cache
source.remote!
materialize_strictly
materialize(self, &:first)
end
def materialized_for_installation
@ -137,7 +137,9 @@ module Bundler
source.local!
if use_exact_resolved_specifications?
materialize_strictly
materialize(self) do |matching_specs|
choose_compatible(matching_specs)
end
else
materialize([name, version]) do |matching_specs|
target_platform = source.is_a?(Source::Path) ? platform : local_platform
@ -185,12 +187,6 @@ module Bundler
(most_specific_locked_platform != generic_platform) || force_ruby_platform || Bundler.settings[:force_ruby_platform]
end
def materialize_strictly
materialize(self) do |matching_specs|
choose_compatible(matching_specs)
end
end
def materialize(query)
matching_specs = source.specs.search(query)
return self if matching_specs.empty?

View file

@ -482,6 +482,53 @@ RSpec.describe "bundle install with gem sources" do
expect(the_bundle).to include_gems("platform_specific 1.0 ruby")
end
it "keeps gems that are locked and cached for the current platform, even if incompatible with the current ruby" do
build_repo4 do
build_gem "bcrypt_pbkdf", "1.1.1"
build_gem "bcrypt_pbkdf", "1.1.1" do |s|
s.platform = "arm64-darwin"
s.required_ruby_version = "< #{current_ruby_minor}"
end
end
app_cache = bundled_app("vendor/cache")
FileUtils.mkdir_p app_cache
FileUtils.cp gem_repo4("gems/bcrypt_pbkdf-1.1.1-arm64-darwin.gem"), app_cache
FileUtils.cp gem_repo4("gems/bcrypt_pbkdf-1.1.1.gem"), app_cache
bundle "config cache_all_platforms true"
lockfile <<~L
GEM
remote: https://gem.repo4/
specs:
bcrypt_pbkdf (1.1.1)
bcrypt_pbkdf (1.1.1-arm64-darwin)
PLATFORMS
arm64-darwin
ruby
DEPENDENCIES
bcrypt_pbkdf
BUNDLED WITH
#{Bundler::VERSION}
L
simulate_platform "arm64-darwin-23" do
install_gemfile <<~G, verbose: true
source "https://gem.repo4"
gem "bcrypt_pbkdf"
G
expect(out).to include("Updating files in vendor/cache")
expect(err).to be_empty
expect(app_cache.join("bcrypt_pbkdf-1.1.1-arm64-darwin.gem")).to exist
expect(app_cache.join("bcrypt_pbkdf-1.1.1.gem")).to exist
end
end
it "does not update the cache if --no-cache is passed" do
gemfile <<-G
source "https://gem.repo1"