summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThe Bundler Bot <bot@bundler.io>2017-11-29 08:13:12 +0000
committerThe Bundler Bot <bot@bundler.io>2017-11-29 08:13:12 +0000
commit778dcf58506b99fc7923a1ae530f1353dee9a4d4 (patch)
tree90911c3d675d0092a59fbcbdd3e7af417177565c
parent914a4a8b8d0cf1a79dbc7b334fbb5c2db1ecdc16 (diff)
parent5e434f754132764465f68e4a2b7dbb8116644d3c (diff)
downloadbundler-778dcf58506b99fc7923a1ae530f1353dee9a4d4.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 8a3afa3418..d7911c1de2 100644
--- a/lib/bundler/resolver.rb
+++ b/lib/bundler/resolver.rb
@@ -249,7 +249,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 568958ae00..c829243a9f 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