diff options
author | David RodrÃguez <deivid.rodriguez@riseup.net> | 2023-03-17 14:18:30 +0100 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2023-11-13 11:06:10 +0900 |
commit | 435eb56f6175b7c9a16121ec8441f7492fa9aec5 (patch) | |
tree | 086201ded65f06c9f09d057287ce92778fe9abaf /spec/bundler/install | |
parent | 59b361aaca0194bd526e32b7053948a49da4e39d (diff) |
[rubygems/rubygems] Automatically lock extra ruby platforms
Since we started locking the specific platform in the lockfile, that has
created an annoying situation for users that don't develop on Linux.
They will create a lockfile on their machines, locking their local
platform, for example, darwin. But then that lockfile won't work
automatically when deploying to Heroku for example, because the lockfile
is frozen and the Linux platform is not included.
There's the chance though that resolving against two platforms (Linux +
the local platform) won't succeed while resolving for just the current
platform will. So, instead, we check other platform specific variants
available for the resolution we initially found, and lock those
platforms and specs too if they satisfy the resolution.
This is only done when generating new lockfiles from scratch, existing
lockfiles should keep working as before, and it's only done for "ruby
platforms", i.e., not Java or Windows which have their own complexities,
and so are excluded.
With this change, we expect that MacOS users can bundle locally and
deploy to Heroku without needing to do anything special.
https://github.com/rubygems/rubygems/commit/5f24f06bc5
Diffstat (limited to 'spec/bundler/install')
-rw-r--r-- | spec/bundler/install/gemfile/sources_spec.rb | 30 | ||||
-rw-r--r-- | spec/bundler/install/gemfile/specific_platform_spec.rb | 136 |
2 files changed, 133 insertions, 33 deletions
diff --git a/spec/bundler/install/gemfile/sources_spec.rb b/spec/bundler/install/gemfile/sources_spec.rb index 64eed1a2f4..15ff15e46d 100644 --- a/spec/bundler/install/gemfile/sources_spec.rb +++ b/spec/bundler/install/gemfile/sources_spec.rb @@ -379,7 +379,7 @@ RSpec.describe "bundle install with gems on multiple sources" do rack PLATFORMS - #{local_platform} + #{lockfile_platforms} DEPENDENCIES depends_on_rack! @@ -422,7 +422,7 @@ RSpec.describe "bundle install with gems on multiple sources" do rack PLATFORMS - #{local_platform} + #{lockfile_platforms} DEPENDENCIES depends_on_rack! @@ -803,7 +803,7 @@ RSpec.describe "bundle install with gems on multiple sources" do zeitwerk (2.4.2) PLATFORMS - #{local_platform} + #{lockfile_platforms} DEPENDENCIES activesupport @@ -874,7 +874,7 @@ RSpec.describe "bundle install with gems on multiple sources" do sidekiq (>= 6.1.0) PLATFORMS - #{local_platform} + #{lockfile_platforms} DEPENDENCIES activesupport @@ -975,7 +975,7 @@ RSpec.describe "bundle install with gems on multiple sources" do sidekiq (>= 6.1.0) PLATFORMS - #{local_platform} + #{lockfile_platforms} DEPENDENCIES activesupport @@ -1049,7 +1049,7 @@ RSpec.describe "bundle install with gems on multiple sources" do sidekiq (>= 6.1.0) PLATFORMS - #{local_platform} + #{lockfile_platforms} DEPENDENCIES activesupport @@ -1146,7 +1146,7 @@ RSpec.describe "bundle install with gems on multiple sources" do nokogiri (>= 1.2.3) PLATFORMS - #{local_platform} + #{lockfile_platforms} DEPENDENCIES handsoap! @@ -1209,7 +1209,7 @@ RSpec.describe "bundle install with gems on multiple sources" do rack (0.9.1) PLATFORMS - #{local_platform} + #{lockfile_platforms} DEPENDENCIES rack! @@ -1239,7 +1239,7 @@ RSpec.describe "bundle install with gems on multiple sources" do rack (0.9.1) PLATFORMS - #{local_platform} + #{lockfile_platforms} DEPENDENCIES rack! @@ -1261,7 +1261,7 @@ RSpec.describe "bundle install with gems on multiple sources" do rack (0.9.1) PLATFORMS - #{local_platform} + #{lockfile_platforms} DEPENDENCIES rack! @@ -1701,7 +1701,7 @@ RSpec.describe "bundle install with gems on multiple sources" do mime-types (3.3.1) PLATFORMS - #{local_platform} + #{lockfile_platforms} DEPENDENCIES capybara (~> 2.5.0) @@ -1732,7 +1732,7 @@ RSpec.describe "bundle install with gems on multiple sources" do mime-types (3.0.0) PLATFORMS - #{local_platform} + #{lockfile_platforms} DEPENDENCIES capybara (~> 2.5.0) @@ -1789,7 +1789,7 @@ RSpec.describe "bundle install with gems on multiple sources" do pdf-writer (= 1.1.8) PLATFORMS - #{local_platform} + #{lockfile_platforms} DEPENDENCIES ruport (= 1.7.0.3)! @@ -1851,7 +1851,7 @@ RSpec.describe "bundle install with gems on multiple sources" do pdf-writer (= 1.1.8) PLATFORMS - #{local_platform} + #{lockfile_platforms} DEPENDENCIES ruport (= 1.7.0.3)! @@ -1899,7 +1899,7 @@ RSpec.describe "bundle install with gems on multiple sources" do pdf-writer (1.1.8) PLATFORMS - #{local_platform} + #{lockfile_platforms} DEPENDENCIES pdf-writer (= 1.1.8) diff --git a/spec/bundler/install/gemfile/specific_platform_spec.rb b/spec/bundler/install/gemfile/specific_platform_spec.rb index 099ef35bbf..0c9816eaac 100644 --- a/spec/bundler/install/gemfile/specific_platform_spec.rb +++ b/spec/bundler/install/gemfile/specific_platform_spec.rb @@ -11,11 +11,11 @@ RSpec.describe "bundle install with specific platforms" do setup_multiplatform_gem install_gemfile(google_protobuf) allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) - expect(the_bundle.locked_gems.platforms).to eq([pl("x86_64-darwin-15")]) + expect(the_bundle.locked_gems.platforms).to include(pl("x86_64-darwin-15")) expect(the_bundle).to include_gem("google-protobuf 3.0.0.alpha.5.0.5.1 universal-darwin") - expect(the_bundle.locked_gems.specs.map(&:full_name)).to eq(%w[ - google-protobuf-3.0.0.alpha.5.0.5.1-universal-darwin - ]) + expect(the_bundle.locked_gems.specs.map(&:full_name)).to include( + "google-protobuf-3.0.0.alpha.5.0.5.1-universal-darwin" + ) end end @@ -309,10 +309,10 @@ RSpec.describe "bundle install with specific platforms" do G allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) - expect(the_bundle.locked_gems.platforms).to eq([pl("x86_64-darwin-15")]) + expect(the_bundle.locked_gems.platforms).to include(pl("x86_64-darwin-15")) expect(the_bundle).to include_gems("facter 2.4.6 universal-darwin", "CFPropertyList 1.0") - expect(the_bundle.locked_gems.specs.map(&:full_name)).to eq(["CFPropertyList-1.0", - "facter-2.4.6-universal-darwin"]) + expect(the_bundle.locked_gems.specs.map(&:full_name)).to include("CFPropertyList-1.0", + "facter-2.4.6-universal-darwin") end end @@ -327,8 +327,8 @@ RSpec.describe "bundle install with specific platforms" do install_gemfile(google_protobuf) bundle "lock --add-platform=#{x64_mingw32}" - expect(the_bundle.locked_gems.platforms).to eq([x64_mingw32, pl("x86_64-darwin-15")]) - expect(the_bundle.locked_gems.specs.map(&:full_name)).to eq(%w[ + expect(the_bundle.locked_gems.platforms).to include(x64_mingw32, pl("x86_64-darwin-15")) + expect(the_bundle.locked_gems.specs.map(&:full_name)).to include(*%w[ google-protobuf-3.0.0.alpha.5.0.5.1-universal-darwin google-protobuf-3.0.0.alpha.5.0.5.1-x64-mingw32 ]) @@ -341,11 +341,11 @@ RSpec.describe "bundle install with specific platforms" do install_gemfile(google_protobuf) bundle "lock --add-platform=#{java}" - expect(the_bundle.locked_gems.platforms).to eq([java, pl("x86_64-darwin-15")]) - expect(the_bundle.locked_gems.specs.map(&:full_name)).to eq(%w[ - google-protobuf-3.0.0.alpha.5.0.5.1 - google-protobuf-3.0.0.alpha.5.0.5.1-universal-darwin - ]) + expect(the_bundle.locked_gems.platforms).to include(java, pl("x86_64-darwin-15")) + expect(the_bundle.locked_gems.specs.map(&:full_name)).to include( + "google-protobuf-3.0.0.alpha.5.0.5.1", + "google-protobuf-3.0.0.alpha.5.0.5.1-universal-darwin" + ) end end end @@ -517,7 +517,7 @@ RSpec.describe "bundle install with specific platforms" do sorbet-runtime (= 0.5.10160) PLATFORMS - #{lockfile_platforms("ruby")} + #{lockfile_platforms} DEPENDENCIES sorbet-static-and-runtime @@ -548,7 +548,7 @@ RSpec.describe "bundle install with specific platforms" do sorbet-runtime (= 0.5.10160) PLATFORMS - #{lockfile_platforms} + #{local_platform} DEPENDENCIES sorbet-static-and-runtime @@ -601,7 +601,7 @@ RSpec.describe "bundle install with specific platforms" do DEPENDENCIES nokogiri - sorbet + sorbet-static BUNDLED WITH #{Bundler::VERSION} @@ -702,7 +702,7 @@ RSpec.describe "bundle install with specific platforms" do sorbet-runtime (= 0.5.10160) PLATFORMS - #{lockfile_platforms} + #{local_platform} DEPENDENCIES sorbet-static-and-runtime @@ -1067,6 +1067,106 @@ RSpec.describe "bundle install with specific platforms" do end end + it "locks specific platforms automatically" do + simulate_platform "x86_64-linux" do + build_repo4 do + build_gem "nokogiri", "1.14.0" + build_gem "nokogiri", "1.14.0" do |s| + s.platform = "x86_64-linux" + end + build_gem "nokogiri", "1.14.0" do |s| + s.platform = "arm-linux" + end + build_gem "nokogiri", "1.14.0" do |s| + s.platform = "x64-mingw32" + end + build_gem "nokogiri", "1.14.0" do |s| + s.platform = "java" + end + + build_gem "sorbet-static", "0.5.10696" do |s| + s.platform = "x86_64-linux" + end + build_gem "sorbet-static", "0.5.10696" do |s| + s.platform = "universal-darwin-22" + end + end + + gemfile <<~G + source "#{file_uri_for(gem_repo4)}" + + gem "nokogiri" + G + + bundle "lock" + + # locks all compatible platforms, excluding Java and Windows + expect(lockfile).to eq(<<~L) + GEM + remote: #{file_uri_for(gem_repo4)}/ + specs: + nokogiri (1.14.0) + nokogiri (1.14.0-arm-linux) + nokogiri (1.14.0-x86_64-linux) + + PLATFORMS + arm-linux + ruby + x86_64-linux + + DEPENDENCIES + nokogiri + + CHECKSUMS + #{gem_no_checksum "nokogiri", "1.14.0"} + #{gem_no_checksum "nokogiri", "1.14.0", "arm-linux"} + #{gem_no_checksum "nokogiri", "1.14.0", "x86_64-linux"} + + BUNDLED WITH + #{Bundler::VERSION} + L + + gemfile <<~G + source "#{file_uri_for(gem_repo4)}" + + gem "nokogiri" + gem "sorbet-static" + G + + FileUtils.rm bundled_app_lock + + bundle "lock" + + # locks only platforms compatible with all gems in the bundle + expect(lockfile).to eq(<<~L) + GEM + remote: #{file_uri_for(gem_repo4)}/ + specs: + nokogiri (1.14.0) + nokogiri (1.14.0-x86_64-linux) + sorbet-static (0.5.10696-universal-darwin-22) + sorbet-static (0.5.10696-x86_64-linux) + + PLATFORMS + universal-darwin-22 + x86_64-linux + + DEPENDENCIES + nokogiri + sorbet-static + + CHECKSUMS + #{gem_no_checksum "nokogiri", "1.14.0"} + #{gem_no_checksum "nokogiri", "1.14.0", "x86_64-linux"} + #{gem_no_checksum "sorbet-static", "0.5.10696", "universal-darwin-22"} + #{gem_no_checksum "sorbet-static", "0.5.10696", "x86_64-linux"} + + BUNDLED WITH + #{Bundler::VERSION} + L + end + end + private def setup_multiplatform_gem |