From 68a1867f53c5343a72a436fe75eccafdbcb41ce0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Tue, 23 Apr 2024 21:56:51 +0200 Subject: [PATCH] [rubygems/rubygems] Fix issue with `bundle update` with an out of sync lockfile An old platform related bug fix made some existing lockfiles no longer work because they included invalid platforms. So to make it backwards compatible, code was added to remove invalid platforms from the lockfile before resolution. This is skipped though when Gemfile has changed dependencies because in that case we will be re-resolving anyways. However, in the `bundle update` case, the detection of "dependencies have changed" was not actually working making Bundler remove all platforms and not be able to resolve. https://github.com/rubygems/rubygems/commit/6452adfd62 --- lib/bundler/definition.rb | 8 ++--- spec/bundler/commands/update_spec.rb | 46 ++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index c8faf77b3b..b402bc50de 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -92,11 +92,12 @@ module Bundler @platforms = @locked_platforms.dup @locked_bundler_version = @locked_gems.bundler_version @locked_ruby_version = @locked_gems.ruby_version + @originally_locked_deps = @locked_gems.dependencies @originally_locked_specs = SpecSet.new(@locked_gems.specs) @locked_checksums = @locked_gems.checksums if unlock != true - @locked_deps = @locked_gems.dependencies + @locked_deps = @originally_locked_deps @locked_specs = @originally_locked_specs @locked_sources = @locked_gems.sources else @@ -111,6 +112,7 @@ module Bundler @locked_gems = nil @locked_deps = {} @locked_specs = SpecSet.new([]) + @originally_locked_deps = {} @originally_locked_specs = @locked_specs @locked_sources = [] @locked_platforms = [] @@ -835,9 +837,7 @@ module Bundler dep.source = sources.get(dep.source) end - next if unlocking? - - unless locked_dep = @locked_deps[dep.name] + unless locked_dep = @originally_locked_deps[dep.name] changes = true next end diff --git a/spec/bundler/commands/update_spec.rb b/spec/bundler/commands/update_spec.rb index cfb86ebb54..8565e27ebf 100644 --- a/spec/bundler/commands/update_spec.rb +++ b/spec/bundler/commands/update_spec.rb @@ -1954,6 +1954,52 @@ RSpec.describe "bundle update conservative" do end end + context "when Gemfile dependencies have changed" do + before do + build_repo4 do + build_gem "nokogiri", "1.16.4" do |s| + s.platform = "arm64-darwin" + end + + build_gem "nokogiri", "1.16.4" do |s| + s.platform = "x86_64-linux" + end + + build_gem "prism", "0.25.0" + end + + gemfile <<~G + source "#{file_uri_for(gem_repo4)}" + gem "nokogiri", ">=1.16.4" + gem "prism", ">=0.25.0" + G + + lockfile <<~L + GEM + remote: #{file_uri_for(gem_repo4)}/ + specs: + nokogiri (1.16.4-arm64-darwin) + nokogiri (1.16.4-x86_64-linux) + + PLATFORMS + arm64-darwin + x86_64-linux + + DEPENDENCIES + nokogiri (>= 1.16.4) + + BUNDLED WITH + #{Bundler::VERSION} + L + end + + it "still works" do + simulate_platform "arm64-darwin-23" do + bundle "update" + end + end + end + context "error handling" do before do gemfile "source \"#{file_uri_for(gem_repo1)}\""