Skip to content

Commit

Permalink
Fix expand_dependencies logic edge case
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
deivid-rodriguez committed Sep 1, 2020
1 parent 743b2d7 commit b475adf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
3 changes: 1 addition & 2 deletions bundler/lib/bundler/definition.rb
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions bundler/spec/install/gemfile/platform_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit b475adf

Please sign in to comment.