Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions bundler/lib/bundler/definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def initialize(lockfile, dependencies, sources, unlock, ruby_version = nil, opti
@locked_bundler_version = nil
@locked_ruby_version = nil
@new_platform = nil
@removed_platform = nil

if lockfile && File.exist?(lockfile)
@lockfile_contents = Bundler.read_file(lockfile)
Expand Down Expand Up @@ -267,7 +268,7 @@ def resolve
SpecSet.new(filter_specs(@locked_specs, @dependencies - deleted_deps))
else
Bundler.ui.debug "Found no changes, using resolution from the lockfile"
if @locked_gems.may_include_redundant_platform_specific_gems?
if @removed_platform || @locked_gems.may_include_redundant_platform_specific_gems?
SpecSet.new(filter_specs(@locked_specs, @dependencies))
else
@locked_specs
Expand Down Expand Up @@ -446,7 +447,9 @@ def add_platform(platform)
end

def remove_platform(platform)
return if @platforms.delete(Gem::Platform.new(platform))
removed_platform = @platforms.delete(Gem::Platform.new(platform))
@removed_platform ||= removed_platform
return if removed_platform
raise InvalidOption, "Unable to remove the platform `#{platform}` since the only platforms are #{@platforms.join ", "}"
end

Expand Down
55 changes: 55 additions & 0 deletions bundler/spec/commands/lock_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,61 @@ def read_lockfile(file = "Gemfile.lock")
expect(lockfile.platforms).to match_array([x86_mingw32, specific_local_platform].uniq)
end

it "also cleans up redundant platform gems when removing platforms" do
build_repo4 do
build_gem "nokogiri", "1.12.0"
build_gem "nokogiri", "1.12.0" do |s|
s.platform = "x86_64-darwin"
end
end

simulate_platform "x86_64-darwin-22" do
install_gemfile <<~G
source "#{file_uri_for(gem_repo4)}"

gem "nokogiri"
G
end

lockfile <<~L
GEM
remote: #{file_uri_for(gem_repo4)}/
specs:
nokogiri (1.12.0)
nokogiri (1.12.0-x86_64-darwin)

PLATFORMS
ruby
x86_64-darwin

DEPENDENCIES
nokogiri

BUNDLED WITH
#{Bundler::VERSION}
L

simulate_platform "x86_64-darwin-22" do
bundle "lock --remove-platform ruby"
end

expect(lockfile).to eq <<~L
GEM
remote: #{file_uri_for(gem_repo4)}/
specs:
nokogiri (1.12.0-x86_64-darwin)

PLATFORMS
x86_64-darwin

DEPENDENCIES
nokogiri

BUNDLED WITH
#{Bundler::VERSION}
L
end

it "errors when removing all platforms" do
bundle "lock --remove-platform #{specific_local_platform}", :raise_on_error => false
expect(err).to include("Removing all platforms from the bundle is not allowed")
Expand Down