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

bundle clean native extensions for gems with a git source #7058

Closed
dylanahsmith opened this issue Mar 21, 2019 · 1 comment · Fixed by #7059
Closed

bundle clean native extensions for gems with a git source #7058

dylanahsmith opened this issue Mar 21, 2019 · 1 comment · Fixed by #7059

Comments

@dylanahsmith
Copy link
Contributor

The bug fix for #5596 didn't clean extensions for gems with a git source, which ironically was my original use case for opening that issue

Note that my actual use case was that I want to uninstall a gem installed through bundler from a git source, where gem uninstall can't be used.

The remaining issue can be reproduced as follows.

Create this Gemfile

gem 'cityhash', git: 'https://github.com/nashby/cityhash.git', ref: 'v0.9.0'

then install and uninstall the gem using bundler

$ bundle install --path .bundle
...
Using bundler 1.17.3
Using cityhash 0.9.0 from https://github.com/nashby/cityhash.git (at v0.9.0@f2a15ac)
...
$ find .bundle -name '*.bundle'
.bundle
.bundle/ruby/2.5.0/bundler/gems/cityhash-f2a15ac7cc71/ext/cityhash/cityhash.bundle
.bundle/ruby/2.5.0/bundler/gems/cityhash-f2a15ac7cc71/lib/cityhash/cityhash.bundle
.bundle/ruby/2.5.0/bundler/gems/extensions/x86_64-darwin-18/2.5.0-static/cityhash-f2a15ac7cc71/cityhash/cityhash.bundle
$ touch empty_gemfile
$ BUNDLE_GEMFILE=empty_gemfile bundle clean --force
Resolving dependencies...
Removing cityhash (f2a15ac7cc71)
$ find .bundle -type f
.bundle/config
.bundle/ruby/2.5.0/bundler/gems/extensions/x86_64-darwin-18/2.5.0-static/cityhash-f2a15ac7cc71/gem_make.out
.bundle/ruby/2.5.0/bundler/gems/extensions/x86_64-darwin-18/2.5.0-static/cityhash-f2a15ac7cc71/gem.build_complete
.bundle/ruby/2.5.0/bundler/gems/extensions/x86_64-darwin-18/2.5.0-static/cityhash-f2a15ac7cc71/cityhash/cityhash.bundle

so the extension wasn't completely cleaned. The presence of the gem.build_complete will prevent the extension from being rebuilt.

I was also able to reproduce this issue on master.

@dylanahsmith
Copy link
Contributor Author

I think the fix for this is

diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb
index 762e7b3ec..83945868f 100644
--- a/lib/bundler/runtime.rb
+++ b/lib/bundler/runtime.rb
@@ -163,7 +163,7 @@ module Bundler
       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/*/*/*"]
+      extension_dirs       = Dir["#{Gem.dir}/extensions/*/*/*"] + Dir["#{Gem.dir}/bundler/gems/extensions/*/*/*"]
       spec_gem_paths       = []
       # need to keep git sources around
       spec_git_paths       = @definition.spec_git_paths

ghost pushed a commit that referenced this issue Mar 27, 2019
7059: Make `bundle clean` clean git extension directories r=hsbt a=dylanahsmith

Fixes #7058

This PR fixes it by adding the native extension directories for git gems to the ones for non-git gems.  This is used to get the unused extension directories (`stale_extension_dirs = extension_dirs - spec_extension_paths`) which was already excluding extension directories for git gems.

Co-authored-by: Dylan Thacker-Smith <dylan.smith@shopify.com>
@ghost ghost closed this as completed in #7059 Mar 27, 2019
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant