Skip to content

Commit c176231

Browse files
Merge pull request #7891 from rubygems/deivid-rodriguez/better-current-platform-debug
Print better log message when current platform is not present in the lockfile (cherry picked from commit 894b724)
1 parent 060d1f8 commit c176231

File tree

3 files changed

+47
-16
lines changed

3 files changed

+47
-16
lines changed

bundler/lib/bundler/definition.rb

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def initialize(lockfile, dependencies, sources, unlock, ruby_version = nil, opti
137137
end
138138
@unlocking ||= @unlock[:ruby] ||= (!@locked_ruby_version ^ !@ruby_version)
139139

140-
add_current_platform unless Bundler.frozen_bundle?
140+
@current_platform_missing = add_current_platform unless Bundler.frozen_bundle?
141141

142142
converge_path_sources_to_gemspec_sources
143143
@path_changes = converge_paths
@@ -484,6 +484,7 @@ def nothing_changed?
484484

485485
!@source_changes &&
486486
!@dependency_changes &&
487+
!@current_platform_missing &&
487488
@new_platforms.empty? &&
488489
!@path_changes &&
489490
!@local_changes &&
@@ -671,19 +672,19 @@ def current_platform_locked?
671672
end
672673

673674
def add_current_platform
674-
@most_specific_non_local_locked_ruby_platform = find_most_specific_non_local_locked_ruby_platform
675+
return if @platforms.include?(local_platform)
676+
677+
@most_specific_non_local_locked_ruby_platform = find_most_specific_locked_ruby_platform
675678
return if @most_specific_non_local_locked_ruby_platform
676679

677-
add_platform(local_platform)
680+
@platforms << local_platform
681+
true
678682
end
679683

680-
def find_most_specific_non_local_locked_ruby_platform
684+
def find_most_specific_locked_ruby_platform
681685
return unless generic_local_platform_is_ruby? && current_platform_locked?
682686

683-
most_specific_locked_ruby_platform = most_specific_locked_platform
684-
return unless most_specific_locked_ruby_platform != local_platform
685-
686-
most_specific_locked_ruby_platform
687+
most_specific_locked_platform
687688
end
688689

689690
def change_reason
@@ -705,6 +706,7 @@ def change_reason
705706
[
706707
[@source_changes, "the list of sources changed"],
707708
[@dependency_changes, "the dependencies in your gemfile changed"],
709+
[@current_platform_missing, "your lockfile does not include the current platform"],
708710
[@new_platforms.any?, "you added a new platform to your gemfile"],
709711
[@path_changes, "the gemspecs for path gems changed"],
710712
[@local_changes, "the gemspecs for git local gems changed"],

bundler/spec/commands/install_spec.rb

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,12 +1136,16 @@ def run
11361136
end
11371137
end
11381138

1139-
context "in a frozen bundle" do
1140-
before do
1139+
context "when current platform not included in the lockfile" do
1140+
around do |example|
11411141
build_repo4 do
11421142
build_gem "libv8", "8.4.255.0" do |s|
11431143
s.platform = "x86_64-darwin-19"
11441144
end
1145+
1146+
build_gem "libv8", "8.4.255.0" do |s|
1147+
s.platform = "x86_64-linux"
1148+
end
11451149
end
11461150

11471151
gemfile <<-G
@@ -1166,11 +1170,36 @@ def run
11661170
#{Bundler::VERSION}
11671171
L
11681172

1169-
bundle "config set --local deployment true"
1173+
simulate_platform("x86_64-linux", &example)
11701174
end
11711175

1172-
it "should fail loudly if the lockfile platforms don't include the current platform" do
1173-
simulate_platform(Gem::Platform.new("x86_64-linux")) { bundle "install", raise_on_error: false }
1176+
it "adds the current platform to the lockfile" do
1177+
bundle "install --verbose"
1178+
1179+
expect(out).to include("re-resolving dependencies because your lockfile does not include the current platform")
1180+
1181+
expect(lockfile).to eq <<~L
1182+
GEM
1183+
remote: https://gem.repo4/
1184+
specs:
1185+
libv8 (8.4.255.0-x86_64-darwin-19)
1186+
libv8 (8.4.255.0-x86_64-linux)
1187+
1188+
PLATFORMS
1189+
x86_64-darwin-19
1190+
x86_64-linux
1191+
1192+
DEPENDENCIES
1193+
libv8
1194+
1195+
BUNDLED WITH
1196+
#{Bundler::VERSION}
1197+
L
1198+
end
1199+
1200+
it "fails loudly if frozen mode set" do
1201+
bundle "config set --local deployment true"
1202+
bundle "install", raise_on_error: false
11741203

11751204
expect(err).to eq(
11761205
"Your bundle only supports platforms [\"x86_64-darwin-19\"] but your local platform is x86_64-linux. " \

bundler/spec/commands/lock_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@
10611061
#{Bundler::VERSION}
10621062
G
10631063

1064-
simulate_platform(Gem::Platform.new("x86_64-darwin-19")) { bundle "lock --update" }
1064+
simulate_platform("x86_64-darwin-19") { bundle "lock --update" }
10651065

10661066
expect(out).to match(/Writing lockfile to.+Gemfile\.lock/)
10671067
end
@@ -1083,7 +1083,7 @@
10831083
gem "libv8"
10841084
G
10851085

1086-
simulate_platform(Gem::Platform.new("x86_64-darwin-19")) { bundle "lock" }
1086+
simulate_platform("x86_64-darwin-19") { bundle "lock" }
10871087

10881088
checksums = checksums_section_when_enabled do |c|
10891089
c.checksum gem_repo4, "libv8", "8.4.255.0", "x86_64-darwin-19"
@@ -1151,7 +1151,7 @@
11511151
previous_lockfile = lockfile
11521152

11531153
%w[x86_64-darwin-19 x86_64-darwin-20].each do |platform|
1154-
simulate_platform(Gem::Platform.new(platform)) do
1154+
simulate_platform(platform) do
11551155
bundle "lock"
11561156
expect(lockfile).to eq(previous_lockfile)
11571157

0 commit comments

Comments
 (0)