Skip to content

Commit

Permalink
[rubygems/rubygems] Fix Ruby platform incorrectly removed on `bundle …
Browse files Browse the repository at this point in the history
  • Loading branch information
deivid-rodriguez authored and matzbot committed Aug 15, 2022
1 parent cbcf2da commit e77c839
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/bundler/definition.rb
Expand Up @@ -888,7 +888,7 @@ def remove_ruby_from_platforms_if_necessary!(dependencies)
Bundler.local_platform == Gem::Platform::RUBY ||
!platforms.include?(Gem::Platform::RUBY) ||
(@new_platform && platforms.last == Gem::Platform::RUBY) ||
!@originally_locked_specs.incomplete_ruby_specs?(dependencies)
!@originally_locked_specs.incomplete_ruby_specs?(expand_dependencies(dependencies))

remove_platform(Gem::Platform::RUBY)
add_current_platform
Expand Down
41 changes: 41 additions & 0 deletions spec/bundler/install/gemfile/specific_platform_spec.rb
Expand Up @@ -445,6 +445,47 @@
L
end

it "does not remove ruby if gems for other platforms, and not present in the lockfile, exist in the Gemfile" do
build_repo4 do
build_gem "nokogiri", "1.13.8"
build_gem "nokogiri", "1.13.8" do |s|
s.platform = Gem::Platform.local
end
end

gemfile <<~G
source "#{file_uri_for(gem_repo4)}"
gem "nokogiri"
gem "tzinfo", "~> 1.2", platform: :#{not_local_tag}
G

original_lockfile = <<~L
GEM
remote: #{file_uri_for(gem_repo4)}/
specs:
nokogiri (1.13.8)
nokogiri (1.13.8-#{Gem::Platform.local})
PLATFORMS
#{lockfile_platforms_for([specific_local_platform, "ruby"])}
DEPENDENCIES
nokogiri
tzinfo (~> 1.2)
BUNDLED WITH
#{Bundler::VERSION}
L

lockfile original_lockfile

bundle "lock --update"

expect(lockfile).to eq(original_lockfile)
end

it "can fallback to a source gem when platform gems are incompatible with current ruby version" do
setup_multiplatform_gem_with_source_gem

Expand Down

0 comments on commit e77c839

Please sign in to comment.