class Bundler::Resolver
def self.resolve(requirements, index, source_requirements = {}, base = [], ruby_version = nil)
==== Returns
*dependencies
==== Parameters
causing any gem activation errors.
the list of passed dependencies and any child dependencies without
Figures out the best possible configuration of gems that satisfies
def self.resolve(requirements, index, source_requirements = {}, base = [], ruby_version = nil) base = SpecSet.new(base) unless base.is_a?(SpecSet) resolver = new(index, source_requirements, base, ruby_version) result = resolver.start(requirements) SpecSet.new(result) end
def after_resolution
def after_resolution Bundler.ui.info "" end
def amount_constrained(dependency)
def amount_constrained(dependency) @amount_constrained ||= {} @amount_constrained[dependency.name] ||= begin if (base = @base[dependency.name]) && !base.empty? dependency.requirement.satisfied_by?(base.first.version) ? 0 : 1 else base_dep = Dependency.new dependency.name, ">= 0.a" all = search_for(DepProxy.new base_dep, dependency.__platform).size.to_f if all.zero? 0 elsif (search = search_for(dependency).size.to_f) == all && all == 1 0 else search / all end end end end
def before_resolution
def before_resolution Bundler.ui.info "Resolving dependencies...", false end
def debug(depth = 0)
-
(void)
-
Parameters:
-
depth
(Integer
) -- the current depth of the resolution process.
def debug(depth = 0) return unless debug? debug_info = yield debug_info = debug_info.inspect unless debug_info.is_a?(String) STDERR.puts debug_info.split("\n").map {|s| " " * depth + s } end
def debug?
def debug? return @debug_mode if defined?(@debug_mode) @debug_mode = ENV["DEBUG_RESOLVER"] || ENV["DEBUG_RESOLVER_TREE"] end
def dependencies_for(specification)
def dependencies_for(specification) specification.dependencies_for_activated_platforms end
def formatted_versions_with_platforms(versions_with_platforms)
def formatted_versions_with_platforms(versions_with_platforms) version_platform_strs = versions_with_platforms.map do |vwp| version = vwp.first platform = vwp.last version_platform_str = String.new(version.to_s) version_platform_str << " #{platform}" unless platform.nil? end version_platform_strs.join(", ") end
def indicate_progress
def indicate_progress Bundler.ui.info ".", false end
def initialize(index, source_requirements, base, ruby_version)
def initialize(index, source_requirements, base, ruby_version) @index = index @source_requirements = source_requirements @base = base @resolver = Molinillo::Resolver.new(self, self) @search_for = {} @base_dg = Molinillo::DependencyGraph.new @base.each {|ls| @base_dg.add_vertex(ls.name, Dependency.new(ls.name, ls.version), true) } @ruby_version = ruby_version end
def name_for(dependency)
def name_for(dependency) dependency.name end
def name_for_explicit_dependency_source
def name_for_explicit_dependency_source Bundler.default_gemfile.basename.to_s rescue "Gemfile" end
def name_for_locking_dependency_source
def name_for_locking_dependency_source Bundler.default_lockfile.basename.to_s rescue "Gemfile.lock" end
def requirement_satisfied_by?(requirement, activated, spec)
def requirement_satisfied_by?(requirement, activated, spec) requirement.matches_spec?(spec) end
def search_for(dependency)
def search_for(dependency) platform = dependency.__platform dependency = dependency.dep unless dependency.is_a? Gem::Dependency search = @search_for[dependency] ||= begin index = @source_requirements[dependency.name] || @index results = index.search(dependency, @base[dependency.name]) if vertex = @base_dg.vertex_named(dependency.name) locked_requirement = vertex.payload.requirement end if results.any? version = results.first.version nested = [[]] results.each do |spec| if spec.version != version nested << [] version = spec.version end nested.last << spec end groups = nested.map {|a| SpecGroup.new(a) } !locked_requirement ? groups : groups.select {|sg| locked_requirement.satisfied_by? sg.version } else [] end end search.select {|sg| sg.for?(platform, @ruby_version) }.each {|sg| sg.activate_platform(platform) } end
def sort_dependencies(dependencies, activated, conflicts)
def sort_dependencies(dependencies, activated, conflicts) dependencies.sort_by do |dependency| name = name_for(dependency) [ activated.vertex_named(name).payload ? 0 : 1, amount_constrained(dependency), conflicts[name] ? 0 : 1, activated.vertex_named(name).payload ? 0 : search_for(dependency).count, ] end end
def start(requirements)
def start(requirements) verify_gemfile_dependencies_are_found!(requirements) dg = @resolver.resolve(requirements, @base_dg) dg.map(&:payload).map(&:to_specs).flatten rescue Molinillo::VersionConflict => e raise VersionConflict.new(e.conflicts.keys.uniq, e.message) rescue Molinillo::CircularDependencyError => e names = e.dependencies.sort_by(&:name).map {|d| "gem '#{d.name}'" } raise CyclicDependencyError, "Your bundle requires gems that depend" \ " on each other, creating an infinite loop. Please remove" \ " #{names.count > 1 ? "either " : ""}#{names.join(" or ")}" \ " and try again." end
def verify_gemfile_dependencies_are_found!(requirements)
def verify_gemfile_dependencies_are_found!(requirements) requirements.each do |requirement| next if requirement.name == "bundler" next unless search_for(requirement).empty? if (base = @base[requirement.name]) && !base.empty? version = base.first.version message = "You have requested:\n" \ " #{requirement.name} #{requirement.requirement}\n\n" \ "The bundle currently has #{requirement.name} locked at #{version}.\n" \ "Try running `bundle update #{requirement.name}`\n\n" \ "If you are updating multiple gems in your Gemfile at once,\n" \ "try passing them all to `bundle update`" elsif requirement.source name = requirement.name specs = @source_requirements[name][name] versions_with_platforms = specs.map {|s| [s.version, s.platform] } message = String.new("Could not find gem '#{requirement}' in #{requirement.source}.\n") message << if versions_with_platforms.any? "Source contains '#{name}' at: #{formatted_versions_with_platforms(versions_with_platforms)}" else "Source does not contain any versions of '#{requirement}'" end else message = "Could not find gem '#{requirement}' in any of the gem sources " \ "listed in your Gemfile or available on this machine." end raise GemNotFound, message end end