diff options
author | Carl Lerche <carllerche@mac.com> | 2010-06-23 13:54:42 -0700 |
---|---|---|
committer | Carl Lerche <carllerche@mac.com> | 2010-06-23 13:54:42 -0700 |
commit | 2eeff95e617c0bde57fab2eedfbef970b29ec9f9 (patch) | |
tree | 423e6f554dad8706f3a8051f500bdb9a482722ee | |
parent | 1e1bf7ce98b24e24ee05313c31fd38370bc3b9f7 (diff) | |
download | bundler-2eeff95e617c0bde57fab2eedfbef970b29ec9f9.tar.gz |
Add bundle install --local to enable installing from vendor/cache
-rw-r--r-- | lib/bundler/cli.rb | 2 | ||||
-rw-r--r-- | lib/bundler/definition.rb | 6 | ||||
-rw-r--r-- | lib/bundler/installer.rb | 4 | ||||
-rw-r--r-- | lib/bundler/source.rb | 19 | ||||
-rw-r--r-- | spec/cache/gems_spec.rb | 15 | ||||
-rw-r--r-- | spec/install/gems/packed_spec.rb | 3 | ||||
-rw-r--r-- | spec/spec_helper.rb | 4 |
7 files changed, 34 insertions, 19 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index e05411d501..b48da72b2e 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -91,6 +91,8 @@ module Bundler "Don't update the existing gem cache." method_option "quiet", :type => :boolean, :banner => "Only output warnings and errors." + method_option "local", :type => :boolean, :banner => + "Do not attempt to fetch gems remotely and use the gem cache instead" def install(path = nil) opts = options.dup opts[:without] ||= [] diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index eb2c59e4bc..e2ba51cf52 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -56,6 +56,12 @@ module Bundler converge end + def resolve_with_cache! + raise "Specs already loaded" if @specs + @sources.each { |s| s.cached! } + specs + end + def resolve_remotely! raise "Specs already loaded" if @specs @remote = true diff --git a/lib/bundler/installer.rb b/lib/bundler/installer.rb index 4a18b2ccaa..cc35d4d972 100644 --- a/lib/bundler/installer.rb +++ b/lib/bundler/installer.rb @@ -16,7 +16,9 @@ module Bundler # Since we are installing, we can resolve the definition # using remote specs - @definition.resolve_remotely! + options["local"] ? + @definition.resolve_with_cache! : + @definition.resolve_remotely! # Ensure that BUNDLE_PATH exists FileUtils.mkdir_p(Bundler.bundle_path) diff --git a/lib/bundler/source.rb b/lib/bundler/source.rb index 2daee135d6..ca2b19ef1e 100644 --- a/lib/bundler/source.rb +++ b/lib/bundler/source.rb @@ -15,6 +15,7 @@ module Bundler @options = options @remotes = (options["remotes"] || []).map { |r| normalize_uri(r) } @allow_remote = false + @allow_cached = false # Hardcode the paths for now @caches = [ Bundler.app_cache ] + Gem.path.map { |p| File.expand_path("#{p}/cache") } @spec_fetch_map = {} @@ -24,6 +25,10 @@ module Bundler @allow_remote = true end + def cached! + @allow_cached = true + end + def hash Rubygems.hash end @@ -62,7 +67,7 @@ module Bundler end def specs - @specs ||= @allow_remote ? fetch_specs : installed_specs + @specs ||= fetch_specs end def fetch(spec) @@ -133,8 +138,8 @@ module Bundler def fetch_specs Index.build do |idx| idx.use installed_specs - # idx.use cached_specs - idx.use remote_specs + idx.use cached_specs if @allow_cached + idx.use remote_specs if @allow_remote end end @@ -249,6 +254,7 @@ module Bundler @options = options @glob = options["glob"] || DEFAULT_GLOB + @allow_cached = false @allow_remote = false if options["path"] @@ -263,6 +269,10 @@ module Bundler @allow_remote = true end + def cached! + @allow_cached = true + end + def self.from_lock(options) new(options.merge("path" => options.delete("remote"))) end @@ -484,8 +494,9 @@ module Bundler @revision = nil end + # TODO: actually cache git specs def specs - if @allow_remote && !@update + if (@allow_remote || @allow_cached) && !@update # Start by making sure the git cache is up to date cache checkout diff --git a/spec/cache/gems_spec.rb b/spec/cache/gems_spec.rb index 3d8b14b17a..3a9bb773db 100644 --- a/spec/cache/gems_spec.rb +++ b/spec/cache/gems_spec.rb @@ -17,9 +17,8 @@ describe "bundle cache" do end it "uses the cache as a source when installing gems" do - pending_cache_fixes system_gems [] - bundle :install + bundle "install --local" should_be_installed("rack 1.0.0") end @@ -37,9 +36,9 @@ describe "bundle cache" do end it "does not reinstall gems from the cache if they exist in the bundle" do - pending_cache_fixes - system_gems [] - install_gemfile <<-G + system_gems "rack-1.0.0" + + gemfile <<-G gem "rack" G @@ -47,18 +46,18 @@ describe "bundle cache" do s.write "lib/rack.rb", "RACK = 'FAIL'" end - bundle :install + bundle "install --local" should_be_installed("rack 1.0.0") end end describe "when there are also git sources" do it "still works" do - pending_cache_fixes build_git "foo" system_gems "rack-1.0.0" install_gemfile <<-G + source "file://#{gem_repo1}" git "#{lib_path("foo-1.0")}" gem 'rack' gem 'foo' @@ -67,7 +66,7 @@ describe "bundle cache" do bundle :cache system_gems [] - bundle :install + bundle "install --local" should_be_installed("rack 1.0.0", "foo 1.0") end diff --git a/spec/install/gems/packed_spec.rb b/spec/install/gems/packed_spec.rb index e0d2011989..92633150ec 100644 --- a/spec/install/gems/packed_spec.rb +++ b/spec/install/gems/packed_spec.rb @@ -3,7 +3,6 @@ require "spec_helper" describe "bundle install with gem sources" do describe "when cached and locked" do it "does not hit the remote at all" do - pending_cache_fixes build_repo2 install_gemfile <<-G source "file://#{gem_repo2}" @@ -14,7 +13,7 @@ describe "bundle install with gem sources" do simulate_new_machine FileUtils.rm_rf gem_repo2 - bundle :install + bundle "install --local" should_be_installed "rack 1.0.0" end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f023a5f9f2..95234d88bc 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -48,10 +48,6 @@ Spec::Runner.configure do |config| # e.g. check foo.should == bar end - def pending_cache_fixes - pending "pending fixing the cache stuff" - end - config.before :all do build_repo1 end |