Class: Bundler::Resolver
Defined Under Namespace
Classes: Base, SpecGroup
Constant Summary
Constants included
from GemHelpers
GemHelpers::GENERICS, GemHelpers::GENERIC_CACHE
Instance Method Summary
collapse
#allow_missing?, #dependencies_equal?, #name_for_locking_dependency_source
#output, #progress_rate
Methods included from GemHelpers
generic, generic_local_platform, local_platform, platform_specificity_match, same_deps, same_specificity, select_best_platform_match, sort_best_platform_match
Constructor Details
#initialize(source_requirements, base, gem_version_promoter, additional_base_requirements, platforms) ⇒ Resolver
Returns a new instance of Resolver.
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/bundler/resolver.rb', line 11
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]
@gem_version_promoter = gem_version_promoter
end
|
Instance Method Details
#after_resolution ⇒ Object
89
90
91
|
# File 'lib/bundler/resolver.rb', line 89
def after_resolution
Bundler.ui.info ""
end
|
#before_resolution ⇒ Object
85
86
87
|
# File 'lib/bundler/resolver.rb', line 85
def before_resolution
Bundler.ui.info "Resolving dependencies...", debug?
end
|
#debug(depth = 0) ⇒ void
This method returns an undefined value.
Conveys debug information to the user.
68
69
70
71
72
73
|
# File 'lib/bundler/resolver.rb', line 68
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}" }
end
|
#debug? ⇒ Boolean
75
76
77
78
79
80
81
82
83
|
# File 'lib/bundler/resolver.rb', line 75
def debug?
return @debug_mode if defined?(@debug_mode)
@debug_mode =
ENV["BUNDLER_DEBUG_RESOLVER"] ||
ENV["BUNDLER_DEBUG_RESOLVER_TREE"] ||
ENV["DEBUG_RESOLVER"] ||
ENV["DEBUG_RESOLVER_TREE"] ||
false
end
|
#dependencies_for(specification) ⇒ Object
99
100
101
|
# File 'lib/bundler/resolver.rb', line 99
def dependencies_for(specification)
specification.dependencies_for_activated_platforms
end
|
#index_for(dependency) ⇒ Object
136
137
138
|
# File 'lib/bundler/resolver.rb', line 136
def index_for(dependency)
source_for(dependency.name).specs
end
|
#indicate_progress ⇒ Object
93
94
95
|
# File 'lib/bundler/resolver.rb', line 93
def indicate_progress
Bundler.ui.info ".", false unless debug?
end
|
#name_for(dependency) ⇒ Object
148
149
150
|
# File 'lib/bundler/resolver.rb', line 148
def name_for(dependency)
dependency.name
end
|
#name_for_explicit_dependency_source ⇒ Object
152
153
154
155
156
|
# File 'lib/bundler/resolver.rb', line 152
def name_for_explicit_dependency_source
Bundler.default_gemfile.basename.to_s
rescue StandardError
"Gemfile"
end
|
#requirement_satisfied_by?(requirement, activated, spec) ⇒ Boolean
158
159
160
|
# File 'lib/bundler/resolver.rb', line 158
def requirement_satisfied_by?(requirement, activated, spec)
requirement.matches_spec?(spec) || spec.source.is_a?(Source::Gemspec)
end
|
#results_for(dependency) ⇒ Object
144
145
146
|
# File 'lib/bundler/resolver.rb', line 144
def results_for(dependency)
@results_for[dependency] ||= index_for(dependency).search(dependency)
end
|
#search_for(dependency) ⇒ Object
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
# File 'lib/bundler/resolver.rb', line 103
def search_for(dependency)
@search_for[dependency] ||= begin
name = dependency.name
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
dep_platforms = dependency.gem_platforms(@platforms)
@gem_version_promoter.sort_versions(dependency, results).group_by(&:version).reduce([]) do |groups, (_, specs)|
relevant_platforms = dep_platforms.select {|platform| specs.any? {|spec| spec.match_platform(platform) } }
next groups unless relevant_platforms.any?
ruby_specs = select_best_platform_match(specs, Gem::Platform::RUBY)
if ruby_specs.any?
spec_group_ruby = SpecGroup.new(ruby_specs, [Gem::Platform::RUBY])
spec_group_ruby.force_ruby_platform = dependency.force_ruby_platform
groups << spec_group_ruby
end
next groups if @resolving_only_for_ruby || dependency.force_ruby_platform
platform_specs = relevant_platforms.flat_map {|platform| select_best_platform_match(specs, platform) }
next groups if platform_specs == ruby_specs
spec_group = SpecGroup.new(platform_specs, relevant_platforms)
groups << spec_group
groups
end
end
end
|
#sort_dependencies(dependencies, activated, conflicts) ⇒ Object
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
# File 'lib/bundler/resolver.rb', line 162
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,
]
end
end
|
#source_for(name) ⇒ Object
140
141
142
|
# File 'lib/bundler/resolver.rb', line 140
def source_for(name)
@source_requirements[name] || @source_requirements[:default]
end
|
#start(requirements, exclude_specs: []) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/bundler/resolver.rb', line 22
def start(requirements, exclude_specs: [])
@metadata_requirements, regular_requirements = requirements.partition {|dep| dep.name.end_with?("\0") }
exclude_specs.each do |spec|
remove_from_candidates(spec)
end
requirements.each {|dep| prerelease_specified[dep.name] ||= dep.prerelease? }
verify_gemfile_dependencies_are_found!(requirements)
result = @resolver.resolve(requirements).
map(&:payload).
reject {|sg| sg.name.end_with?("\0") }.
map(&:to_specs).
flatten
SpecSet.new(SpecSet.new(result).for(regular_requirements, false, @platforms))
rescue Molinillo::VersionConflict => e
conflicts = e.conflicts
deps_to_unlock = conflicts.values.inject([]) do |deps, conflict|
deps |= conflict.requirement_trees.flatten.map {|req| base_requirements[req.name] }.compact
end
if deps_to_unlock.any?
@base.unlock_deps(deps_to_unlock)
reset_spec_cache
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."
end
|