Skip to content

Commit 68a1867

Browse files
deivid-rodriguezmatzbot
authored andcommitted
[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. rubygems/rubygems@6452adfd62
1 parent 6203307 commit 68a1867

File tree

2 files changed

+50
-4
lines changed

2 files changed

+50
-4
lines changed

lib/bundler/definition.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,12 @@ def initialize(lockfile, dependencies, sources, unlock, ruby_version = nil, opti
9292
@platforms = @locked_platforms.dup
9393
@locked_bundler_version = @locked_gems.bundler_version
9494
@locked_ruby_version = @locked_gems.ruby_version
95+
@originally_locked_deps = @locked_gems.dependencies
9596
@originally_locked_specs = SpecSet.new(@locked_gems.specs)
9697
@locked_checksums = @locked_gems.checksums
9798

9899
if unlock != true
99-
@locked_deps = @locked_gems.dependencies
100+
@locked_deps = @originally_locked_deps
100101
@locked_specs = @originally_locked_specs
101102
@locked_sources = @locked_gems.sources
102103
else
@@ -111,6 +112,7 @@ def initialize(lockfile, dependencies, sources, unlock, ruby_version = nil, opti
111112
@locked_gems = nil
112113
@locked_deps = {}
113114
@locked_specs = SpecSet.new([])
115+
@originally_locked_deps = {}
114116
@originally_locked_specs = @locked_specs
115117
@locked_sources = []
116118
@locked_platforms = []
@@ -835,9 +837,7 @@ def converge_dependencies
835837
dep.source = sources.get(dep.source)
836838
end
837839

838-
next if unlocking?
839-
840-
unless locked_dep = @locked_deps[dep.name]
840+
unless locked_dep = @originally_locked_deps[dep.name]
841841
changes = true
842842
next
843843
end

spec/bundler/commands/update_spec.rb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1954,6 +1954,52 @@
19541954
end
19551955
end
19561956

1957+
context "when Gemfile dependencies have changed" do
1958+
before do
1959+
build_repo4 do
1960+
build_gem "nokogiri", "1.16.4" do |s|
1961+
s.platform = "arm64-darwin"
1962+
end
1963+
1964+
build_gem "nokogiri", "1.16.4" do |s|
1965+
s.platform = "x86_64-linux"
1966+
end
1967+
1968+
build_gem "prism", "0.25.0"
1969+
end
1970+
1971+
gemfile <<~G
1972+
source "#{file_uri_for(gem_repo4)}"
1973+
gem "nokogiri", ">=1.16.4"
1974+
gem "prism", ">=0.25.0"
1975+
G
1976+
1977+
lockfile <<~L
1978+
GEM
1979+
remote: #{file_uri_for(gem_repo4)}/
1980+
specs:
1981+
nokogiri (1.16.4-arm64-darwin)
1982+
nokogiri (1.16.4-x86_64-linux)
1983+
1984+
PLATFORMS
1985+
arm64-darwin
1986+
x86_64-linux
1987+
1988+
DEPENDENCIES
1989+
nokogiri (>= 1.16.4)
1990+
1991+
BUNDLED WITH
1992+
#{Bundler::VERSION}
1993+
L
1994+
end
1995+
1996+
it "still works" do
1997+
simulate_platform "arm64-darwin-23" do
1998+
bundle "update"
1999+
end
2000+
end
2001+
end
2002+
19572003
context "error handling" do
19582004
before do
19592005
gemfile "source \"#{file_uri_for(gem_repo1)}\""

0 commit comments

Comments
 (0)