Skip to content
This repository was archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Auto merge of #6186 - greysteil:treat-release-preference-as-constrain…
Browse files Browse the repository at this point in the history
…t, r=indirect

Resolver: treat dependencies with prerelease versions as slightly constrained

Fixes #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.
  • Loading branch information
bundlerbot committed Nov 29, 2017
2 parents 914a4a8 + 5e434f7 commit 778dcf5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/bundler/resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ def amount_constrained(dependency)
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
Expand Down
7 changes: 7 additions & 0 deletions spec/resolver/basic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@
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"
Expand Down
15 changes: 15 additions & 0 deletions spec/support/indexes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -401,5 +401,20 @@ def an_ambiguous_index
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

0 comments on commit 778dcf5

Please sign in to comment.