summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Lerche <carllerche@mac.com>2010-07-14 12:48:07 -0700
committerCarl Lerche <carllerche@mac.com>2010-07-14 12:48:30 -0700
commit5665eef2785fe4344e4a7818b2a332f530dd66ce (patch)
treea0dbc89b335a7679b0b863bc5a89e966671ca7e4
parent499bb4360dd342b6d9a46e6b57cc73190857f18d (diff)
downloadbundler-5665eef2785fe4344e4a7818b2a332f530dd66ce.tar.gz
Don't delete cached gems for dependencies that are pinned to certain platforms
-rw-r--r--lib/bundler/runtime.rb7
-rw-r--r--spec/cache/platform_spec.rb41
-rw-r--r--spec/support/helpers.rb13
3 files changed, 58 insertions, 3 deletions
diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb
index 99f72bc7d2..efcee1c5b6 100644
--- a/lib/bundler/runtime.rb
+++ b/lib/bundler/runtime.rb
@@ -85,11 +85,12 @@ module Bundler
def prune_cache
FileUtils.mkdir_p(cache_path)
+ resolve = @definition.resolve
+
Bundler.ui.info "Removing outdated .gem files from vendor/cache"
Pathname.glob(cache_path.join("*.gem").to_s).each do |gem_path|
- cached_spec = Gem::Format.from_file_by_path(gem_path).spec
- next unless Gem::Platform.match(cached_spec.platform)
- unless specs.any?{|s| s.full_name == cached_spec.full_name }
+ cached = Gem::Format.from_file_by_path(gem_path).spec
+ unless resolve.any?{|s| s.name == cached.name && s.version == cached.version }
Bundler.ui.info " * #{File.basename(gem_path)}"
gem_path.rmtree
end
diff --git a/spec/cache/platform_spec.rb b/spec/cache/platform_spec.rb
new file mode 100644
index 0000000000..d665c92070
--- /dev/null
+++ b/spec/cache/platform_spec.rb
@@ -0,0 +1,41 @@
+require "spec_helper"
+
+describe "bundle cache with multiple platforms" do
+ before :each do
+ gemfile <<-G
+ source "file://#{gem_repo1}"
+
+ platforms :ruby do
+ gem "rack", "1.0.0"
+ end
+
+ platforms :jruby do
+ gem "activesupport", "2.3.5"
+ end
+ G
+
+ lockfile <<-G
+ GEM
+ remote: file:#{gem_repo1}/
+ specs:
+ rack (1.0.0)
+ activesupport (2.3.5)
+
+ PLATFORMS
+ ruby
+ java
+
+ DEPENDENCIES
+ rack (1.0.0)
+ activesupport (2.3.5)
+ G
+ end
+
+ it "does not delete gems for other platforms" do
+ cache_gems "rack-1.0.0", "activesupport-2.3.5"
+ bundle "install"
+
+ bundled_app("vendor/cache/rack-1.0.0.gem").should exist
+ bundled_app("vendor/cache/activesupport-2.3.5.gem").should exist
+ end
+end
diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb
index 57b62710bc..ab60a6381f 100644
--- a/spec/support/helpers.rb
+++ b/spec/support/helpers.rb
@@ -179,6 +179,19 @@ module Spec
end
end
+ def cache_gems(*gems)
+ gems = gems.flatten
+
+ FileUtils.rm_rf("#{bundled_app}/vendor/cache")
+ FileUtils.mkdir_p("#{bundled_app}/vendor/cache")
+
+ gems.each do |g|
+ path = "#{gem_repo1}/gems/#{g}.gem"
+ raise "OMG `#{path}` does not exist!" unless File.exist?(path)
+ FileUtils.cp(path, "#{bundled_app}/vendor/cache")
+ end
+ end
+
def simulate_new_machine
system_gems []
FileUtils.rm_rf default_bundle_path