ruby-changes:73056
From: David <ko1@a...>
Date: Thu, 25 Aug 2022 23:39:17 +0900 (JST)
Subject: [ruby-changes:73056] ad8774f8e5 (master): [rubygems/rubygems] Fix another regression for sorbet
https://git.ruby-lang.org/ruby.git/commit/?id=ad8774f8e5 From ad8774f8e537a3ad73ce56bd12e75c85271f93a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= <deivid.rodriguez@r...> Date: Wed, 24 Aug 2022 22:54:33 +0200 Subject: [rubygems/rubygems] Fix another regression for sorbet Recently a changed was introduced to update the resolver platforms after it has been created, in order to remove the "ruby" platform from it if it's to be removed from the lockfile. However, it did not update the `@resolving_only_for_ruby` instance variable in that case, so the resolver was not properly doing the right thing anymore. To fix this, I tweaked the code to restore not changing resolver platforms after the resolver has been instantiated. https://github.com/rubygems/rubygems/commit/8fbc30a1d0 --- lib/bundler/definition.rb | 7 +-- lib/bundler/resolver.rb | 2 - .../install/gemfile/specific_platform_spec.rb | 71 ++++++++++++++++++++++ 3 files changed, 73 insertions(+), 7 deletions(-) diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index 66efd82b53..8bd9e11f32 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -484,15 +484,13 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/definition.rb#L484 def resolver @resolver ||= begin last_resolve = converge_locked_specs + remove_ruby_from_platforms_if_necessary!(dependencies) Resolver.new(source_requirements, last_resolve, gem_version_promoter, additional_base_requirements_for_resolve, platforms) end end def expanded_dependencies - @expanded_dependencies ||= begin - remove_ruby_from_platforms_if_necessary!(dependencies) - expand_dependencies(dependencies + metadata_dependencies, true) - end + @expanded_dependencies ||= expand_dependencies(dependencies + metadata_dependencies, true) end def filter_specs(specs, deps) @@ -896,7 +894,6 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/definition.rb#L894 remove_platform(Gem::Platform::RUBY) add_current_platform - resolver.platforms = @platforms end def source_map diff --git a/lib/bundler/resolver.rb b/lib/bundler/resolver.rb index e382319112..a74af45027 100644 --- a/lib/bundler/resolver.rb +++ b/lib/bundler/resolver.rb @@ -7,8 +7,6 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/resolver.rb#L7 include GemHelpers - attr_writer :platforms - # Figures out the best possible configuration of gems that satisfies # the list of passed dependencies and any child dependencies without # causing any gem activation errors. diff --git a/spec/bundler/install/gemfile/specific_platform_spec.rb b/spec/bundler/install/gemfile/specific_platform_spec.rb index bb5526203f..094186e63d 100644 --- a/spec/bundler/install/gemfile/specific_platform_spec.rb +++ b/spec/bundler/install/gemfile/specific_platform_spec.rb @@ -445,6 +445,77 @@ RSpec.describe "bundle install with specific platforms" do https://github.com/ruby/ruby/blob/trunk/spec/bundler/install/gemfile/specific_platform_spec.rb#L445 L end + it "automatically fixes the lockfile if only RUBY platform is locked and some gem has no RUBY variant available" do + build_repo4 do + build_gem("sorbet-static-and-runtime", "0.5.10160") do |s| + s.add_runtime_dependency "sorbet", "= 0.5.10160" + s.add_runtime_dependency "sorbet-runtime", "= 0.5.10160" + end + + build_gem("sorbet", "0.5.10160") do |s| + s.add_runtime_dependency "sorbet-static", "= 0.5.10160" + end + + build_gem("sorbet-runtime", "0.5.10160") + + build_gem("sorbet-static", "0.5.10160") do |s| + s.platform = Gem::Platform.local + end + end + + gemfile <<~G + source "#{file_uri_for(gem_repo4)}" + + gem "sorbet-static-and-runtime" + G + + lockfile <<~L + GEM + remote: #{file_uri_for(gem_repo4)}/ + specs: + sorbet (0.5.10160) + sorbet-static (= 0.5.10160) + sorbet-runtime (0.5.10160) + sorbet-static (0.5.10160-#{Gem::Platform.local}) + sorbet-static-and-runtime (0.5.10160) + sorbet (= 0.5.10160) + sorbet-runtime (= 0.5.10160) + + PLATFORMS + ruby + + DEPENDENCIES + sorbet-static-and-runtime + + BUNDLED WITH + #{Bundler::VERSION} + L + + bundle "update" + + expect(lockfile).to eq <<~L + GEM + remote: #{file_uri_for(gem_repo4)}/ + specs: + sorbet (0.5.10160) + sorbet-static (= 0.5.10160) + sorbet-runtime (0.5.10160) + sorbet-static (0.5.10160-#{Gem::Platform.local}) + sorbet-static-and-runtime (0.5.10160) + sorbet (= 0.5.10160) + sorbet-runtime (= 0.5.10160) + + PLATFORMS + #{lockfile_platforms} + + DEPENDENCIES + sorbet-static-and-runtime + + BUNDLED WITH + #{Bundler::VERSION} + L + end + it "does not remove ruby if gems for other platforms, and not present in the lockfile, exist in the Gemfile" do build_repo4 do build_gem "nokogiri", "1.13.8" -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/