Skip to content

Commit

Permalink
Fix crash when no matching variants are found for the current platform
Browse files Browse the repository at this point in the history
If we are resolving a dependency against a particular platform, and
there are no platform specific variants of the candidates that match
that platform, we should not consider those candidates.
  • Loading branch information
deivid-rodriguez committed Dec 15, 2021
1 parent 077e3c2 commit f6077fe
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion bundler/lib/bundler/resolver.rb
Expand Up @@ -134,6 +134,7 @@ def search_for(dependency_proxy)
end
nested.reduce([]) do |groups, (version, specs)|
next groups if locked_requirement && !locked_requirement.satisfied_by?(version)
next groups unless specs.any? {|spec| spec.match_platform(platform) }

specs_by_platform = Hash.new do |current_specs, current_platform|
current_specs[current_platform] = select_best_platform_match(specs, current_platform)
Expand All @@ -145,7 +146,7 @@ def search_for(dependency_proxy)
next groups if @resolving_only_for_ruby

spec_group = SpecGroup.create_for(specs_by_platform, @platforms, platform)
groups << spec_group if spec_group
groups << spec_group

groups
end
Expand Down
20 changes: 20 additions & 0 deletions bundler/spec/install/gemfile/specific_platform_spec.rb
Expand Up @@ -282,6 +282,26 @@
bundle "install --verbose"
end

it "does not resolve if the current platform does not match any of available platform specific variants for a top level dependency" do
build_repo2 do
build_gem("sorbet-static", "0.5.6433") {|s| s.platform = "x86_64-linux" }
build_gem("sorbet-static", "0.5.6433") {|s| s.platform = "universal-darwin-20" }
end

gemfile <<~G
source "#{file_uri_for(gem_repo2)}"
gem "sorbet-static", "0.5.6433"
G

simulate_platform "arm64-darwin-21" do
bundle "install", :raise_on_error => false
end

expect(err).to include("Could not find gem 'sorbet-static (= 0.5.6433) arm64-darwin-21' in rubygems repository #{file_uri_for(gem_repo2)}/ or installed locally.")
expect(err).to include("The source contains the following gems matching 'sorbet-static (= 0.5.6433)': sorbet-static-0.5.6433-universal-darwin-20, sorbet-static-0.5.6433-x86_64-linux")
end

private

def setup_multiplatform_gem
Expand Down

0 comments on commit f6077fe

Please sign in to comment.