diff options
author | David RodrÃguez <[email protected]> | 2022-08-24 22:54:33 +0200 |
---|---|---|
committer | git <[email protected]> | 2022-08-25 23:39:02 +0900 |
commit | ad8774f8e537a3ad73ce56bd12e75c85271f93a3 (patch) | |
tree | 0bb3a958751cd7f6d93b54919b7fb6375713076b | |
parent | f5f81bb777bb1dbf8da3f976136733e65b026fef (diff) |
[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
-rw-r--r-- | lib/bundler/definition.rb | 7 | ||||
-rw-r--r-- | lib/bundler/resolver.rb | 2 | ||||
-rw-r--r-- | spec/bundler/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 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 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 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 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" |