From 3ca83a01484351fd4158a8b077409a4cc026e8dd Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Fri, 17 Jan 2020 09:03:47 +0900 Subject: Don't ignore resolved platform information This is a follow-up change of #7522. --- lib/bundler/lazy_specification.rb | 9 +++++++-- lib/bundler/match_platform.rb | 5 ++++- spec/install/gems/resolving_spec.rb | 23 +++++++++++++++++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/lib/bundler/lazy_specification.rb b/lib/bundler/lazy_specification.rb index 7a6f5614ef..a6aeb16648 100644 --- a/lib/bundler/lazy_specification.rb +++ b/lib/bundler/lazy_specification.rb @@ -80,8 +80,13 @@ module Bundler @specification = if source.is_a?(Source::Gemspec) && source.gemspec.name == name source.gemspec.tap {|s| s.source = source } else - search = source.specs.search(search_object).last - if search && Gem::Platform.new(search.platform) != Gem::Platform.new(platform) && !search.runtime_dependencies.-(dependencies.reject {|d| d.type == :development }).empty? + platform_object = Gem::Platform.new(platform) + candidates = source.specs.search(search_object) + same_platform_candidates = candidates.select do |spec| + MatchPlatform.platforms_match?(spec.platform, platform_object) + end + search = same_platform_candidates.last || candidates.last + if search && Gem::Platform.new(search.platform) != platform_object && !search.runtime_dependencies.-(dependencies.reject {|d| d.type == :development }).empty? Bundler.ui.warn "Unable to use the platform-specific (#{search.platform}) version of #{name} (#{version}) " \ "because it has different dependencies from the #{platform} version. " \ "To use the platform-specific version of the gem, run `bundle config set specific_platform true` and install again." diff --git a/lib/bundler/match_platform.rb b/lib/bundler/match_platform.rb index 69074925a6..81d85d8e46 100644 --- a/lib/bundler/match_platform.rb +++ b/lib/bundler/match_platform.rb @@ -15,7 +15,10 @@ module Bundler return true if Gem::Platform::RUBY == gemspec_platform return true if local_platform == gemspec_platform gemspec_platform = Gem::Platform.new(gemspec_platform) - return true if GemHelpers.generic(gemspec_platform) === local_platform + generic_gemspec_platform = GemHelpers.generic(gemspec_platform) + unless generic_gemspec_platform == Gem::Platform::RUBY + return true if generic_gemspec_platform === local_platform + end return true if gemspec_platform === local_platform false diff --git a/spec/install/gems/resolving_spec.rb b/spec/install/gems/resolving_spec.rb index 547d13134f..1c7554700a 100644 --- a/spec/install/gems/resolving_spec.rb +++ b/spec/install/gems/resolving_spec.rb @@ -143,6 +143,29 @@ RSpec.describe "bundle install with install-time dependencies" do expect(out).to_not include("rack-9001.0.0 requires ruby version > 9000") expect(the_bundle).to include_gems("rack 1.2") end + + it "installs the older not platform specific version" do + build_repo4 do + build_gem "rack", "9001.0.0" do |s| + s.required_ruby_version = "> 9000" + end + build_gem "rack", "1.2" do |s| + s.platform = Bundler.local_platform + s.required_ruby_version = "> 9000" + end + build_gem "rack", "1.2" + end + + install_gemfile <<-G, :artifice => "compact_index_rate_limited", :env => { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s } + ruby "#{RUBY_VERSION}" + source "http://localgemserver.test/" + gem 'rack' + G + + expect(out).to_not include("rack-9001.0.0 requires ruby version > 9000") + expect(out).to_not include("rack-1.2-#{Bundler.local_platform} requires ruby version > 9000") + expect(the_bundle).to include_gems("rack 1.2") + end end context "allows no gems" do -- cgit v1.2.1 From a634e0a6c64b69e3bd5d8d528d7b311e73e31c58 Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Fri, 17 Jan 2020 09:51:11 +0900 Subject: Revert MatchPlatform#platforms_match? Because some examples are failed: rspec ./spec/cache/gems_spec.rb:236 # bundle cache when previously cached doesn't remove gems that are for another platform rspec ./spec/commands/install_spec.rb:220 # bundle install with gem sources the simple case with a gem that installs multiple platforms installs gems for the local platform as first choice rspec ./spec/commands/update_spec.rb:39 # bundle update with --all updates the entire bundle rspec ./spec/commands/update_spec.rb:49 # bundle update with --all doesn't delete the Gemfile.lock file if something goes wrong rspec ./spec/commands/update_spec.rb:104 # bundle update with a top level dependency unlocks all child dependencies that are unrelated to other locked dependencies rspec ./spec/commands/update_spec.rb:115 # bundle update with an unknown dependency should inform the user rspec ./spec/commands/update_spec.rb:119 # bundle update with an unknown dependency should suggest alternatives rspec ./spec/commands/update_spec.rb:126 # bundle update with a child dependency should update the child dependency rspec ./spec/commands/update_spec.rb:299 # bundle update in a frozen bundle should suggest different command when frozen is set globally rspec ./spec/runtime/platform_spec.rb:60 # Bundler.setup with multi platform stuff will add the resolve for the current platform --- lib/bundler/match_platform.rb | 5 +---- spec/install/gems/resolving_spec.rb | 14 ++++++++------ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/bundler/match_platform.rb b/lib/bundler/match_platform.rb index 81d85d8e46..69074925a6 100644 --- a/lib/bundler/match_platform.rb +++ b/lib/bundler/match_platform.rb @@ -15,10 +15,7 @@ module Bundler return true if Gem::Platform::RUBY == gemspec_platform return true if local_platform == gemspec_platform gemspec_platform = Gem::Platform.new(gemspec_platform) - generic_gemspec_platform = GemHelpers.generic(gemspec_platform) - unless generic_gemspec_platform == Gem::Platform::RUBY - return true if generic_gemspec_platform === local_platform - end + return true if GemHelpers.generic(gemspec_platform) === local_platform return true if gemspec_platform === local_platform false diff --git a/spec/install/gems/resolving_spec.rb b/spec/install/gems/resolving_spec.rb index 1c7554700a..2f46661058 100644 --- a/spec/install/gems/resolving_spec.rb +++ b/spec/install/gems/resolving_spec.rb @@ -150,17 +150,19 @@ RSpec.describe "bundle install with install-time dependencies" do s.required_ruby_version = "> 9000" end build_gem "rack", "1.2" do |s| - s.platform = Bundler.local_platform + s.platform = mingw s.required_ruby_version = "> 9000" end build_gem "rack", "1.2" end - install_gemfile <<-G, :artifice => "compact_index_rate_limited", :env => { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s } - ruby "#{RUBY_VERSION}" - source "http://localgemserver.test/" - gem 'rack' - G + simulate_platform mingw do + install_gemfile <<-G, :artifice => "compact_index_rate_limited", :env => { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s } + ruby "#{RUBY_VERSION}" + source "http://localgemserver.test/" + gem 'rack' + G + end expect(out).to_not include("rack-9001.0.0 requires ruby version > 9000") expect(out).to_not include("rack-1.2-#{Bundler.local_platform} requires ruby version > 9000") -- cgit v1.2.1 From 0629cb41dd2b780cfb88971dabe06b06d1d77e0a Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Fri, 17 Jan 2020 18:19:19 +0900 Subject: Don't use needless specific API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: David Rodríguez --- spec/install/gems/resolving_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/install/gems/resolving_spec.rb b/spec/install/gems/resolving_spec.rb index 2f46661058..fc2936b28c 100644 --- a/spec/install/gems/resolving_spec.rb +++ b/spec/install/gems/resolving_spec.rb @@ -157,7 +157,7 @@ RSpec.describe "bundle install with install-time dependencies" do end simulate_platform mingw do - install_gemfile <<-G, :artifice => "compact_index_rate_limited", :env => { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s } + install_gemfile <<-G, :artifice => "compact_index", :env => { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s } ruby "#{RUBY_VERSION}" source "http://localgemserver.test/" gem 'rack' -- cgit v1.2.1