summaryrefslogtreecommitdiff
path: root/lib/rubygems/resolver
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-08 01:22:39 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-08 01:22:39 +0000
commit7ed9b794b4e3f3f9874f2ce19401461596d8a2c0 (patch)
tree5caaf13685de34b09d2949709a77b4c650b62741 /lib/rubygems/resolver
parent866b438c21ff05dfeabba8bc9aa9850e415be607 (diff)
* lib/rubygems: Update to RubyGems master 14749ce. This fixes bugs
handling of gem dependencies lockfiles (Gemfile.lock). * test/rubygems: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44054 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rubygems/resolver')
-rw-r--r--lib/rubygems/resolver/git_set.rb26
-rw-r--r--lib/rubygems/resolver/lock_set.rb6
-rw-r--r--lib/rubygems/resolver/lock_specification.rb58
-rw-r--r--lib/rubygems/resolver/requirement_list.rb25
-rw-r--r--lib/rubygems/resolver/stats.rb44
5 files changed, 154 insertions, 5 deletions
diff --git a/lib/rubygems/resolver/git_set.rb b/lib/rubygems/resolver/git_set.rb
index ed809c124f..1a2b230b80 100644
--- a/lib/rubygems/resolver/git_set.rb
+++ b/lib/rubygems/resolver/git_set.rb
@@ -46,6 +46,32 @@ class Gem::Resolver::GitSet < Gem::Resolver::Set
end
##
+ # Adds and returns a GitSpecification with the given +name+ and +version+
+ # which came from a +repository+ at the given +reference+. If +submodules+
+ # is true they are checked out along with the repository.
+ #
+ # This fills in the prefetch information as enough information about the gem
+ # is present in the arguments.
+
+ def add_git_spec name, version, repository, reference, submodules # :nodoc:
+ add_git_gem name, repository, reference, submodules
+
+ source = Gem::Source::Git.new name, repository, reference
+ source.root_dir = @root_dir
+
+ spec = Gem::Specification.new do |s|
+ s.name = name
+ s.version = version
+ end
+
+ git_spec = Gem::Resolver::GitSpecification.new self, spec, source
+
+ @specs[spec.name] = git_spec
+
+ git_spec
+ end
+
+ ##
# Finds all git gems matching +req+
def find_all req
diff --git a/lib/rubygems/resolver/lock_set.rb b/lib/rubygems/resolver/lock_set.rb
index ef5395597d..cdb41b22bf 100644
--- a/lib/rubygems/resolver/lock_set.rb
+++ b/lib/rubygems/resolver/lock_set.rb
@@ -24,10 +24,12 @@ class Gem::Resolver::LockSet < Gem::Resolver::Set
version = Gem::Version.new version
spec =
- Gem::Resolver::IndexSpecification.new self, name, version, @source,
- platform
+ Gem::Resolver::LockSpecification.new self, name, version, @source,
+ platform
@specs << spec
+
+ spec
end
##
diff --git a/lib/rubygems/resolver/lock_specification.rb b/lib/rubygems/resolver/lock_specification.rb
new file mode 100644
index 0000000000..4bc21b9402
--- /dev/null
+++ b/lib/rubygems/resolver/lock_specification.rb
@@ -0,0 +1,58 @@
+##
+# The LockSpecification comes from a lockfile (Gem::RequestSet::Lockfile).
+#
+# A LockSpecification's dependency information is pre-filled from the
+# lockfile.
+
+class Gem::Resolver::LockSpecification < Gem::Resolver::Specification
+
+ def initialize set, name, version, source, platform
+ super()
+
+ @name = name
+ @platform = platform
+ @set = set
+ @source = source
+ @version = version
+
+ @dependencies = []
+ @spec = nil
+ end
+
+ ##
+ # This is a null install as a locked specification is considered installed.
+ # +options+ are ignored.
+
+ def install options
+ destination = options[:install_dir] || Gem.dir
+
+ if File.exist? File.join(destination, 'specifications', spec.spec_name) then
+ yield nil
+ return
+ end
+
+ super
+ end
+
+ ##
+ # Adds +dependency+ from the lockfile to this specification
+
+ def add_dependency dependency # :nodoc:
+ @dependencies << dependency
+ end
+
+ ##
+ # A specification constructed from the lockfile is returned
+
+ def spec
+ @spec ||= Gem::Specification.new do |s|
+ s.name = @name
+ s.version = @version
+ s.platform = @platform
+
+ s.dependencies.concat @dependencies
+ end
+ end
+
+end
+
diff --git a/lib/rubygems/resolver/requirement_list.rb b/lib/rubygems/resolver/requirement_list.rb
index fe1d77afc3..a6bfaab307 100644
--- a/lib/rubygems/resolver/requirement_list.rb
+++ b/lib/rubygems/resolver/requirement_list.rb
@@ -13,10 +13,12 @@ class Gem::Resolver::RequirementList
# Creates a new RequirementList.
def initialize
+ @exact = []
@list = []
end
def initialize_copy other # :nodoc:
+ @exact = @exact.dup
@list = @list.dup
end
@@ -24,7 +26,11 @@ class Gem::Resolver::RequirementList
# Adds Resolver::DependencyRequest +req+ to this requirements list.
def add(req)
- @list.push req
+ if req.requirement.exact?
+ @exact.push req
+ else
+ @list.push req
+ end
req
end
@@ -34,22 +40,34 @@ class Gem::Resolver::RequirementList
def each # :nodoc:
return enum_for __method__ unless block_given?
+ @exact.each do |requirement|
+ yield requirement
+ end
+
@list.each do |requirement|
yield requirement
end
end
##
+ # How many elements are in the list
+
+ def size
+ @exact.size + @list.size
+ end
+
+ ##
# Is the list empty?
def empty?
- @list.empty?
+ @exact.empty? && @list.empty?
end
##
# Remove the oldest DependencyRequest from the list.
def remove
+ return @exact.shift unless @exact.empty?
@list.shift
end
@@ -57,6 +75,7 @@ class Gem::Resolver::RequirementList
# Returns the oldest five entries from the list.
def next5
- @list[0,5]
+ x = @exact[0,5]
+ x + @list[0,5 - x.size]
end
end
diff --git a/lib/rubygems/resolver/stats.rb b/lib/rubygems/resolver/stats.rb
new file mode 100644
index 0000000000..c31e5be962
--- /dev/null
+++ b/lib/rubygems/resolver/stats.rb
@@ -0,0 +1,44 @@
+class Gem::Resolver::Stats
+ def initialize
+ @max_depth = 0
+ @max_requirements = 0
+ @requirements = 0
+ @backtracking = 0
+ @iterations = 0
+ end
+
+ def record_depth(stack)
+ if stack.size > @max_depth
+ @max_depth = stack.size
+ end
+ end
+
+ def record_requirements(reqs)
+ if reqs.size > @max_requirements
+ @max_requirements = reqs.size
+ end
+ end
+
+ def requirement!
+ @requirements += 1
+ end
+
+ def backtracking!
+ @backtracking += 1
+ end
+
+ def iteration!
+ @iterations += 1
+ end
+
+ PATTERN = "%20s: %d\n"
+
+ def display
+ $stdout.puts "=== Resolver Statistics ==="
+ $stdout.printf PATTERN, "Max Depth", @max_depth
+ $stdout.printf PATTERN, "Total Requirements", @requirements
+ $stdout.printf PATTERN, "Max Requirements", @max_requirements
+ $stdout.printf PATTERN, "Backtracking #", @backtracking
+ $stdout.printf PATTERN, "Iteration #", @iterations
+ end
+end