summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/bundler/lazy_specification.rb9
-rw-r--r--spec/install/gems/resolving_spec.rb25
2 files changed, 32 insertions, 2 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/spec/install/gems/resolving_spec.rb b/spec/install/gems/resolving_spec.rb
index 20fe4c7728..d0448ca30b 100644
--- a/spec/install/gems/resolving_spec.rb
+++ b/spec/install/gems/resolving_spec.rb
@@ -143,6 +143,31 @@ 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 = mingw
+ s.required_ruby_version = "> 9000"
+ end
+ build_gem "rack", "1.2"
+ end
+
+ simulate_platform mingw do
+ install_gemfile <<-G, :artifice => "compact_index", :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")
+ expect(the_bundle).to include_gems("rack 1.2")
+ end
end
context "allows no gems" do