2012-11-29 01:52:18 -05:00
|
|
|
require 'rubygems'
|
|
|
|
require 'rubygems/dependency'
|
|
|
|
require 'rubygems/dependency_resolver'
|
|
|
|
require 'rubygems/dependency_list'
|
|
|
|
require 'rubygems/installer'
|
|
|
|
require 'tsort'
|
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
class Gem::RequestSet
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
include TSort
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
##
|
|
|
|
# Array of gems to install even if already installed
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
attr_reader :always_install
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
attr_reader :dependencies
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
attr_accessor :development
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
##
|
|
|
|
# Treat missing dependencies as silent errors
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
attr_accessor :soft_missing
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
def initialize *deps
|
|
|
|
@dependencies = deps
|
2013-07-09 19:21:36 -04:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
@always_install = []
|
|
|
|
@development = false
|
|
|
|
@requests = []
|
|
|
|
@soft_missing = false
|
|
|
|
@sorted = nil
|
|
|
|
@specs = nil
|
2013-07-09 19:21:36 -04:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
yield self if block_given?
|
|
|
|
end
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
##
|
|
|
|
# Declare that a gem of name +name+ with +reqs+ requirements is needed.
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
def gem name, *reqs
|
|
|
|
@dependencies << Gem::Dependency.new(name, reqs)
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Add +deps+ Gem::Dependency objects to the set.
|
|
|
|
|
|
|
|
def import deps
|
|
|
|
@dependencies += deps
|
|
|
|
end
|
2013-07-09 19:21:36 -04:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
def install options, &block
|
|
|
|
if dir = options[:install_dir]
|
|
|
|
return install_into dir, false, options, &block
|
2013-09-13 15:58:57 -04:00
|
|
|
end
|
2013-07-09 19:21:36 -04:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
cache_dir = options[:cache_dir] || Gem.dir
|
|
|
|
|
|
|
|
specs = []
|
|
|
|
|
|
|
|
sorted_requests.each do |req|
|
2013-10-15 20:14:16 -04:00
|
|
|
if req.installed? then
|
|
|
|
req.spec.spec.build_extensions
|
|
|
|
|
|
|
|
if @always_install.none? { |spec| spec == req.spec.spec } then
|
|
|
|
yield req, nil if block_given?
|
|
|
|
next
|
|
|
|
end
|
2012-11-29 01:52:18 -05:00
|
|
|
end
|
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
path = req.download cache_dir
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
inst = Gem::Installer.new path, options
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
yield req, inst if block_given?
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
specs << inst.install
|
|
|
|
end
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
specs
|
|
|
|
end
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
def install_into dir, force = true, options = {}
|
|
|
|
existing = force ? [] : specs_in(dir)
|
|
|
|
existing.delete_if { |s| @always_install.include? s }
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
dir = File.expand_path dir
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
installed = []
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
sorted_requests.each do |req|
|
|
|
|
if existing.find { |s| s.full_name == req.spec.full_name }
|
|
|
|
yield req, nil if block_given?
|
|
|
|
next
|
2012-11-29 01:52:18 -05:00
|
|
|
end
|
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
path = req.download(dir)
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
unless path then # already installed
|
|
|
|
yield req, nil if block_given?
|
|
|
|
next
|
2012-11-29 01:52:18 -05:00
|
|
|
end
|
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
options[:install_dir] = dir
|
|
|
|
options[:only_install_dir] = true
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
inst = Gem::Installer.new path, options
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
yield req, inst if block_given?
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
inst.install
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
installed << req
|
|
|
|
end
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
installed
|
|
|
|
end
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
##
|
|
|
|
# Load a dependency management file.
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
def load_gemdeps path
|
|
|
|
gf = Gem::RequestSet::GemDepedencyAPI.new self, path
|
|
|
|
gf.load
|
|
|
|
end
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
##
|
|
|
|
# Resolve the requested dependencies and return an Array of Specification
|
|
|
|
# objects to be activated.
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
def resolve set = nil
|
|
|
|
resolver = Gem::DependencyResolver.new @dependencies, set
|
|
|
|
resolver.development = @development
|
|
|
|
resolver.soft_missing = @soft_missing
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
@requests = resolver.resolve
|
|
|
|
end
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
##
|
|
|
|
# Resolve the requested dependencies against the gems available via Gem.path
|
|
|
|
# and return an Array of Specification objects to be activated.
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
def resolve_current
|
|
|
|
resolve Gem::DependencyResolver::CurrentSet.new
|
|
|
|
end
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
def sorted_requests
|
|
|
|
@sorted ||= strongly_connected_components.flatten
|
|
|
|
end
|
2013-07-09 19:21:36 -04:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
def specs
|
|
|
|
@specs ||= @requests.map { |r| r.full_spec }
|
|
|
|
end
|
|
|
|
|
|
|
|
def specs_in dir
|
|
|
|
Dir["#{dir}/specifications/*.gemspec"].map do |g|
|
|
|
|
Gem::Specification.load g
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def tsort_each_node &block # :nodoc:
|
|
|
|
@requests.each(&block)
|
|
|
|
end
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
def tsort_each_child node # :nodoc:
|
|
|
|
node.spec.dependencies.each do |dep|
|
|
|
|
next if dep.type == :development and not @development
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
match = @requests.find { |r| dep.match? r.spec.name, r.spec.version }
|
|
|
|
if match
|
|
|
|
begin
|
|
|
|
yield match
|
|
|
|
rescue TSort::Cyclic
|
|
|
|
end
|
|
|
|
else
|
|
|
|
unless @soft_missing
|
|
|
|
raise Gem::DependencyError, "Unresolved depedency found during sorting - #{dep}"
|
|
|
|
end
|
2012-11-29 01:52:18 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-09-14 04:59:02 -04:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
end
|
2013-09-14 04:59:02 -04:00
|
|
|
|
|
|
|
require 'rubygems/request_set/gem_dependency_api'
|