diff options
author | Andre Arko <andre@arko.net> | 2010-04-20 11:57:52 -0700 |
---|---|---|
committer | Andre Arko <andre@arko.net> | 2010-04-20 11:57:52 -0700 |
commit | 1d5b0696cf0f0b2d53e96143ff6d2e8c1a128313 (patch) | |
tree | 5e6275c894f3f4c82fbcd67886c0cece52f5d871 | |
parent | 20d36fd9a575a88f3b13f8ac6f3fd2bcf9482ea6 (diff) | |
download | bundler-1d5b0696cf0f0b2d53e96143ff6d2e8c1a128313.tar.gz |
Cache command now prunes stale .gem files from vendor/cache
If you don't want to prune, pass --no-prune to either cache or pack
-rw-r--r-- | lib/bundler/cli.rb | 3 | ||||
-rw-r--r-- | lib/bundler/runtime.rb | 15 | ||||
-rw-r--r-- | spec/cache/gems_spec.rb | 50 | ||||
-rw-r--r-- | spec/install/gems/packed_spec.rb | 24 | ||||
-rw-r--r-- | spec/support/path.rb | 4 |
5 files changed, 72 insertions, 24 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index 89c28ea4ba..decab015e7 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -143,8 +143,10 @@ module Bundler map %w(list) => "show" desc "cache", "Cache all the gems to vendor/cache" + method_option "no-prune", :type => :boolean, :banner => "Don't remove stale gems from the cache." def cache Bundler.runtime.cache + Bundler.runtime.prune_cache unless options[:no_prune] rescue GemNotFound => e Bundler.ui.error(e.message) Bundler.ui.warn "Run `bundle install` to install missing gems." @@ -152,6 +154,7 @@ module Bundler end desc "package", "Locks and then caches all of the gems into vendor/cache" + method_option "no-prune", :type => :boolean, :banner => "Don't remove stale gems from the cache." def package lock cache diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb index bbb4e81316..6284aad04c 100644 --- a/lib/bundler/runtime.rb +++ b/lib/bundler/runtime.rb @@ -79,7 +79,6 @@ module Bundler alias gems specs def cache - cache_path = "#{root}/vendor/cache/" FileUtils.mkdir_p(cache_path) Bundler.ui.info "Copying .gem files into vendor/cache" @@ -94,12 +93,26 @@ module Bundler end end + def prune_cache + FileUtils.mkdir_p(cache_path) + + Bundler.ui.info "Removing outdated .gem files from vendor/cache" + cache_path.children.each do |gemfile| + spec = Gem::Format.from_file_by_path(gemfile).spec + gemfile.rmtree unless specs.include?(spec) + end + end + private def load_paths specs.map { |s| s.load_paths }.flatten end + def cache_path + root.join("vendor/cache") + end + def write_yml_lock yml = details.to_yaml File.open("#{root}/Gemfile.lock", 'w') do |f| diff --git a/spec/cache/gems_spec.rb b/spec/cache/gems_spec.rb index ee62200c03..8b1a006e9b 100644 --- a/spec/cache/gems_spec.rb +++ b/spec/cache/gems_spec.rb @@ -1,6 +1,7 @@ require File.expand_path('../../spec_helper', __FILE__) -describe "bundle cache with gems" do +describe "bundle cache" do + describe "when there are only gemsources" do before :each do gemfile <<-G @@ -69,4 +70,51 @@ describe "bundle cache with gems" do end end + describe "when previously cached" do + before :each do + build_repo2 + install_gemfile <<-G + source "file://#{gem_repo2}" + gem "rack" + gem "actionpack" + G + bundle :cache + cached_gem("rack-1.0.0").should exist + cached_gem("actionpack-2.3.2").should exist + cached_gem("activesupport-2.3.2").should exist + end + + it "re-caches during install" do + cached_gem("rack-1.0.0").rmtree + bundle :install + out.should include("Copying .gem files into vendor/cache") + cached_gem("rack-1.0.0").should exist + end + + it "adds updated gems" do + update_repo2 + bundle :install + cached_gem("rack-1.2").should exist + end + + it "adds new gems and dependencies" do + install_gemfile <<-G + source "file://#{gem_repo2}" + gem "rails" + G + cached_gem("rails-2.3.2").should exist + cached_gem("activerecord-2.3.2").should exist + end + + it "removes .gems for removed gems and dependencies" do + install_gemfile <<-G + source "file://#{gem_repo2}" + gem "rack" + G + cached_gem("rack-1.0.0").should exist + cached_gem("actionpack-2.3.2").should_not exist + cached_gem("activesupport-2.3.2").should_not exist + end + end + end
\ No newline at end of file diff --git a/spec/install/gems/packed_spec.rb b/spec/install/gems/packed_spec.rb index 3c73ebbda9..2b5e3ef34a 100644 --- a/spec/install/gems/packed_spec.rb +++ b/spec/install/gems/packed_spec.rb @@ -32,43 +32,23 @@ describe "bundle install with gem sources" do err.should be_empty should_be_installed "rack 1.0" end - end - describe "when cached" do it "ignores cached gems for the wrong platform" do install_gemfile <<-G Gem.platforms = [#{java}] source "file://#{gem_repo1}" gem "platform_specific" G - bundle :cache + bundle :pack simulate_new_machine - install_gemfile <<-G + install_gemfile <<-G, :relock => true Gem.platforms = [#{rb}] source "file://#{gem_repo1}" gem "platform_specific" G - bundle :install run "require 'platform_specific' ; puts PLATFORM_SPECIFIC" out.should == "1.0.0 RUBY" end - - it "updates the cache during later installs" do - cached_gem = bundled_app("vendor/cache/rack-1.0.0.gem") - install_gemfile <<-G - source "file://#{gem_repo1}" - gem "rack" - G - - bundle :cache - cached_gem.should exist - - FileUtils.rm_rf(cached_gem) - - bundle :install - out.should include("Copying .gem files into vendor/cache") - cached_gem.should exist - end end end
\ No newline at end of file diff --git a/spec/support/path.rb b/spec/support/path.rb index efc48738d1..05a8c5c925 100644 --- a/spec/support/path.rb +++ b/spec/support/path.rb @@ -30,6 +30,10 @@ module Spec root.join(*path) end + def cached_gem(path) + bundled_app("vendor/cache/#{path}.gem") + end + def base_system_gems tmp.join("gems/base") end |