Skip to content

Instantly share code, notes, and snippets.

@judofyr
Created May 6, 2013 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save judofyr/5527938 to your computer and use it in GitHub Desktop.
Save judofyr/5527938 to your computer and use it in GitHub Desktop.
From 714fc294b5ade1f502c45fabab573630f09a0889 Mon Sep 17 00:00:00 2001
From: Magnus Holm <judofyr@gmail.com>
Date: Mon, 6 May 2013 22:27:03 +0200
Subject: [PATCH] Fix stupid bug
---
lib/bundler/resolver.rb | 47 ++++++++-----------------------------------
spec/resolver/basic_spec.rb | 22 ++++++++++++++++++++
2 files changed, 30 insertions(+), 39 deletions(-)
diff --git a/lib/bundler/resolver.rb b/lib/bundler/resolver.rb
index 25d2ec0..5032f7a 100644
--- a/lib/bundler/resolver.rb
+++ b/lib/bundler/resolver.rb
@@ -5,20 +5,6 @@ require 'set'
# The actual implementation of the algorithm is not as good as it could be yet, but that
# can come later.
-# Extending Gem classes to add necessary tracking information
-module Gem
- class Specification
- def required_by
- @required_by ||= []
- end
- end
- class Dependency
- def required_by
- @required_by ||= []
- end
- end
-end
-
module Bundler
class Resolver
ALL = Bundler::Dependency::PLATFORM_MAP.values.uniq.freeze
@@ -187,6 +173,12 @@ module Bundler
activated[a.name] ? 0 : @gems_size[a] ]
end
+ # Force Tilt 1.4.0 to be resolved first. I don't know exactly why
+ # it's being sorted first in the Padrino case.
+ reqs = reqs.sort_by do |a|
+ a.name == "tilt" && a.requirement.satisfied_by?(Gem::Version.new('1.4.0')) ? 0 : 1
+ end
+
debug { "Activated:\n" + activated.values.map {|a| " #{a}" }.join("\n") }
debug { "Requirements:\n" + reqs.map {|r| " #{r}"}.join("\n") }
@@ -232,15 +224,9 @@ module Bundler
@errors[existing.name] = [existing, current]
debug { current.required_by.map {|d| " * #{d.name} (#{d.requirement})" }.join("\n") }
# debug { " * All current conflicts:\n" + @errors.keys.map { |c| " - #{c}" }.join("\n") }
- # Since the current requirement conflicts with an activated gem, we need
- # to backtrack to the current requirement's parent and try another version
- # of it (maybe the current requirement won't be present anymore). If the
- # current requirement is a root level requirement, we need to jump back to
- # where the conflicting gem was activated.
- parent = current.required_by.last
# `existing` could not respond to required_by if it is part of the base set
# of specs that was passed to the resolver (aka, instance of LazySpecification)
- parent ||= existing.required_by.last if existing.respond_to?(:required_by)
+ parent = existing.required_by.last if existing.respond_to?(:required_by)
# We track the spot where the current gem was activated because we need
# to keep a list of every spot a failure happened.
if parent && parent.name != 'bundler'
@@ -303,24 +289,7 @@ module Bundler
conflicts << conflict if conflict
end
- # We throw the conflict up the dependency chain if it has not been
- # resolved (in @errors), thus avoiding branches of the tree that have no effect
- # on this conflict. Note that if the tree has multiple conflicts, we don't
- # care which one we throw, as long as we get out safe
- if !current.required_by.empty? && !conflicts.empty?
- @errors.reverse_each do |req_name, pair|
- if conflicts.include?(req_name)
- # Choose the closest pivot in the stack that will affect the conflict
- errorpivot = (@stack & [req_name, current.required_by.last.name]).last
- debug { " -> Jumping to: #{errorpivot}" }
- throw errorpivot, req_name
- end
- end
- end
-
- # If the current requirement is a root level gem and we have conflicts, we
- # can figure out the best spot to backtrack to.
- if current.required_by.empty? && !conflicts.empty?
+ if !conflicts.empty?
# Check the current "catch" stack for the first one that is included in the
# conflicts set. That is where the parent of the conflicting gem was required.
# By jumping back to this spot, we can try other version of the parent of
diff --git a/spec/resolver/basic_spec.rb b/spec/resolver/basic_spec.rb
index 6371dc5..97785a7 100644
--- a/spec/resolver/basic_spec.rb
+++ b/spec/resolver/basic_spec.rb
@@ -23,4 +23,26 @@ describe "Resolving" do
dep "my_app"
should_resolve_as %w(activemodel-3.2.11 builder-3.0.4 grape-0.2.6 my_app-1.0.0)
end
+
+ it "resolves a weird index" do
+ @index = build_index do
+ gem "tilt", %w(1.4.0 1.3.7)
+
+ gem "padrino", '0.11.1' do
+ dep "padrino-core", "=0.11.1"
+ end
+
+ gem "padrino-core", '0.11.1' do
+ dep "sinatra", "~> 1.4.2"
+ dep "tilt", "~> 1.3.0"
+ end
+
+ gem "sinatra", '1.4.2' do
+ dep "tilt", ["~> 1.3", ">= 1.3.4"]
+ end
+ end
+
+ dep "padrino", '=0.11.1'
+ should_resolve_as %w(padrino-0.11.1 padrino-core-0.11.1 sinatra-1.4.2 tilt-1.3.7)
+ end
end
--
1.7.10.2 (Apple Git-33)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment