From b475adf605fa03b4f376e17cb427ab24eb3c0d6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Thu, 27 Aug 2020 17:47:09 +0200 Subject: [PATCH] Fix `expand_dependencies` logic edge case In the case of running under jruby, on a frozen bundle, and against a lockfile only including the ruby platform, `expand_dependencies` would end up filtering out all dependencies, causing errors. The reason is that on a frozen bundle, the local platform is not added to the array of definition platforms, since only platform information from the lockfile should be used. That means that under the previous logic, `expand_dependencies` would filter out everything. The solution is to make sure to always _at least_ expand all dependencies with the local platform. --- bundler/lib/bundler/definition.rb | 3 +-- bundler/spec/install/gemfile/platform_spec.rb | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/bundler/lib/bundler/definition.rb b/bundler/lib/bundler/definition.rb index 107a55e2af76..003ba63ee4f3 100644 --- a/bundler/lib/bundler/definition.rb +++ b/bundler/lib/bundler/definition.rb @@ -890,8 +890,7 @@ def expand_dependencies(dependencies, remote = false) dependencies.each do |dep| dep = Dependency.new(dep, ">= 0") unless dep.respond_to?(:name) next unless remote || dep.current_platform? - target_platforms = dep.gem_platforms(Resolver.sort_platforms(@platforms)) - target_platforms &= [generic_local_platform] unless remote + target_platforms = dep.gem_platforms(remote ? Resolver.sort_platforms(@platforms) : [generic_local_platform]) deps += expand_dependency_with_platforms(dep, target_platforms) end deps diff --git a/bundler/spec/install/gemfile/platform_spec.rb b/bundler/spec/install/gemfile/platform_spec.rb index dd58aef29b1d..ad351ebd03b3 100644 --- a/bundler/spec/install/gemfile/platform_spec.rb +++ b/bundler/spec/install/gemfile/platform_spec.rb @@ -50,6 +50,31 @@ expect(the_bundle).to include_gems "platform_specific 1.0 JAVA" end + it "pulls the pure ruby version on jruby if the java platform is not present in the lockfile and bundler is run in frozen mode", :jruby do + lockfile <<-G + GEM + remote: #{file_uri_for(gem_repo1)} + specs: + platform_specific (1.0) + + PLATFORMS + ruby + + DEPENDENCIES + platform_specific + G + + bundle "config set --local frozen true" + + install_gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + + gem "platform_specific" + G + + expect(the_bundle).to include_gems "platform_specific 1.0 RUBY" + end + it "works with gems that have different dependencies" do simulate_platform "java" install_gemfile <<-G