Skip to content

Commit 3c3cce1

Browse files
deivid-rodriguezmatzbot
authored andcommitted
[rubygems/rubygems] Fix another case of bundle lock --add-platform doing nothing
rubygems/rubygems@0629e27dda
1 parent 58aebcb commit 3c3cce1

File tree

2 files changed

+64
-6
lines changed

2 files changed

+64
-6
lines changed

lib/bundler/definition.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def initialize(lockfile, dependencies, sources, unlock, ruby_version = nil, opti
8181
@resolved_bundler_version = nil
8282

8383
@locked_ruby_version = nil
84-
@new_platform = nil
84+
@new_platforms = []
8585
@removed_platform = nil
8686

8787
if lockfile_exists?
@@ -457,8 +457,10 @@ def validate_platforms!
457457
end
458458

459459
def add_platform(platform)
460-
@new_platform ||= !@platforms.include?(platform)
461-
@platforms |= [platform]
460+
return if @platforms.include?(platform)
461+
462+
@new_platforms << platform
463+
@platforms << platform
462464
end
463465

464466
def remove_platform(platform)
@@ -482,7 +484,7 @@ def nothing_changed?
482484

483485
!@source_changes &&
484486
!@dependency_changes &&
485-
!@new_platform &&
487+
@new_platforms.empty? &&
486488
!@path_changes &&
487489
!@local_changes &&
488490
!@missing_lockfile_dep &&
@@ -703,7 +705,7 @@ def change_reason
703705
[
704706
[@source_changes, "the list of sources changed"],
705707
[@dependency_changes, "the dependencies in your gemfile changed"],
706-
[@new_platform, "you added a new platform to your gemfile"],
708+
[@new_platforms.any?, "you added a new platform to your gemfile"],
707709
[@path_changes, "the gemspecs for path gems changed"],
708710
[@local_changes, "the gemspecs for git local gems changed"],
709711
[@missing_lockfile_dep, "your lock file is missing \"#{@missing_lockfile_dep}\""],
@@ -1061,7 +1063,7 @@ def remove_invalid_platforms!(dependencies)
10611063

10621064
platforms.reverse_each do |platform|
10631065
next if local_platform == platform ||
1064-
(@new_platform && platforms.last == platform) ||
1066+
@new_platforms.include?(platform) ||
10651067
@path_changes ||
10661068
@dependency_changes ||
10671069
@locked_spec_with_invalid_deps ||

spec/bundler/commands/lock_spec.rb

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,62 @@
629629
expect(lockfile.platforms).to match_array(default_platform_list(java, x86_mingw32))
630630
end
631631

632+
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
633+
simulate_platform "arm64-darwin-23" do
634+
build_repo4 do
635+
build_gem "foo" do |s|
636+
s.platform = "arm64-darwin"
637+
end
638+
639+
build_gem "foo" do |s|
640+
s.platform = "java"
641+
end
642+
end
643+
644+
gemfile <<-G
645+
source "https://gem.repo4"
646+
647+
gem "foo"
648+
G
649+
650+
lockfile <<-L
651+
GEM
652+
remote: https://gem.repo4/
653+
specs:
654+
foo (1.0-arm64-darwin)
655+
656+
PLATFORMS
657+
arm64-darwin
658+
659+
DEPENDENCIES
660+
foo
661+
662+
BUNDLED WITH
663+
#{Bundler::VERSION}
664+
L
665+
666+
bundle "lock --add-platform java"
667+
668+
expect(lockfile).to eq <<~L
669+
GEM
670+
remote: https://gem.repo4/
671+
specs:
672+
foo (1.0-arm64-darwin)
673+
foo (1.0-java)
674+
675+
PLATFORMS
676+
arm64-darwin
677+
java
678+
679+
DEPENDENCIES
680+
foo
681+
682+
BUNDLED WITH
683+
#{Bundler::VERSION}
684+
L
685+
end
686+
end
687+
632688
it "supports adding new platforms with force_ruby_platform = true" do
633689
lockfile <<-L
634690
GEM

0 commit comments

Comments
 (0)