[rubygems/rubygems] Allow ruby platform to be remove also when dependencies have changed

Since we will now add it back if the final resolution is compatible, we
can also get this kind of edge case (`bundle add`) working.

https://github.com/rubygems/rubygems/commit/cdc5ebec77
This commit is contained in:
David Rodríguez 2025-03-25 14:46:35 +01:00 committed by Hiroshi SHIBATA
parent b2bcd36044
commit dea505dea0
No known key found for this signature in database
GPG Key ID: F9CF13417264FAC2
2 changed files with 82 additions and 2 deletions

View File

@ -1144,8 +1144,14 @@ module Bundler
@originally_invalid_platforms = platforms.select do |platform|
next if local_platform == platform ||
@new_platforms.include?(platform) ||
@dependency_changes
@new_platforms.include?(platform)
# We should probably avoid removing non-ruby platforms, since that means
# lockfile will no longer install on those platforms, so a error to give
# heads up to the user may be better. However, we have tests expecting
# non ruby platform autoremoval to work, so leaving that in place for
# now.
next if @dependency_changes && platform != Gem::Platform::RUBY
spec_set_incomplete_for_platform?(@originally_locked_specs, platform)
end

View File

@ -752,6 +752,80 @@ RSpec.describe "bundle install with specific platforms" do
L
end
it "automatically fixes the lockfile when adding a gem that introduces dependencies with no ruby platform variants transitively" do
simulate_platform "x86_64-linux" do
build_repo4 do
build_gem "nokogiri", "1.18.2"
build_gem "nokogiri", "1.18.2" do |s|
s.platform = "x86_64-linux"
end
build_gem("sorbet", "0.5.11835") do |s|
s.add_dependency "sorbet-static", "= 0.5.11835"
end
build_gem "sorbet-static", "0.5.11835" do |s|
s.platform = "x86_64-linux"
end
end
gemfile <<~G
source "https://gem.repo4"
gem "nokogiri"
gem "sorbet"
G
lockfile <<~L
GEM
remote: https://gem.repo4/
specs:
nokogiri (1.18.2)
nokogiri (1.18.2-x86_64-linux)
PLATFORMS
ruby
x86_64-linux
DEPENDENCIES
nokogiri
BUNDLED WITH
#{Bundler::VERSION}
L
bundle "lock"
checksums = checksums_section_when_enabled do |c|
c.checksum gem_repo4, "nokogiri", "1.18.2", "x86_64-linux"
c.checksum gem_repo4, "sorbet", "0.5.11835"
c.checksum gem_repo4, "sorbet-static", "0.5.11835", "x86_64-linux"
end
expect(lockfile).to eq <<~L
GEM
remote: https://gem.repo4/
specs:
nokogiri (1.18.2)
nokogiri (1.18.2-x86_64-linux)
sorbet (0.5.11835)
sorbet-static (= 0.5.11835)
sorbet-static (0.5.11835-x86_64-linux)
PLATFORMS
x86_64-linux
DEPENDENCIES
nokogiri
sorbet
#{checksums}
BUNDLED WITH
#{Bundler::VERSION}
L
end
end
it "automatically fixes the lockfile if multiple platforms locked, but no valid versions of direct dependencies for all of them" do
simulate_platform "x86_64-linux" do
build_repo4 do