diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index a96fd36b6a..c7de130f24 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -137,7 +137,7 @@ module Bundler end @unlocking ||= @unlock[:ruby] ||= (!@locked_ruby_version ^ !@ruby_version) - add_current_platform unless Bundler.frozen_bundle? + @current_platform_missing = add_current_platform unless Bundler.frozen_bundle? converge_path_sources_to_gemspec_sources @path_changes = converge_paths @@ -484,6 +484,7 @@ module Bundler !@source_changes && !@dependency_changes && + !@current_platform_missing && @new_platforms.empty? && !@path_changes && !@local_changes && @@ -676,7 +677,8 @@ module Bundler @most_specific_non_local_locked_ruby_platform = find_most_specific_locked_ruby_platform return if @most_specific_non_local_locked_ruby_platform - add_platform(local_platform) + @platforms << local_platform + true end def find_most_specific_locked_ruby_platform @@ -704,6 +706,7 @@ module Bundler [ [@source_changes, "the list of sources changed"], [@dependency_changes, "the dependencies in your gemfile changed"], + [@current_platform_missing, "your lockfile does not include the current platform"], [@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"], diff --git a/spec/bundler/commands/install_spec.rb b/spec/bundler/commands/install_spec.rb index bff7fd8460..09f920052a 100644 --- a/spec/bundler/commands/install_spec.rb +++ b/spec/bundler/commands/install_spec.rb @@ -1136,12 +1136,16 @@ RSpec.describe "bundle install with gem sources" do end end - context "in a frozen bundle" do - before do + context "when current platform not included in the lockfile" do + around do |example| build_repo4 do build_gem "libv8", "8.4.255.0" do |s| s.platform = "x86_64-darwin-19" end + + build_gem "libv8", "8.4.255.0" do |s| + s.platform = "x86_64-linux" + end end gemfile <<-G @@ -1166,11 +1170,36 @@ RSpec.describe "bundle install with gem sources" do #{Bundler::VERSION} L - bundle "config set --local deployment true" + simulate_platform("x86_64-linux", &example) end - it "should fail loudly if the lockfile platforms don't include the current platform" do - simulate_platform("x86_64-linux") { bundle "install", raise_on_error: false } + it "adds the current platform to the lockfile" do + bundle "install --verbose" + + expect(out).to include("re-resolving dependencies because your lockfile does not include the current platform") + + expect(lockfile).to eq <<~L + GEM + remote: https://gem.repo4/ + specs: + libv8 (8.4.255.0-x86_64-darwin-19) + libv8 (8.4.255.0-x86_64-linux) + + PLATFORMS + x86_64-darwin-19 + x86_64-linux + + DEPENDENCIES + libv8 + + BUNDLED WITH + #{Bundler::VERSION} + L + end + + it "fails loudly if frozen mode set" do + bundle "config set --local deployment true" + bundle "install", raise_on_error: false expect(err).to eq( "Your bundle only supports platforms [\"x86_64-darwin-19\"] but your local platform is x86_64-linux. " \