Class: Bundler::Resolver
- Inherits:
-
Object
- Object
- Bundler::Resolver
- Includes:
- Molinillo::SpecificationProvider, Molinillo::UI
- Defined in:
- lib/bundler/resolver.rb
Defined Under Namespace
Classes: SpecGroup
Constant Summary collapse
- ALL =
Bundler::Dependency::PLATFORM_MAP.values.uniq.freeze
Class Method Summary collapse
-
.resolve(requirements, index, source_requirements = {}, base = []) ⇒ Object
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.
Instance Method Summary collapse
- #after_resolution ⇒ Object
- #before_resolution ⇒ Object
-
#debug(depth = 0) ⇒ void
Conveys debug information to the user.
- #debug? ⇒ Boolean
- #indicate_progress ⇒ Object
-
#initialize(index, source_requirements, base) ⇒ Resolver
constructor
A new instance of Resolver.
- #start(requirements) ⇒ Object
Methods included from Molinillo::UI
Constructor Details
#initialize(index, source_requirements, base) ⇒ Resolver
Returns a new instance of Resolver.
187 188 189 190 191 192 193 194 195 |
# File 'lib/bundler/resolver.rb', line 187 def initialize(index, source_requirements, base) @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_root_vertex ls.name, Dependency.new(ls.name, ls.version) } end |
Class Method Details
.resolve(requirements, index, source_requirements = {}, base = []) ⇒ Object
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.
179 180 181 182 183 184 |
# File 'lib/bundler/resolver.rb', line 179 def self.resolve(requirements, index, source_requirements = {}, base = []) base = SpecSet.new(base) unless base.is_a?(SpecSet) resolver = new(index, source_requirements, base) result = resolver.start(requirements) SpecSet.new(result) end |
Instance Method Details
#after_resolution ⇒ Object
233 234 235 |
# File 'lib/bundler/resolver.rb', line 233 def after_resolution Bundler.ui.info '' end |
#before_resolution ⇒ Object
229 230 231 |
# File 'lib/bundler/resolver.rb', line 229 def before_resolution Bundler.ui.info 'Resolving dependencies...', false end |
#debug(depth = 0) ⇒ void
This method returns an undefined value.
Conveys debug information to the user.
217 218 219 220 221 222 223 |
# File 'lib/bundler/resolver.rb', line 217 def debug(depth = 0) if 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 end |
#debug? ⇒ Boolean
225 226 227 |
# File 'lib/bundler/resolver.rb', line 225 def debug? ENV['DEBUG_RESOLVER'] || ENV['DEBUG_RESOLVER_TREE'] end |
#indicate_progress ⇒ Object
237 238 239 |
# File 'lib/bundler/resolver.rb', line 237 def indicate_progress Bundler.ui.info '.', false end |
#start(requirements) ⇒ Object
197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/bundler/resolver.rb', line 197 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.) rescue Molinillo::CircularDependencyError => e names = e.dependencies.sort_by(&:name).map { |d| "gem '#{d.name}'"} raise CyclicDependencyError, "Your Gemfile requires gems that depend" \ " on each other, creating an infinite loop. Please remove" \ " #{names.count > 1 ? 'either ' : '' }#{names.join(' or ')}" \ " and try again." end |