diff options
Diffstat (limited to 'lib/bundler/resolver.rb')
-rw-r--r-- | lib/bundler/resolver.rb | 697 |
1 files changed, 384 insertions, 313 deletions
diff --git a/lib/bundler/resolver.rb b/lib/bundler/resolver.rb index 161a3c0518..1a6711ea6f 100644 --- a/lib/bundler/resolver.rb +++ b/lib/bundler/resolver.rb @@ -1,174 +1,297 @@ # frozen_string_literal: true module Bundler + # + # This class implements the interface needed by PubGrub for resolution. It is + # equivalent to the `PubGrub::BasicPackageSource` class provided by PubGrub by + # default and used by the most simple PubGrub consumers. + # class Resolver - require_relative "vendored_molinillo" + require_relative "vendored_pub_grub" require_relative "resolver/base" - require_relative "resolver/spec_group" + require_relative "resolver/candidate" + require_relative "resolver/incompatibility" + require_relative "resolver/root" include GemHelpers - # Figures out the best possible configuration of gems that satisfies - # the list of passed dependencies and any child dependencies without - # causing any gem activation errors. - # - # ==== Parameters - # *dependencies<Gem::Dependency>:: The list of dependencies to resolve - # - # ==== Returns - # <GemBundle>,nil:: If the list of dependencies can be resolved, a - # collection of gemspecs is returned. Otherwise, nil is returned. - def self.resolve(requirements, source_requirements = {}, base = [], gem_version_promoter = GemVersionPromoter.new, additional_base_requirements = [], platforms = nil) - base = SpecSet.new(base) unless base.is_a?(SpecSet) - resolver = new(source_requirements, base, gem_version_promoter, additional_base_requirements, platforms) - resolver.start(requirements) - end - - def initialize(source_requirements, base, gem_version_promoter, additional_base_requirements, platforms) - @source_requirements = source_requirements - @base = Resolver::Base.new(base, additional_base_requirements) - @resolver = Molinillo::Resolver.new(self, self) - @results_for = {} - @search_for = {} - @platforms = platforms - @resolving_only_for_ruby = platforms == [Gem::Platform::RUBY] + def initialize(base, gem_version_promoter) + @source_requirements = base.source_requirements + @base = base @gem_version_promoter = gem_version_promoter end - def start(requirements, exclude_specs: []) - @metadata_requirements, regular_requirements = requirements.partition {|dep| dep.name.end_with?("\0") } + def start + @requirements = @base.requirements + @packages = @base.packages - exclude_specs.each do |spec| - remove_from_candidates(spec) + root, logger = setup_solver + + Bundler.ui.info "Resolving dependencies...", true + + solve_versions(root: root, logger: logger) + end + + def setup_solver + root = Resolver::Root.new(name_for_explicit_dependency_source) + root_version = Resolver::Candidate.new(0) + + @all_specs = Hash.new do |specs, name| + source = source_for(name) + matches = source.specs.search(name) + + # Don't bother to check for circular deps when no dependency API are + # available, since it's too slow to be usable. That edge case won't work + # but resolution other than that should work fine and reasonably fast. + if source.respond_to?(:dependency_api_available?) && source.dependency_api_available? + matches = filter_invalid_self_dependencies(matches, name) + end + + specs[name] = matches.sort_by {|s| [s.version, s.platform.to_s] } end - requirements.each {|dep| prerelease_specified[dep.name] ||= dep.prerelease? } + @all_versions = Hash.new do |candidates, package| + candidates[package] = all_versions_for(package) + end - verify_gemfile_dependencies_are_found!(requirements) - result = @resolver.resolve(requirements). - map(&:payload). - reject {|sg| sg.name.end_with?("\0") }. - map(&:to_specs). - flatten + @sorted_versions = Hash.new do |candidates, package| + candidates[package] = filtered_versions_for(package).sort + end - SpecSet.new(SpecSet.new(result).for(regular_requirements, false, @platforms)) - rescue Molinillo::VersionConflict => e - conflicts = e.conflicts + @sorted_versions[root] = [root_version] - deps_to_unlock = conflicts.values.inject([]) do |deps, conflict| - deps |= conflict.requirement_trees.flatten.map {|req| base_requirements[req.name] }.compact + root_dependencies = prepare_dependencies(@requirements, @packages) + + @cached_dependencies = Hash.new do |dependencies, package| + dependencies[package] = Hash.new do |versions, version| + versions[version] = to_dependency_hash(version.dependencies.reject {|d| d.name == package.name }, @packages) + end end - if deps_to_unlock.any? - @base.unlock_deps(deps_to_unlock) - reset_spec_cache + @cached_dependencies[root] = { root_version => root_dependencies } + + logger = Bundler::UI::Shell.new + logger.level = debug? ? "debug" : "warn" + + [root, logger] + end + + def solve_versions(root:, logger:) + solver = PubGrub::VersionSolver.new(source: self, root: root, logger: logger) + result = solver.solve + result.map {|package, version| version.to_specs(package) }.flatten.uniq + rescue PubGrub::SolveFailure => e + incompatibility = e.incompatibility + + names_to_unlock, names_to_allow_prereleases_for, extended_explanation = find_names_to_relax(incompatibility) + + names_to_relax = names_to_unlock + names_to_allow_prereleases_for + + if names_to_relax.any? + if names_to_unlock.any? + Bundler.ui.debug "Found conflicts with locked dependencies. Will retry with #{names_to_unlock.join(", ")} unlocked...", true + + @base.unlock_names(names_to_unlock) + end + + if names_to_allow_prereleases_for.any? + Bundler.ui.debug "Found conflicts with dependencies with prereleases. Will retrying considering prereleases for #{names_to_allow_prereleases_for.join(", ")}...", true + + @base.include_prereleases(names_to_allow_prereleases_for) + end + + root, logger = setup_solver + + Bundler.ui.debug "Retrying resolution...", true retry end - message = version_conflict_message(e) - raise VersionConflict.new(conflicts.keys.uniq, 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." + explanation = e.message + + if extended_explanation + explanation << "\n\n" + explanation << extended_explanation + end + + raise SolveFailure.new(explanation) + end + + def find_names_to_relax(incompatibility) + names_to_unlock = [] + names_to_allow_prereleases_for = [] + extended_explanation = nil + + while incompatibility.conflict? + cause = incompatibility.cause + incompatibility = cause.incompatibility + + incompatibility.terms.each do |term| + package = term.package + name = package.name + + if base_requirements[name] + names_to_unlock << name + elsif package.ignores_prereleases? && @all_specs[name].any? {|s| s.version.prerelease? } + names_to_allow_prereleases_for << name + end + + no_versions_incompat = [cause.incompatibility, cause.satisfier].find {|incompat| incompat.cause.is_a?(PubGrub::Incompatibility::NoVersions) } + next unless no_versions_incompat + + extended_explanation = no_versions_incompat.extended_explanation + end + end + + [names_to_unlock.uniq, names_to_allow_prereleases_for.uniq, extended_explanation] + end + + def parse_dependency(package, dependency) + range = if repository_for(package).is_a?(Source::Gemspec) + PubGrub::VersionRange.any + else + requirement_to_range(dependency) + end + + PubGrub::VersionConstraint.new(package, range: range) end - include Molinillo::UI + def versions_for(package, range=VersionRange.any) + versions = select_sorted_versions(package, range) - # Conveys debug information to the user. - # - # @param [Integer] depth the current depth of the resolution process. - # @return [void] - def debug(depth = 0) - return unless debug? - debug_info = yield - debug_info = debug_info.inspect unless debug_info.is_a?(String) - puts debug_info.split("\n").map {|s| depth == 0 ? "BUNDLER: #{s}" : "BUNDLER(#{depth}): #{s}" } + # Conditional avoids (among other things) calling + # sort_versions_by_preferred with the root package + if versions.size > 1 + sort_versions_by_preferred(package, versions) + else + versions + end + end + + def no_versions_incompatibility_for(package, unsatisfied_term) + cause = PubGrub::Incompatibility::NoVersions.new(unsatisfied_term) + name = package.name + constraint = unsatisfied_term.constraint + constraint_string = constraint.constraint_string + requirements = constraint_string.split(" OR ").map {|req| Gem::Requirement.new(req.split(",")) } + + if name == "bundler" && bundler_pinned_to_current_version? + custom_explanation = "the current Bundler version (#{Bundler::VERSION}) does not satisfy #{constraint}" + extended_explanation = bundler_not_found_message(requirements) + else + specs_matching_other_platforms = filter_matching_specs(@all_specs[name], requirements) + + platforms_explanation = specs_matching_other_platforms.any? ? " for any resolution platforms (#{package.platforms.join(", ")})" : "" + custom_explanation = "#{constraint} could not be found in #{repository_for(package)}#{platforms_explanation}" + + label = "#{name} (#{constraint_string})" + extended_explanation = other_specs_matching_message(specs_matching_other_platforms, label) if specs_matching_other_platforms.any? + end + + Incompatibility.new([unsatisfied_term], cause: cause, custom_explanation: custom_explanation, extended_explanation: extended_explanation) end def debug? - return @debug_mode if defined?(@debug_mode) - @debug_mode = - ENV["BUNDLER_DEBUG_RESOLVER"] || + ENV["BUNDLER_DEBUG_RESOLVER"] || ENV["BUNDLER_DEBUG_RESOLVER_TREE"] || ENV["DEBUG_RESOLVER"] || ENV["DEBUG_RESOLVER_TREE"] || false end - def before_resolution - Bundler.ui.info "Resolving dependencies...", debug? - end + def incompatibilities_for(package, version) + package_deps = @cached_dependencies[package] + sorted_versions = @sorted_versions[package] + package_deps[version].map do |dep_package, dep_constraint| + low = high = sorted_versions.index(version) - def after_resolution - Bundler.ui.info "" - end + # find version low such that all >= low share the same dep + while low > 0 && package_deps[sorted_versions[low - 1]][dep_package] == dep_constraint + low -= 1 + end + low = + if low == 0 + nil + else + sorted_versions[low] + end - def indicate_progress - Bundler.ui.info ".", false unless debug? - end + # find version high such that all < high share the same dep + while high < sorted_versions.length && package_deps[sorted_versions[high]][dep_package] == dep_constraint + high += 1 + end + high = + if high == sorted_versions.length + nil + else + sorted_versions[high] + end + + range = PubGrub::VersionRange.new(min: low, max: high, include_min: true) - include Molinillo::SpecificationProvider + self_constraint = PubGrub::VersionConstraint.new(package, range: range) - def dependencies_for(specification) - specification.dependencies_for_activated_platforms + dep_term = PubGrub::Term.new(dep_constraint, false) + self_term = PubGrub::Term.new(self_constraint, true) + + custom_explanation = if dep_package.meta? && package.root? + "current #{dep_package} version is #{dep_constraint.constraint_string}" + end + + PubGrub::Incompatibility.new([self_term, dep_term], cause: :dependency, custom_explanation: custom_explanation) + end end - def search_for(dependency_proxy) - platform = dependency_proxy.__platform - dependency = dependency_proxy.dep - name = dependency.name - @search_for[dependency_proxy] ||= begin - locked_results = @base[name].select {|spec| requirement_satisfied_by?(dependency, nil, spec) } - locked_requirement = base_requirements[name] - results = results_for(dependency) + locked_results - results = results.select {|spec| requirement_satisfied_by?(locked_requirement, nil, spec) } if locked_requirement + def all_versions_for(package) + name = package.name + results = (@base[name] + filter_prereleases(@all_specs[name], package)).uniq {|spec| [spec.version.hash, spec.platform] } - if results.any? - results = @gem_version_promoter.sort_versions(dependency, results) + if name == "bundler" && !bundler_pinned_to_current_version? + bundler_spec = Gem.loaded_specs["bundler"] + results << bundler_spec if bundler_spec + end - results.group_by(&:version).reduce([]) do |groups, (_, specs)| - next groups unless specs.any? {|spec| spec.match_platform(platform) } + locked_requirement = base_requirements[name] + results = filter_matching_specs(results, locked_requirement) if locked_requirement + + results.group_by(&:version).reduce([]) do |groups, (version, specs)| + platform_specs = package.platforms.map {|platform| select_best_platform_match(specs, platform) } + + # If package is a top-level dependency, + # candidate is only valid if there are matching versions for all resolution platforms. + # + # If package is not a top-level deependency, + # then it's not necessary that it has matching versions for all platforms, since it may have been introduced only as + # a dependency for a platform specific variant, so it will only need to have a valid version for that platform. + # + if package.top_level? + next groups if platform_specs.any?(&:empty?) + else + next groups if platform_specs.all?(&:empty?) + end - specs_by_platform = Hash.new do |current_specs, current_platform| - current_specs[current_platform] = select_best_platform_match(specs, current_platform) - end + platform_specs.flatten! - spec_group_ruby = SpecGroup.create_for(specs_by_platform, [Gem::Platform::RUBY], Gem::Platform::RUBY) - if spec_group_ruby - spec_group_ruby.force_ruby_platform = dependency.force_ruby_platform - groups << spec_group_ruby - end + ruby_specs = select_best_platform_match(specs, Gem::Platform::RUBY) + groups << Resolver::Candidate.new(version, specs: ruby_specs) if ruby_specs.any? - next groups if @resolving_only_for_ruby || dependency.force_ruby_platform + next groups if platform_specs == ruby_specs || package.force_ruby_platform? - spec_group = SpecGroup.create_for(specs_by_platform, @platforms, platform) - groups << spec_group + groups << Resolver::Candidate.new(version, specs: platform_specs) - groups - end - else - [] - end + groups end end - def index_for(dependency) - source_for(dependency.name).specs - end - def source_for(name) @source_requirements[name] || @source_requirements[:default] end - def results_for(dependency) - @results_for[dependency] ||= index_for(dependency).search(dependency) + def default_bundler_source + @source_requirements[:default_bundler] end - def name_for(dependency) - dependency.name + def bundler_pinned_to_current_version? + !default_bundler_source.nil? end def name_for_explicit_dependency_source @@ -177,245 +300,193 @@ module Bundler "Gemfile" end - def requirement_satisfied_by?(requirement, activated, spec) - requirement.matches_spec?(spec) || spec.source.is_a?(Source::Gemspec) - end + def raise_not_found!(package) + name = package.name + source = source_for(name) + specs = @all_specs[name] + matching_part = name + requirement_label = SharedHelpers.pretty_dependency(package.dependency) + cache_message = begin + " or in gems cached in #{Bundler.settings.app_cache_path}" if Bundler.app_cache.exist? + rescue GemfileNotFound + nil + end + specs_matching_requirement = filter_matching_specs(specs, package.dependency.requirement) - def dependencies_equal?(dependencies, other_dependencies) - dependencies.map(&:dep) == other_dependencies.map(&:dep) - end + not_found_message = if specs_matching_requirement.any? + specs = specs_matching_requirement + matching_part = requirement_label + platforms = package.platforms - def sort_dependencies(dependencies, activated, conflicts) - dependencies.sort_by do |dependency| - name = name_for(dependency) - vertex = activated.vertex_named(name) - [ - @base[name].any? ? 0 : 1, - vertex.payload ? 0 : 1, - vertex.root? ? 0 : 1, - amount_constrained(dependency), - conflicts[name] ? 0 : 1, - vertex.payload ? 0 : search_for(dependency).count, - self.class.platform_sort_key(dependency.__platform), - ] + if platforms.size == 1 + "Could not find gem '#{requirement_label}' with platform '#{platforms.first}'" + else + "Could not find gems matching '#{requirement_label}' valid for all resolution platforms (#{platforms.join(", ")})" + end + else + "Could not find gem '#{requirement_label}'" end - end - def self.platform_sort_key(platform) - # Prefer specific platform to not specific platform - return ["99-LAST", "", "", ""] if Gem::Platform::RUBY == platform - ["00", *platform.to_a.map {|part| part || "" }] + message = String.new("#{not_found_message} in #{source}#{cache_message}.\n") + + if specs.any? + message << "\n#{other_specs_matching_message(specs, matching_part)}" + end + + raise GemNotFound, message end private - def base_requirements - @base.base_requirements + def filtered_versions_for(package) + @gem_version_promoter.filter_versions(package, @all_versions[package]) end - def prerelease_specified - @gem_version_promoter.prerelease_specified + def raise_all_versions_filtered_out!(package) + level = @gem_version_promoter.level + name = package.name + locked_version = package.locked_version + requirement = package.dependency + + raise GemNotFound, + "#{name} is locked to #{locked_version}, while Gemfile is requesting #{requirement}. " \ + "--strict --#{level} was specified, but there are no #{level} level upgrades from #{locked_version} satisfying #{requirement}, so version solving has failed" end - def remove_from_candidates(spec) - @base.delete(spec) + def filter_matching_specs(specs, requirements) + Array(requirements).flat_map do |requirement| + specs.select {| spec| requirement_satisfied_by?(requirement, spec) } + end + end - @results_for.keys.each do |dep| - next unless dep.name == spec.name + def filter_prereleases(specs, package) + return specs unless package.ignores_prereleases? && specs.size > 1 + + specs.reject {|s| s.version.prerelease? } + end - @results_for[dep].reject {|s| s.name == spec.name && s.version == spec.version } + # Ignore versions that depend on themselves incorrectly + def filter_invalid_self_dependencies(specs, name) + specs.reject do |s| + s.dependencies.any? {|d| d.name == name && !d.requirement.satisfied_by?(s.version) } end + end - reset_spec_cache + def requirement_satisfied_by?(requirement, spec) + requirement.satisfied_by?(spec.version) || spec.source.is_a?(Source::Gemspec) end - def reset_spec_cache - @search_for = {} - @gem_version_promoter.reset + def sort_versions_by_preferred(package, versions) + @gem_version_promoter.sort_versions(package, versions) end - # returns an integer \in (-\infty, 0] - # a number closer to 0 means the dependency is less constraining - # - # dependencies w/ 0 or 1 possibilities (ignoring version requirements) - # are given very negative values, so they _always_ sort first, - # before dependencies that are unconstrained - def amount_constrained(dependency) - @amount_constrained ||= {} - @amount_constrained[dependency.name] ||= if (base = @base[dependency.name]) && !base.empty? - dependency.requirement.satisfied_by?(base.first.version) ? 0 : 1 - else - all = index_for(dependency).search(dependency.name).size + def repository_for(package) + source_for(package.name) + end - if all <= 1 - all - 1_000_000 - else - search = search_for(dependency) - search = prerelease_specified[dependency.name] ? search.count : search.count {|s| !s.version.prerelease? } - search - all - end - end + def base_requirements + @base.base_requirements end - def verify_gemfile_dependencies_are_found!(requirements) - requirements.map! do |requirement| - name = requirement.name - next requirement if name == "bundler" - next requirement unless search_for(requirement).empty? - next unless requirement.current_platform? - - if (base = @base[name]) && !base.empty? - version = base.first.version - message = "You have requested:\n" \ - " #{name} #{requirement.requirement}\n\n" \ - "The bundle currently has #{name} locked at #{version}.\n" \ - "Try running `bundle update #{name}`\n\n" \ - "If you are updating multiple gems in your Gemfile at once,\n" \ - "try passing them all to `bundle update`" - else - message = gem_not_found_message(name, requirement, source_for(name)) + def prepare_dependencies(requirements, packages) + to_dependency_hash(requirements, packages).map do |dep_package, dep_constraint| + name = dep_package.name + + next [dep_package, dep_constraint] if name == "bundler" + + dep_range = dep_constraint.range + versions = select_sorted_versions(dep_package, dep_range) + if versions.empty? && dep_package.ignores_prereleases? + @all_versions.delete(dep_package) + @sorted_versions.delete(dep_package) + dep_package.consider_prereleases! + versions = select_sorted_versions(dep_package, dep_range) end - raise GemNotFound, message - end.compact! - end - def gem_not_found_message(name, requirement, source, extra_message = "") - specs = source.specs.search(name).sort_by {|s| [s.version, s.platform.to_s] } - matching_part = name - requirement_label = SharedHelpers.pretty_dependency(requirement) - cache_message = begin - " or in gems cached in #{Bundler.settings.app_cache_path}" if Bundler.app_cache.exist? - rescue GemfileNotFound - nil - end - specs_matching_requirement = specs.select {| spec| requirement.matches_spec?(spec) } + if versions.empty? && select_all_versions(dep_package, dep_range).any? + raise_all_versions_filtered_out!(dep_package) + end - if specs_matching_requirement.any? - specs = specs_matching_requirement - matching_part = requirement_label - requirement_label = "#{requirement_label}' with platform '#{requirement.__platform}" - end + next [dep_package, dep_constraint] unless versions.empty? - message = String.new("Could not find gem '#{requirement_label}'#{extra_message} in #{source}#{cache_message}.\n") + next unless dep_package.current_platform? - if specs.any? - message << "\nThe source contains the following gems matching '#{matching_part}':\n" - message << specs.map {|s| " * #{s.full_name}" }.join("\n") - end + raise_not_found!(dep_package) + end.compact.to_h + end - message + def select_sorted_versions(package, range) + range.select_versions(@sorted_versions[package]) end - def version_conflict_message(e) - # only show essential conflicts, if possible - conflicts = e.conflicts.dup + def select_all_versions(package, range) + range.select_versions(@all_versions[package]) + end - if conflicts["bundler"] - conflicts.replace("bundler" => conflicts["bundler"]) - else - conflicts.delete_if do |_name, conflict| - deps = conflict.requirement_trees.map(&:last).flatten(1) - !Bundler::VersionRanges.empty?(*Bundler::VersionRanges.for_many(deps.map(&:requirement))) + def other_specs_matching_message(specs, requirement) + message = String.new("The source contains the following gems matching '#{requirement}':\n") + message << specs.map {|s| " * #{s.full_name}" }.join("\n") + message + end + + def requirement_to_range(requirement) + ranges = requirement.requirements.map do |(op, version)| + ver = Resolver::Candidate.new(version).generic! + platform_ver = Resolver::Candidate.new(version).platform_specific! + + case op + when "~>" + name = "~> #{ver}" + bump = Resolver::Candidate.new(version.bump.to_s + ".A") + PubGrub::VersionRange.new(name: name, min: ver, max: bump, include_min: true) + when ">" + PubGrub::VersionRange.new(min: platform_ver) + when ">=" + PubGrub::VersionRange.new(min: ver, include_min: true) + when "<" + PubGrub::VersionRange.new(max: ver) + when "<=" + PubGrub::VersionRange.new(max: platform_ver, include_max: true) + when "=" + PubGrub::VersionRange.new(min: ver, max: platform_ver, include_min: true, include_max: true) + when "!=" + PubGrub::VersionRange.new(min: ver, max: platform_ver, include_min: true, include_max: true).invert + else + raise "bad version specifier: #{op}" end end - e = Molinillo::VersionConflict.new(conflicts, e.specification_provider) unless conflicts.empty? - - e.message_with_trees( - :full_message_for_conflict => lambda do |name, conflict| - trees = conflict.requirement_trees - - # called first, because we want to reduce the amount of work required to find maximal empty sets - trees = trees.uniq {|t| t.flatten.map {|dep| [dep.name, dep.requirement] } } + ranges.inject(&:intersect) + end - # bail out if tree size is too big for Array#combination to make any sense - if trees.size <= 15 - maximal = 1.upto(trees.size).map do |size| - trees.map(&:last).flatten(1).combination(size).to_a - end.flatten(1).select do |deps| - Bundler::VersionRanges.empty?(*Bundler::VersionRanges.for_many(deps.map(&:requirement))) - end.min_by(&:size) + def to_dependency_hash(dependencies, packages) + dependencies.inject({}) do |deps, dep| + package = packages[dep.name] - trees.reject! {|t| !maximal.include?(t.last) } if maximal + current_req = deps[package] + new_req = parse_dependency(package, dep.requirement) - trees.sort_by! {|t| t.reverse.map(&:name) } - end + deps[package] = if current_req + current_req.intersect(new_req) + else + new_req + end - if trees.size > 1 || name == "bundler" - o = if name.end_with?("\0") - String.new("Bundler found conflicting requirements for the #{name} version:") - else - String.new("Bundler could not find compatible versions for gem \"#{name}\":") - end - o << %(\n) - o << %( In #{name_for_explicit_dependency_source}:\n) - o << trees.map do |tree| - t = "".dup - depth = 2 - - base_tree = tree.first - base_tree_name = base_tree.name - - if base_tree_name.end_with?("\0") - t = nil - else - tree.each do |req| - t << " " * depth << SharedHelpers.pretty_dependency(req) - unless tree.last == req - if spec = conflict.activated_by_name[req.name] - t << %( was resolved to #{spec.version}, which) - end - t << %( depends on) - end - t << %(\n) - depth += 1 - end - end - t - end.compact.join("\n") - else - o = String.new - end + deps + end + end - if name == "bundler" - o << %(\n Current Bundler version:\n bundler (#{Bundler::VERSION})) - - conflict_dependency = conflict.requirement - conflict_requirement = conflict_dependency.requirement - other_bundler_required = !conflict_requirement.satisfied_by?(Gem::Version.new(Bundler::VERSION)) - - if other_bundler_required - o << "\n\n" - - candidate_specs = source_for(:default_bundler).specs.search(conflict_dependency) - if candidate_specs.any? - target_version = candidate_specs.last.version - new_command = [File.basename($PROGRAM_NAME), "_#{target_version}_", *ARGV].join(" ") - o << "Your bundle requires a different version of Bundler than the one you're running.\n" - o << "Install the necessary version with `gem install bundler:#{target_version}` and rerun bundler using `#{new_command}`\n" - else - o << "Your bundle requires a different version of Bundler than the one you're running, and that version could not be found.\n" - end - end - elsif name.end_with?("\0") - o << %(\n Current #{name} version:\n #{SharedHelpers.pretty_dependency(@metadata_requirements.find {|req| req.name == name })}\n\n) - elsif !conflict.existing - o << "\n" - - relevant_source = conflict.requirement.source || source_for(name) - - extra_message = if trees.first.size > 1 - ", which is required by gem '#{SharedHelpers.pretty_dependency(trees.first[-2])}'," - else - "" - end - - o << gem_not_found_message(name, conflict.requirement, relevant_source, extra_message) - end + def bundler_not_found_message(conflict_dependencies) + candidate_specs = filter_matching_specs(default_bundler_source.specs.search("bundler"), conflict_dependencies) - o - end - ) + if candidate_specs.any? + target_version = candidate_specs.last.version + new_command = [File.basename($PROGRAM_NAME), "_#{target_version}_", *ARGV].join(" ") + "Your bundle requires a different version of Bundler than the one you're running.\n" \ + "Install the necessary version with `gem install bundler:#{target_version}` and rerun bundler using `#{new_command}`\n" + else + "Your bundle requires a different version of Bundler than the one you're running, and that version could not be found.\n" + end end end end |