diff options
author | Carl Lerche <carllerche@mac.com> | 2010-04-23 13:11:04 -0700 |
---|---|---|
committer | Carl Lerche <carllerche@mac.com> | 2010-04-23 13:11:04 -0700 |
commit | 4d6f5c4ce372d7e636478e38ec48f28c6f44129d (patch) | |
tree | fea2f7947928d1a62f9a859f3faaab71bc6f3d60 /lib | |
parent | eaac39d3b9cd5645a1567f961303dcc2a4868870 (diff) | |
download | bundler-4d6f5c4ce372d7e636478e38ec48f28c6f44129d.tar.gz |
Push cached gems for install time into the Rubygems source
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bundler/cli.rb | 2 | ||||
-rw-r--r-- | lib/bundler/definition.rb | 4 | ||||
-rw-r--r-- | lib/bundler/dsl.rb | 15 | ||||
-rw-r--r-- | lib/bundler/environment.rb | 5 | ||||
-rw-r--r-- | lib/bundler/installer.rb | 1 | ||||
-rw-r--r-- | lib/bundler/lockfile_parser.rb | 13 | ||||
-rw-r--r-- | lib/bundler/source.rb | 34 |
7 files changed, 43 insertions, 31 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index 73940ce4..e99ce54f 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -88,7 +88,7 @@ module Bundler Bundler.ui.confirm "Your bundle is complete! " + "Use `bundle show [gemname]` to see where a bundled gem is installed." rescue GemNotFound => e - if Bundler.definition.sources.empty? + if Bundler.definition.no_sources? Bundler.ui.warn "Your Gemfile doesn't have any sources. You can add one with a line like 'source :gemcutter'" end raise e diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index f6d293d4..6b2c4c16 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -32,6 +32,10 @@ module Bundler end end + def no_sources? + sources.length == 1 && sources.first.remotes.empty? + end + # TODO: OMG LOL def resolved_dependencies deps = locked_specs_as_deps diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb index 4a7a8cd2..652ee289 100644 --- a/lib/bundler/dsl.rb +++ b/lib/bundler/dsl.rb @@ -9,10 +9,11 @@ module Bundler end def initialize - @source = nil - @sources = [] - @dependencies = [] - @group = [:default] + @rubygems_source = Source::Rubygems.new + @source = nil + @sources = [@rubygems_source] + @dependencies = [] + @group = [:default] end def gem(name, *args) @@ -92,12 +93,6 @@ module Bundler private def rubygems_source(source) - @rubygems_source ||= begin - s = Source::Rubygems.new - @sources << s - s - end - @rubygems_source.add_remote source end diff --git a/lib/bundler/environment.rb b/lib/bundler/environment.rb index 403f1d13..5d6f8c57 100644 --- a/lib/bundler/environment.rb +++ b/lib/bundler/environment.rb @@ -136,11 +136,12 @@ module Bundler specified_sources = all_sources - pinned_sources - unless specified_sources.empty? + unless specified_sources.length == 1 && specified_sources.first.remotes.empty? output << "sources:\n" specified_sources.each do |source| - output << " #{source.to_lock}\n" + o = source.to_lock + output << " #{source.to_lock}\n" unless o.empty? end output << "\n" end diff --git a/lib/bundler/installer.rb b/lib/bundler/installer.rb index 6e3a6dcc..5c99adaa 100644 --- a/lib/bundler/installer.rb +++ b/lib/bundler/installer.rb @@ -71,7 +71,6 @@ module Bundler end idx.use Index.system_gems - idx.use Index.cached_gems rubygems.each do |source| Bundler.ui.debug "Source: Processing index" diff --git a/lib/bundler/lockfile_parser.rb b/lib/bundler/lockfile_parser.rb index 7f75ff7f..11a5fea1 100644 --- a/lib/bundler/lockfile_parser.rb +++ b/lib/bundler/lockfile_parser.rb @@ -6,9 +6,10 @@ module Bundler # Do stuff def initialize(lockfile) - @sources = [] + @rg_source = Source::Rubygems.new + @sources = [@rg_source] @dependencies = [] - @specs = [] + @specs = [] lockfile.split(/\n+/).each do |line| case line @@ -43,17 +44,13 @@ module Bundler options = extract_options(option_line) # There should only be one instance of a rubygem source if type == 'gem' - rg_source.add_remote source - rg_source + @rg_source.add_remote source + @rg_source else TYPES[type].from_lock(source, extra_opts.merge(options)) end end - def rg_source - @rg_source ||= Source::Rubygems.new - end - NAME_VERSION = '(?! )(.*?)(?: \((.*)\))?:?' def parse_dependencies(line) diff --git a/lib/bundler/source.rb b/lib/bundler/source.rb index f423fb12..e0e97888 100644 --- a/lib/bundler/source.rb +++ b/lib/bundler/source.rb @@ -12,7 +12,10 @@ module Bundler def initialize(options = {}) @options = options @remotes = (options["remotes"] || []).map { |r| normalize_uri(r) } - @caches = (options["caches"] || []) + # @caches = (options["caches"] || []) + # Hardcode the paths for now + @caches = [ "#{Bundler.root}/vendor/cache", + "#{Bundler.bundle_path}/cache"] @spec_fetch_map = {} end @@ -39,12 +42,22 @@ module Bundler def fetch(spec) action = @spec_fetch_map[[spec.name, spec.version, spec.platform]] - action.call + action.call if action end def install(spec) Bundler.ui.debug " * Installing" - installer = Gem::Installer.new gem_path(spec), + # TODO: Stop doing craz + # I'm not going to bother tracking which cache gem the spec + # came from, so I'm going to just loop over the caches in + # order of priority until I find it + path = nil + @caches.find do |cache| + path = "#{cache}/#{spec.full_name}.gem" + File.exist?(path) + end + + installer = Gem::Installer.new path, :install_dir => Gem.dir, :ignore_dependencies => true, :wrappers => true, @@ -70,19 +83,22 @@ module Bundler uri end - def gem_path(spec) - "#{Gem.dir}/cache/#{spec.full_name}.gem" - end - def fetch_specs idx = Index.new - fetch_cached_specs(idx) fetch_remote_specs(idx) + fetch_cached_specs(idx) idx end def fetch_cached_specs(idx) - # Nothing yet + @caches.each do |path| + Dir["#{path}/*.gem"].each do |gemfile| + s = Gem::Format.from_file_by_path(gemfile).spec + next unless Gem::Platform.match(s.platform) + s.source = self + idx << s + end + end end def fetch_remote_specs(index) |