summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Rodríguez <deivid.rodriguez@riseup.net>2025-03-25 14:46:35 +0100
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2025-03-31 09:39:22 +0900
commitdea505dea014c45062fb2963d4eb770be1497a4a (patch)
treef60014bd2dc412567690bea0dbb358c46964c914
parentb2bcd360441c334f16148908684e9b409eac4949 (diff)
[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
-rw-r--r--lib/bundler/definition.rb10
-rw-r--r--spec/bundler/install/gemfile/specific_platform_spec.rb74
2 files changed, 82 insertions, 2 deletions
diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb
index d57a9704d8..f0d7cf8d2a 100644
--- a/lib/bundler/definition.rb
+++ b/lib/bundler/definition.rb
@@ -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
diff --git a/spec/bundler/install/gemfile/specific_platform_spec.rb b/spec/bundler/install/gemfile/specific_platform_spec.rb
index e09336e435..7f147adcb0 100644
--- a/spec/bundler/install/gemfile/specific_platform_spec.rb
+++ b/spec/bundler/install/gemfile/specific_platform_spec.rb
@@ -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