Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
312 lines (249 sloc) 7.94 KB
/Users/nsingh/.rvm/gems/ruby-1.9.2-p180@b/gems/bundler-1.0.15/lib/bundler.rb
source.rb remotespecs
Fetching source index for http://rubygems.org
When we do 'bundel install' then install method defined in CLI gets invoked
Thor is like rake but it has some additional features. If you want to know more about Thor then I highly recommed you to watch
railscast on thor at http://railscasts.com/episodes/242-thor
module Bundler
class CLI < Thor
default_task :install
def help; end
def init; end
def check; end
def install; end
def update; end
def lock; end
def unlock; end
def show; end
def cache; end
def package; end
def exec; end
def config; end
def open; end
def console; end
def version; end
def viz; end
def gem; end
end
end
def install
....
Installer.install(Bundler.root, Bundler.definition, opts)
....
end
def definition(unlock = nil)
@definition = nil if unlock
@definition ||= begin
configure
upgrade_lockfile
puts "default_gemfile is #{default_gemfile.inspect}"
puts "default_lockfile is #{default_lockfile.inspect}"
puts "default unlock is #{unlock.inspect}"
Definition.build(default_gemfile, default_lockfile, unlock)
end
end
module Bundler
class Definition
def self.build(gemfile, lockfile, unlock)
unlock ||= {}
gemfile = Pathname.new(gemfile).expand_path
unless gemfile.file?
raise GemfileNotFound, "#{gemfile} not found"
end
Dsl.evaluate(gemfile, lockfile, unlock)
end
end
end
module Bundler
class Dsl
def self.evaluate(gemfile, lockfile, unlock)
builder = new
builder.instance_eval(Bundler.read_file(gemfile.to_s), gemfile.to_s, 1)
builder.to_definition(lockfile, unlock)
end
end
end
def gem(name, *args)
.....
@dependencies << Dependency.new(name, version, options)
end
def install
....
Installer.install(Bundler.root, Bundler.definition, opts)
....
end
module Bundler
class Installer < Environment
def self.install(root, definition, options = {})
puts "root is #{root.inspect}"
puts "definition is #{definition.inspect}"
puts "options is #{options.inspect}"
installer = new(root, definition)
installer.run(options)
installer
end
def run(options)
.....
@definition.resolve_remotely!
...
end
end
def resolve_remotely!
raise "Specs already loaded" if @specs
@remote = true
@sources.each { |s| s.remote! }
specs
end
def specs
@specs ||= begin
specs = resolve.materialize(requested_dependencies)
unless specs["bundler"].any?
local = Bundler.settings[:frozen] ? rubygems_index : index
bundler = local.search(Gem::Dependency.new('bundler', VERSION)).last
specs["bundler"] = bundler if bundler
end
specs
end
end
def resolve
@resolve ||= begin
if Bundler.settings[:frozen]
@locked_specs
else
last_resolve = converge_locked_specs
source_requirements = {}
puts "dependencies is " + dependencies.inspect
dependencies.each do |dep|
next unless dep.source
source_requirements[dep.name] = dep.source.specs
end
# Run a resolve against the locally available gems
last_resolve.merge Resolver.resolve(expanded_dependencies, index, source_requirements, last_resolve)
end
end
end
def index
@index ||= Index.build do |idx|
@sources.each do |s|
idx.use s.specs
end
end
end
module Bundler
class Source
def fetch_specs
Index.build do |idx|
idx.use installed_specs
idx.use cached_specs if @allow_cached || @allow_remote
idx.use remote_specs if @allow_remote
end
end
def remote_specs
raise 'boom2'
@remote_specs ||= begin
idx = Index.new
old = Bundler.rubygems.sources
puts "remotes is " + remotes.inspect
remotes.each do |uri|
Bundler.ui.info "Fetching source index for #{uri}"
Gem.sources = ["#{uri}"]
nn = 0
fetch_all_remote_specs do |n,v|
v.each do |name, version, platform|
#puts name + ' '+version.to_s+ ' '+platform
next if name == 'bundler'
spec = RemoteSpecification.new(name, version, platform, uri)
spec.source = self
@spec_fetch_map[spec.full_name] = [spec, uri]
idx << spec
end
end
end
idx
ensure
Bundler.rubygems.sources = old
end
end
end
end
Fetching source index for http://rubygems.org/
When I ran this code I found 129,136 records. This number is always changing as people are pushing newer versions of gems.
addressable 0.1.0 ruby
addressable 0.1.1 ruby
addressable 0.1.2 ruby
addressable 1.0.0 ruby
addressable 1.0.1 ruby
addressable 1.0.2 ruby
addressable 1.0.3 ruby
addressable 1.0.4 ruby
addressable 2.0.0 ruby
addressable 2.0.1 ruby
addressable 2.0.2 ruby
addressable 2.1.0 ruby
addressable 2.1.1 ruby
addressable 2.1.2 ruby
addressable 2.2.0 ruby
addressable 2.2.1 ruby
addressable 2.2.2 ruby
addressable 2.2.3 ruby
addressable 2.2.4 ruby
addressable 2.2.5 ruby
addressable 2.2.6 ruby
source 'http://rubygems.org'
gem 'rails', '3.0.1'
gem 'sqlite3'
last_resolve.merge Resolver.resolve(expanded_dependencies, index, source_requirements, last_resolve)
requested_dependencies is [<Bundler::Dependency type=:runtime name="rails" requirements="= 3.0.1">, <Bundler::Dependency type=:runtime name="sqlite3" requirements=">= 0">]
dependencies is [<Bundler::Dependency type=:runtime name="rails" requirements="= 3.0.1">, <Bundler::Dependency type=:runtime name="sqlite3" requirements=">= 0">]
expanded_dependencies is [rails (= 3.0.1), sqlite3 (>= 0)]
DEBUG_RESOLVER=true bundle install
module Bundler
class Resolver
def self.resolve(requirements, index, source_requirements = {}, base = [])
base = SpecSet.new(base) unless base.is_a?(SpecSet)
resolver = new(index, source_requirements, base)
result = catch(:success) do
resolver.start(requirements)
raise resolver.version_conflict
nil
end
SpecSet.new(result)
end
end
end
matching_versions = search(current)
matching_versions.reverse_each do |spec_group|
conflict = resolve_requirement(spec_group, current, reqs.dup, activated.dup)
conflicts << conflict if conflict
end
def resolve_requirement(spec_group, requirement, reqs, activated)
......
# We create a savepoint and mark it by the name of the requirement that caused
# the gem to be activated. If the activated gem ever conflicts, we are able to
# jump back to this point and try another version of the gem.
length = @stack.length
@stack << requirement.name
retval = catch(requirement.name) do
resolve(reqs, activated)
end
.....
end
Gemfile is instance evaled whenever you do bundle install. It does not care about presence of Gemfile.lock
gem 'rails', '= 3.0.7'
gem 'meta_where'
gem 'arel'
When gem arel is added to above list then no need to reach out to remote because arel can be satisfied with existing information.
if Bundler.default_lockfile.exist? && !options["update"]
begin
tmpdef = Definition.build(Bundler.default_gemfile, Bundler.default_lockfile, nil)
local = true unless tmpdef.new_platform? || tmpdef.missing_specs.any?
rescue BundlerError
end
end
# Since we are installing, we can resolve the definition
# using remote specs
unless local
options["local"] ?
@definition.resolve_with_cache! :
@definition.resolve_remotely!
end