Class: Bundler::Resolver

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Methods included from Molinillo::SpecificationProvider

#allow_missing?

Methods included from Molinillo::UI

#output, #progress_rate

Constructor Details

#initialize(index, source_requirements, base, ruby_version) ⇒ Resolver

Returns a new instance of Resolver.



188
189
190
191
192
193
194
195
196
197
# File 'lib/bundler/resolver.rb', line 188

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

Class Method Details

.resolve(requirements, index, source_requirements = {}, base = [], ruby_version = nil) ⇒ 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.


181
182
183
184
185
186
# File 'lib/bundler/resolver.rb', line 181

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

Instance Method Details

#after_resolutionObject



235
236
237
# File 'lib/bundler/resolver.rb', line 235

def after_resolution
  Bundler.ui.info ""
end

#before_resolutionObject



231
232
233
# File 'lib/bundler/resolver.rb', line 231

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.

Parameters:

  • depth (Integer) (defaults to: 0)

    the current depth of the resolution process.



219
220
221
222
223
224
# File 'lib/bundler/resolver.rb', line 219

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

#debug?Boolean

Returns:

  • (Boolean)


226
227
228
229
# File 'lib/bundler/resolver.rb', line 226

def debug?
  return @debug_mode if defined?(@debug_mode)
  @debug_mode = ENV["DEBUG_RESOLVER"] || ENV["DEBUG_RESOLVER_TREE"]
end

#indicate_progressObject



239
240
241
# File 'lib/bundler/resolver.rb', line 239

def indicate_progress
  Bundler.ui.info ".", false
end

#start(requirements) ⇒ Object



199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/bundler/resolver.rb', line 199

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