From d52e0c9ab6b90af91eb292072a186984e96e3494 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Thu, 27 Aug 2020 16:36:44 +0200 Subject: [PATCH 1/6] Remove unused method --- bundler/lib/bundler/definition.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/bundler/lib/bundler/definition.rb b/bundler/lib/bundler/definition.rb index b03d4d7a8c5f..63204755f7b2 100644 --- a/bundler/lib/bundler/definition.rb +++ b/bundler/lib/bundler/definition.rb @@ -204,10 +204,6 @@ def removed_specs @locked_specs - specs end - def new_platform? - @new_platform - end - def missing_specs missing = [] resolve.materialize(requested_dependencies, missing) From c9893ca843cdd820890c7aa594ea1da1539e8099 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Thu, 27 Aug 2020 17:47:40 +0200 Subject: [PATCH 2/6] Simplify logic --- bundler/lib/bundler/definition.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundler/lib/bundler/definition.rb b/bundler/lib/bundler/definition.rb index 63204755f7b2..22181fc65ee7 100644 --- a/bundler/lib/bundler/definition.rb +++ b/bundler/lib/bundler/definition.rb @@ -891,7 +891,7 @@ def expand_dependencies(dependencies, remote = false) deps = [] dependencies.each do |dep| dep = Dependency.new(dep, ">= 0") unless dep.respond_to?(:name) - next if !remote && !dep.current_platform? + next unless remote || dep.current_platform? dep.gem_platforms(sorted_platforms).each do |p| deps << DepProxy.new(dep, p) if remote || p == generic_local_platform end From e6b6980e38760720091bd145c7d7036043c9b7ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Thu, 27 Aug 2020 18:12:39 +0200 Subject: [PATCH 3/6] Move local variable inline to where it's used --- bundler/lib/bundler/definition.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bundler/lib/bundler/definition.rb b/bundler/lib/bundler/definition.rb index 22181fc65ee7..6392e1a16d79 100644 --- a/bundler/lib/bundler/definition.rb +++ b/bundler/lib/bundler/definition.rb @@ -887,12 +887,11 @@ def ruby_version_requirements(ruby_version) end def expand_dependencies(dependencies, remote = false) - sorted_platforms = Resolver.sort_platforms(@platforms) deps = [] dependencies.each do |dep| dep = Dependency.new(dep, ">= 0") unless dep.respond_to?(:name) next unless remote || dep.current_platform? - dep.gem_platforms(sorted_platforms).each do |p| + dep.gem_platforms(Resolver.sort_platforms(@platforms)).each do |p| deps << DepProxy.new(dep, p) if remote || p == generic_local_platform end end From e6629e66c298f98237032c0eaded5ad9821afc05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Thu, 27 Aug 2020 19:01:01 +0200 Subject: [PATCH 4/6] Small refactor --- bundler/lib/bundler/definition.rb | 5 ++--- bundler/lib/bundler/gem_helpers.rb | 7 ++++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/bundler/lib/bundler/definition.rb b/bundler/lib/bundler/definition.rb index 6392e1a16d79..2af1de319b3c 100644 --- a/bundler/lib/bundler/definition.rb +++ b/bundler/lib/bundler/definition.rb @@ -553,10 +553,9 @@ def add_platforms end def current_platforms - current_platform = Bundler.local_platform [].tap do |platforms| - platforms << current_platform if Bundler.feature_flag.specific_platform? - platforms << generic(current_platform) + platforms << local_platform if Bundler.feature_flag.specific_platform? + platforms << generic_local_platform end end diff --git a/bundler/lib/bundler/gem_helpers.rb b/bundler/lib/bundler/gem_helpers.rb index be047f43977d..2a097375c0cc 100644 --- a/bundler/lib/bundler/gem_helpers.rb +++ b/bundler/lib/bundler/gem_helpers.rb @@ -24,10 +24,15 @@ def generic(p) module_function :generic def generic_local_platform - generic(Bundler.local_platform) + generic(local_platform) end module_function :generic_local_platform + def local_platform + Bundler.local_platform + end + module_function :local_platform + def platform_specificity_match(spec_platform, user_platform) spec_platform = Gem::Platform.new(spec_platform) return PlatformMatch::EXACT_MATCH if spec_platform == user_platform From 743b2d788f88eddbeb3836e8fa3d566946eae29f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Thu, 27 Aug 2020 19:40:33 +0200 Subject: [PATCH 5/6] Refactor `expand_dependencies` logic --- bundler/lib/bundler/definition.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/bundler/lib/bundler/definition.rb b/bundler/lib/bundler/definition.rb index 2af1de319b3c..107a55e2af76 100644 --- a/bundler/lib/bundler/definition.rb +++ b/bundler/lib/bundler/definition.rb @@ -890,13 +890,19 @@ 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? - dep.gem_platforms(Resolver.sort_platforms(@platforms)).each do |p| - deps << DepProxy.new(dep, p) if remote || p == generic_local_platform - end + target_platforms = dep.gem_platforms(Resolver.sort_platforms(@platforms)) + target_platforms &= [generic_local_platform] unless remote + deps += expand_dependency_with_platforms(dep, target_platforms) end deps end + def expand_dependency_with_platforms(dep, platforms) + platforms.map do |p| + DepProxy.new(dep, p) + end + end + def dependencies_for(groups) current_dependencies.reject do |d| (d.groups & groups).empty? 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 6/6] 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