summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThe Bundler Bot <bot@bundler.io>2017-11-29 08:13:12 +0000
committerSHIBATA Hiroshi <hsbt@ruby-lang.org>2017-12-11 20:42:18 +0900
commit47c4bbb340be1d09e38dd3f9dcb4bc764d9f09ca (patch)
treeed0718b7b6fefbd0b69c4e0825b6ad8dd099e675
parent45c2679de96d1dd0b762ff5660c1462ee66249c4 (diff)
downloadbundler-47c4bbb340be1d09e38dd3f9dcb4bc764d9f09ca.tar.gz
Auto merge of #6186 - greysteil:treat-release-preference-as-constraint, r=indirect
Resolver: treat dependencies with prerelease versions as slightly constrained Fixes https://github.com/bundler/bundler/issues/6181. In Bundler 1.15.4, the way we checked for pre-releases meant that dependencies with a lot of them sorted as more constrained than those with few/none. When we moved to our updated resolution strategy in 1.16.0 we accidentally lost that behaviour. I'm not wild about this PR, but it fixes the resolver regression. It's unsatisfying because it would be nice to believe the resolver will always resolve performantly, regardless of the sort order thrown at it, but clearly that isn't the case. Conceptually, this can be justified as "when two resolutions are possible, we prefer the one that does not require one dependency to be at a pre-release version". If others are happy with this I can write a test for it.
-rw-r--r--lib/bundler/resolver.rb3
-rw-r--r--spec/resolver/basic_spec.rb7
-rw-r--r--spec/support/indexes.rb15
3 files changed, 24 insertions, 1 deletions
diff --git a/lib/bundler/resolver.rb b/lib/bundler/resolver.rb
index ddc1d702e0..bfc6b91576 100644
--- a/lib/bundler/resolver.rb
+++ b/lib/bundler/resolver.rb
@@ -245,7 +245,8 @@ module Bundler
if all <= 1
all - 1_000_000
else
- search = search_for(dependency).size
+ search = search_for(dependency)
+ search = @prerelease_specified[dependency.name] ? search.count : search.count {|s| !s.version.prerelease? }
search - all
end
end
diff --git a/spec/resolver/basic_spec.rb b/spec/resolver/basic_spec.rb
index d5658824ba..623d092644 100644
--- a/spec/resolver/basic_spec.rb
+++ b/spec/resolver/basic_spec.rb
@@ -42,6 +42,13 @@ RSpec.describe "Resolving" do
should_resolve_as %w[a-1.0.0 b-2.0.0 c-1.0.0 d-1.0.0]
end
+ it "prefers non-prerelease resolutions in sort order" do
+ @index = optional_prereleases_index
+ dep "a"
+ dep "b"
+ should_resolve_as %w[a-1.0.0 b-1.5.0]
+ end
+
it "resolves a index with root level conflict on child" do
@index = a_index_with_root_conflict_on_child
dep "i18n", "~> 0.4"
diff --git a/spec/support/indexes.rb b/spec/support/indexes.rb
index 05605195b1..c56d6145a7 100644
--- a/spec/support/indexes.rb
+++ b/spec/support/indexes.rb
@@ -401,5 +401,20 @@ module Spec
gem("d", %w[1.0.0 2.0.0])
end
end
+
+ def optional_prereleases_index
+ build_index do
+ gem("a", %w[1.0.0])
+
+ gem("a", "2.0.0") do
+ dep "b", ">= 2.0.0.pre"
+ end
+
+ gem("b", %w[0.9.0 1.5.0 2.0.0.pre])
+
+ # --- Pre-release support
+ gem "rubygems\0", ["1.3.2"]
+ end
+ end
end
end