2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
2013-07-09 19:21:36 -04:00
|
|
|
##
|
|
|
|
# Used internally to indicate that a dependency conflicted
|
|
|
|
# with a spec that would be activated.
|
|
|
|
|
2013-11-18 19:34:13 -05:00
|
|
|
class Gem::Resolver::Conflict
|
2013-11-21 18:27:30 -05:00
|
|
|
##
|
|
|
|
# The specification that was activated prior to the conflict
|
|
|
|
|
2013-07-09 19:21:36 -04:00
|
|
|
attr_reader :activated
|
|
|
|
|
2013-11-21 18:27:30 -05:00
|
|
|
##
|
|
|
|
# The dependency that is in conflict with the activated gem.
|
|
|
|
|
2013-07-09 19:21:36 -04:00
|
|
|
attr_reader :dependency
|
|
|
|
|
2013-11-10 12:51:40 -05:00
|
|
|
attr_reader :failed_dep # :nodoc:
|
|
|
|
|
2013-11-21 18:27:30 -05:00
|
|
|
##
|
|
|
|
# Creates a new resolver conflict when +dependency+ is in conflict with an
|
|
|
|
# already +activated+ specification.
|
|
|
|
|
2013-07-09 19:21:36 -04:00
|
|
|
def initialize(dependency, activated, failed_dep=dependency)
|
|
|
|
@dependency = dependency
|
|
|
|
@activated = activated
|
|
|
|
@failed_dep = failed_dep
|
|
|
|
end
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def ==(other) # :nodoc:
|
2013-11-10 12:51:40 -05:00
|
|
|
self.class === other and
|
|
|
|
@dependency == other.dependency and
|
|
|
|
@activated == other.activated and
|
|
|
|
@failed_dep == other.failed_dep
|
|
|
|
end
|
|
|
|
|
2013-11-21 18:27:30 -05:00
|
|
|
##
|
|
|
|
# A string explanation of the conflict.
|
|
|
|
|
2013-11-18 19:34:13 -05:00
|
|
|
def explain
|
|
|
|
"<Conflict wanted: #{@failed_dep}, had: #{activated.spec.full_name}>"
|
|
|
|
end
|
|
|
|
|
2013-07-09 19:21:36 -04:00
|
|
|
##
|
|
|
|
# Return the 2 dependency objects that conflicted
|
|
|
|
|
|
|
|
def conflicting_dependencies
|
|
|
|
[@failed_dep.dependency, @activated.request.dependency]
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Explanation of the conflict used by exceptions to print useful messages
|
|
|
|
|
|
|
|
def explanation
|
|
|
|
activated = @activated.spec.full_name
|
2014-09-13 23:30:02 -04:00
|
|
|
dependency = @failed_dep.dependency
|
|
|
|
requirement = dependency.requirement
|
2020-06-10 13:46:05 -04:00
|
|
|
alternates = dependency.matching_specs.map {|spec| spec.full_name }
|
2013-07-09 19:21:36 -04:00
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
unless alternates.empty?
|
2014-09-13 23:30:02 -04:00
|
|
|
matching = <<-MATCHING.chomp
|
|
|
|
|
|
|
|
Gems matching %s:
|
|
|
|
%s
|
|
|
|
MATCHING
|
|
|
|
|
|
|
|
matching = matching % [
|
|
|
|
dependency,
|
|
|
|
alternates.join(', '),
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
explanation = <<-EXPLANATION
|
|
|
|
Activated %s
|
|
|
|
which does not match conflicting dependency (%s)
|
|
|
|
|
|
|
|
Conflicting dependency chains:
|
|
|
|
%s
|
|
|
|
|
|
|
|
versus:
|
|
|
|
%s
|
|
|
|
%s
|
|
|
|
EXPLANATION
|
|
|
|
|
|
|
|
explanation % [
|
|
|
|
activated, requirement,
|
|
|
|
request_path(@activated).reverse.join(", depends on\n "),
|
|
|
|
request_path(@failed_dep).reverse.join(", depends on\n "),
|
2020-12-08 02:33:39 -05:00
|
|
|
matching
|
2013-07-09 19:21:36 -04:00
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2013-11-21 18:27:30 -05:00
|
|
|
##
|
|
|
|
# Returns true if the conflicting dependency's name matches +spec+.
|
|
|
|
|
2013-07-09 19:21:36 -04:00
|
|
|
def for_spec?(spec)
|
|
|
|
@dependency.name == spec.name
|
|
|
|
end
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def pretty_print(q) # :nodoc:
|
2013-07-09 19:21:36 -04:00
|
|
|
q.group 2, '[Dependency conflict: ', ']' do
|
|
|
|
q.breakable
|
|
|
|
|
|
|
|
q.text 'activated '
|
|
|
|
q.pp @activated
|
|
|
|
|
|
|
|
q.breakable
|
|
|
|
q.text ' dependency '
|
|
|
|
q.pp @dependency
|
|
|
|
|
|
|
|
q.breakable
|
2018-11-21 05:20:47 -05:00
|
|
|
if @dependency == @failed_dep
|
2013-07-09 19:21:36 -04:00
|
|
|
q.text ' failed'
|
|
|
|
else
|
|
|
|
q.text ' failed dependency '
|
|
|
|
q.pp @failed_dep
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
2013-11-21 18:27:30 -05:00
|
|
|
# Path of activations from the +current+ list.
|
2013-07-09 19:21:36 -04:00
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def request_path(current)
|
2013-11-21 18:27:30 -05:00
|
|
|
path = []
|
2013-07-09 19:21:36 -04:00
|
|
|
|
|
|
|
while current do
|
2014-09-13 23:30:02 -04:00
|
|
|
case current
|
|
|
|
when Gem::Resolver::ActivationRequest then
|
|
|
|
path <<
|
|
|
|
"#{current.request.dependency}, #{current.spec.version} activated"
|
|
|
|
|
|
|
|
current = current.parent
|
|
|
|
when Gem::Resolver::DependencyRequest then
|
|
|
|
path << "#{current.dependency}"
|
2013-07-09 19:21:36 -04:00
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
current = current.requester
|
|
|
|
else
|
|
|
|
raise Gem::Exception, "[BUG] unknown request class #{current.class}"
|
|
|
|
end
|
2013-07-09 19:21:36 -04:00
|
|
|
end
|
|
|
|
|
2013-11-10 12:51:40 -05:00
|
|
|
path = ['user request (gem command or Gemfile)'] if path.empty?
|
|
|
|
|
2013-07-09 19:21:36 -04:00
|
|
|
path
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Return the Specification that listed the dependency
|
|
|
|
|
|
|
|
def requester
|
|
|
|
@failed_dep.requester
|
|
|
|
end
|
|
|
|
end
|