[rubygems/rubygems] Fix another case of bundle lock --add-platform doing nothing

https://github.com/rubygems/rubygems/commit/0629e27dda
This commit is contained in:
David Rodríguez 2024-07-09 19:13:59 +02:00 committed by git
parent 58aebcbce1
commit 3c3cce13c6
2 changed files with 64 additions and 6 deletions

View File

@ -81,7 +81,7 @@ module Bundler
@resolved_bundler_version = nil
@locked_ruby_version = nil
@new_platform = nil
@new_platforms = []
@removed_platform = nil
if lockfile_exists?
@ -457,8 +457,10 @@ module Bundler
end
def add_platform(platform)
@new_platform ||= !@platforms.include?(platform)
@platforms |= [platform]
return if @platforms.include?(platform)
@new_platforms << platform
@platforms << platform
end
def remove_platform(platform)
@ -482,7 +484,7 @@ module Bundler
!@source_changes &&
!@dependency_changes &&
!@new_platform &&
@new_platforms.empty? &&
!@path_changes &&
!@local_changes &&
!@missing_lockfile_dep &&
@ -703,7 +705,7 @@ module Bundler
[
[@source_changes, "the list of sources changed"],
[@dependency_changes, "the dependencies in your gemfile changed"],
[@new_platform, "you added a new platform to your gemfile"],
[@new_platforms.any?, "you added a new platform to your gemfile"],
[@path_changes, "the gemspecs for path gems changed"],
[@local_changes, "the gemspecs for git local gems changed"],
[@missing_lockfile_dep, "your lock file is missing \"#{@missing_lockfile_dep}\""],
@ -1061,7 +1063,7 @@ module Bundler
platforms.reverse_each do |platform|
next if local_platform == platform ||
(@new_platform && platforms.last == platform) ||
@new_platforms.include?(platform) ||
@path_changes ||
@dependency_changes ||
@locked_spec_with_invalid_deps ||

View File

@ -629,6 +629,62 @@ RSpec.describe "bundle lock" do
expect(lockfile.platforms).to match_array(default_platform_list(java, x86_mingw32))
end
it "supports adding new platforms, when most specific locked platform is not the current platform, and current resolve is not compatible with the target platform" do
simulate_platform "arm64-darwin-23" do
build_repo4 do
build_gem "foo" do |s|
s.platform = "arm64-darwin"
end
build_gem "foo" do |s|
s.platform = "java"
end
end
gemfile <<-G
source "https://gem.repo4"
gem "foo"
G
lockfile <<-L
GEM
remote: https://gem.repo4/
specs:
foo (1.0-arm64-darwin)
PLATFORMS
arm64-darwin
DEPENDENCIES
foo
BUNDLED WITH
#{Bundler::VERSION}
L
bundle "lock --add-platform java"
expect(lockfile).to eq <<~L
GEM
remote: https://gem.repo4/
specs:
foo (1.0-arm64-darwin)
foo (1.0-java)
PLATFORMS
arm64-darwin
java
DEPENDENCIES
foo
BUNDLED WITH
#{Bundler::VERSION}
L
end
end
it "supports adding new platforms with force_ruby_platform = true" do
lockfile <<-L
GEM