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

Commit

Permalink
Auto merge of #6168 - akhramov:fix/clean-extensions, r=colby-swandale
Browse files Browse the repository at this point in the history
Make `bundle clean` clean extension directories

### What was the end-user problem that led to this PR?

The problem was that `bundle clean` command doesn't remove gem extensions (#5596)

### What was your diagnosis of the problem?

I've looked into `Bundler::Runtime#clean` and realized that extension dirs are not removed

### What is your fix for the problem, implemented in this PR?

My fix is to tweak `Bundler::Runtime#clean` to remove extensions dirs
as well.

### Why did you choose this fix out of the possible options?

I chose this fix because I didn't see any other option.
  • Loading branch information
bundlerbot committed Jan 10, 2018
2 parents f1990c0 + f631eca commit 2649066
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/bundler/runtime.rb
Expand Up @@ -163,13 +163,15 @@ def clean(dry_run = false)
gem_dirs = Dir["#{Gem.dir}/gems/*"]
gem_files = Dir["#{Gem.dir}/cache/*.gem"]
gemspec_files = Dir["#{Gem.dir}/specifications/*.gemspec"]
extension_dirs = Dir["#{Gem.dir}/extensions/*/*/*"]
spec_gem_paths = []
# need to keep git sources around
spec_git_paths = @definition.spec_git_paths
spec_git_cache_dirs = []
spec_gem_executables = []
spec_cache_paths = []
spec_gemspec_paths = []
spec_extension_paths = []
specs.each do |spec|
spec_gem_paths << spec.full_gem_path
# need to check here in case gems are nested like for the rails git repo
Expand All @@ -181,6 +183,7 @@ def clean(dry_run = false)
end
spec_cache_paths << spec.cache_file
spec_gemspec_paths << spec.spec_file
spec_extension_paths << spec.extension_dir if spec.respond_to?(:extension_dir)
spec_git_cache_dirs << spec.source.cache_path.to_s if spec.source.is_a?(Bundler::Source::Git)
end
spec_gem_paths.uniq!
Expand All @@ -192,6 +195,7 @@ def clean(dry_run = false)
stale_gem_dirs = gem_dirs - spec_gem_paths
stale_gem_files = gem_files - spec_cache_paths
stale_gemspec_files = gemspec_files - spec_gemspec_paths
stale_extension_dirs = extension_dirs - spec_extension_paths

removed_stale_gem_dirs = stale_gem_dirs.collect {|dir| remove_dir(dir, dry_run) }
removed_stale_git_dirs = stale_git_dirs.collect {|dir| remove_dir(dir, dry_run) }
Expand All @@ -204,8 +208,10 @@ def clean(dry_run = false)
FileUtils.rm(file) if File.exist?(file)
end
end
stale_git_cache_dirs.each do |cache_dir|
SharedHelpers.filesystem_access(cache_dir) do |dir|

stale_dirs = stale_git_cache_dirs + stale_extension_dirs
stale_dirs.each do |stale_dir|
SharedHelpers.filesystem_access(stale_dir) do |dir|
FileUtils.rm_rf(dir) if File.exist?(dir)
end
end
Expand Down
35 changes: 35 additions & 0 deletions spec/commands/clean_spec.rb
Expand Up @@ -733,4 +733,39 @@ def should_not_have_gems(*gems)
expect(vendored_gems("bundler/gems/extensions")).to exist
expect(vendored_gems("bundler/gems/very_simple_git_binary-1.0-#{revision[0..11]}")).to exist
end

it "removes extension directories", :rubygems => "2.2" do
gemfile <<-G
source "file://#{gem_repo1}"
gem "thin"
gem "very_simple_binary"
gem "simple_binary"
G

bundle! "install", forgotten_command_line_options(:path => "vendor/bundle")

very_simple_binary_extensions_dir =
Pathname.glob("#{vendored_gems}/extensions/*/*/very_simple_binary-1.0").first

simple_binary_extensions_dir =
Pathname.glob("#{vendored_gems}/extensions/*/*/simple_binary-1.0").first

expect(very_simple_binary_extensions_dir).to exist
expect(simple_binary_extensions_dir).to exist

gemfile <<-G
source "file://#{gem_repo1}"
gem "thin"
gem "simple_binary"
G

bundle! "install"
bundle! :clean
expect(out).to eq("Removing very_simple_binary (1.0)")

expect(very_simple_binary_extensions_dir).not_to exist
expect(simple_binary_extensions_dir).to exist
end
end
1 change: 1 addition & 0 deletions spec/support/builders.rb
Expand Up @@ -182,6 +182,7 @@ def build_repo1
end

build_gem "very_simple_binary", &:add_c_extension
build_gem "simple_binary", &:add_c_extension

build_gem "bundler", "0.9" do |s|
s.executables = "bundle"
Expand Down

0 comments on commit 2649066

Please sign in to comment.