diff options
author | David RodrÃguez <[email protected]> | 2025-02-03 17:37:11 +0100 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2025-02-13 09:37:50 +0900 |
commit | e7720ef8d7176adecd4cfe1a42008a89ff157e97 (patch) | |
tree | 14e9370b52457a44e434ca17dce2fa7bc067df7e | |
parent | 5adbad731b3354e2cdf1befa0ec719f3609678dc (diff) |
[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.
https://github.com/rubygems/rubygems/commit/717b43f565
-rw-r--r-- | lib/bundler/lazy_specification.rb | 12 | ||||
-rw-r--r-- | spec/bundler/commands/cache_spec.rb | 47 |
2 files changed, 51 insertions, 8 deletions
diff --git a/lib/bundler/lazy_specification.rb b/lib/bundler/lazy_specification.rb index 479736094f..5df0cce6f3 100644 --- a/lib/bundler/lazy_specification.rb +++ b/lib/bundler/lazy_specification.rb @@ -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? diff --git a/spec/bundler/commands/cache_spec.rb b/spec/bundler/commands/cache_spec.rb index ab8eb06838..ded8b9a692 100644 --- a/spec/bundler/commands/cache_spec.rb +++ b/spec/bundler/commands/cache_spec.rb @@ -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" |