Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Cleanup gems after the fetching phase of bundling
Browse files Browse the repository at this point in the history
  • Loading branch information
Carl Lerche committed Aug 17, 2009
1 parent 8b71327 commit ef361ad
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 12 deletions.
12 changes: 9 additions & 3 deletions lib/bundler/manifest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def initialize(sources, dependencies, bindir, path, rubygems, system_gems)
def install(update)
fetch(update)
repository.install_cached_gems(:bin_dir => @bindir || repository.path.join("bin"))
# Cleanup incase fetch was a no-op
repository.cleanup(gems)
create_environment_files(repository.path.join("environments"))
Bundler.logger.info "Done."
Expand All @@ -34,9 +35,9 @@ def require_all
end

def gems_for(environment = nil)
deps = dependencies
deps = deps.select { |d| d.in?(environment) } if environment
deps = deps.map { |d| d.to_gem_dependency }
deps = dependencies
deps = deps.select { |d| d.in?(environment) } if environment
deps = deps.map { |d| d.to_gem_dependency }
Resolver.resolve(deps, repository.source_index)
end
alias gems gems_for
Expand Down Expand Up @@ -64,6 +65,11 @@ def fetch(update)
raise VersionConflict, "No compatible versions could be found for:\n#{gems}"
end

# Cleanup here to remove any gems that could cause problem in the expansion
# phase
#
# TODO: Try to avoid double cleanup
repository.cleanup(bundle)
bundle.download(repository)
end

Expand Down
13 changes: 8 additions & 5 deletions spec/bundler/installer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
end

def setup
@gems = %w(actionmailer-2.3.2 actionpack-2.3.2 activerecord-2.3.2
activeresource-2.3.2 activesupport-2.3.2 rails-2.3.2
rake-0.8.7)
@manifest = build_manifest <<-Gemfile
clear_sources
source "file://#{gem_repo1}"
Expand All @@ -22,21 +25,21 @@ def setup
it "creates the bundle directory if it does not exist" do
setup
@manifest.install
tmp_file("vendor", "gems").should have_cached_gems("rails-2.3.2")
tmp_file("vendor", "gems").should have_cached_gems(*@gems)
end

it "uses the bundle directory if it is empty" do
tmp_file("vendor", "gems").mkdir_p
setup
@manifest.install
tmp_file("vendor", "gems").should have_cached_gems("rails-2.3.2")
tmp_file("vendor", "gems").should have_cached_gems(*@gems)
end

it "uses the bundle directory if it is a valid gem repo" do
%w(cache doc gems environments specifications).each { |dir| tmp_file("vendor", "gems", dir).mkdir_p }
setup
@manifest.install
tmp_file("vendor", "gems").should have_cached_gems("rails-2.3.2")
tmp_file("vendor", "gems").should have_cached_gems(*@gems)
end

it "does not use the bundle directory if it is not a valid gem repo" do
Expand Down Expand Up @@ -114,8 +117,8 @@ def setup
gem "webrat", "0.4.4.racktest"
Gemfile
m.install
tmp_file("vendor", "gems").should have_cached_gem("webrat-0.4.4.racktest")
tmp_file("vendor", "gems").should have_installed_gem("webrat-0.4.4.racktest")
tmp_file("vendor", "gems").should have_cached_gem("webrat-0.4.4.racktest", "nokogiri-1.3.2")
tmp_file("vendor", "gems").should have_installed_gem("webrat-0.4.4.racktest", "nokogiri-1.3.2")
end

it "outputs a logger message for each gem that is installed" do
Expand Down
8 changes: 4 additions & 4 deletions spec/bundler/manifest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ def dep(name, version, options = {})

it "removes gems that are not needed anymore" do
@manifest.install
tmp_gem_path.should have_cached_gem("rack-0.9.1")
tmp_gem_path.should have_installed_gem("rack-0.9.1")
tmp_gem_path.should include_cached_gem("rack-0.9.1")
tmp_gem_path.should include_installed_gem("rack-0.9.1")
tmp_bindir("rackup").should exist

m = build_manifest <<-Gemfile
Expand All @@ -93,8 +93,8 @@ def dep(name, version, options = {})

m.install

tmp_gem_path.should_not have_cached_gem("rack-0.9.1")
tmp_gem_path.should_not have_installed_gem("rack-0.9.1")
tmp_gem_path.should_not include_cached_gem("rack-0.9.1")
tmp_gem_path.should_not include_installed_gem("rack-0.9.1")
tmp_bindir("rackup").should_not exist
@log_output.should have_log_message("Deleting gem: rack-0.9.1")
@log_output.should have_log_message("Deleting bin file: rackup")
Expand Down
28 changes: 28 additions & 0 deletions spec/matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,34 @@ def have_load_paths(root, gem_load_paths)
end
end

def include_cached_gems(*gems)
simple_matcher("include cached gems") do |given, matcher|
matcher.negative_failure_message = "Gems #{gems.join(", ")} were all cached"
gems.all? do |name|
matcher.failure_message = "Gem #{name} was not cached"
File.exists?(File.join(given, "cache", "#{name}.gem"))
end
end
end

alias include_cached_gem include_cached_gems

def include_installed_gems(*gems)
simple_matcher("include installed gems") do |given, matcher|
matcher.negative_failure_message = "Gems #{gems.join(", ")} were all installed"
gems.all? do |name|
matcher.failure_message = "Gem #{name} was not installed"
File.exists?(File.join(given, "specifications", "#{name}.gemspec")) &&
File.directory?(File.join(given, "gems", "#{name}"))
end
end
end

alias include_installed_gem include_installed_gems

def have_cached_gems(*gems)
simple_matcher("have cached gems") do |given, matcher|
Dir[File.join(given, "cache", "*.gem")].length == gems.length &&
gems.all? do |name|
matcher.failure_message = "Gem #{name} was not cached"
File.exists?(File.join(given, "cache", "#{name}.gem"))
Expand All @@ -64,6 +90,8 @@ def have_cached_gems(*gems)

def have_installed_gems(*gems)
simple_matcher("have installed gems") do |given, matcher|
Dir[File.join(given, "specifications", "*.gemspec")].length == gems.length &&
Dir[File.join(given, "gems", "*")].length == gems.length &&
gems.all? do |name|
matcher.failure_message = "Gem #{name} was not installed"
File.exists?(File.join(given, "specifications", "#{name}.gemspec")) &&
Expand Down

0 comments on commit ef361ad

Please sign in to comment.