Skip to content

Commit

Permalink
[rubygems/rubygems] Fix another regression for sorbet
Browse files Browse the repository at this point in the history
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.

rubygems/rubygems@8fbc30a1d0
  • Loading branch information
deivid-rodriguez authored and matzbot committed Aug 25, 2022
1 parent f5f81bb commit ad8774f
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 7 deletions.
7 changes: 2 additions & 5 deletions lib/bundler/definition.rb
Expand Up @@ -484,15 +484,13 @@ def unlocking?
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)
Expand Down Expand Up @@ -896,7 +894,6 @@ def remove_ruby_from_platforms_if_necessary!(dependencies)

remove_platform(Gem::Platform::RUBY)
add_current_platform
resolver.platforms = @platforms
end

def source_map
Expand Down
2 changes: 0 additions & 2 deletions lib/bundler/resolver.rb
Expand Up @@ -7,8 +7,6 @@ class Resolver

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.
Expand Down
71 changes: 71 additions & 0 deletions spec/bundler/install/gemfile/specific_platform_spec.rb
Expand Up @@ -445,6 +445,77 @@
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"
Expand Down

0 comments on commit ad8774f

Please sign in to comment.