Skip to content

Commit f665087

Browse files
committed
Support ABI-scoped specification dirs in bundle clean
Assisted-By: devx/9c2464e2-74cd-4d36-a6c0-50aef8c2ad01
1 parent 69c8f65 commit f665087

2 files changed

Lines changed: 55 additions & 1 deletion

File tree

lib/bundler/runtime.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,9 @@ def clean(dry_run = false)
166166
git_cache_dirs = SharedHelpers.glob_files_in_dir("cache/bundler/git/*", Gem.dir)
167167
gem_dirs = SharedHelpers.glob_files_in_dir("gems/*", Gem.dir)
168168
gem_files = SharedHelpers.glob_files_in_dir("cache/*.gem", Gem.dir)
169-
gemspec_files = SharedHelpers.glob_files_in_dir("specifications/*.gemspec", Gem.dir)
169+
gemspec_files = Gem::SpecificationRecord.dirs_from([Gem.dir]).flat_map do |dir|
170+
SharedHelpers.glob_files_in_dir("*.gemspec", dir)
171+
end
170172
extension_dirs = SharedHelpers.glob_files_in_dir("extensions/*/*/*", Gem.dir) + SharedHelpers.glob_files_in_dir("bundler/gems/extensions/*/*/*", Gem.dir)
171173
spec_gem_paths = []
172174
# need to keep git sources around

spec/commands/clean_spec.rb

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,58 @@ def should_not_have_gems(*gems)
391391
expect(vendored_gems("bin/myrackup")).not_to exist
392392
end
393393

394+
it "removes orphaned gemspecs from ABI-scoped specification dirs", rubygems: ">= 4.1.0.dev" do
395+
gemfile <<-G
396+
source "https://gem.repo1"
397+
398+
gem "foo"
399+
G
400+
401+
bundle_config "path vendor/bundle"
402+
bundle "install"
403+
404+
abi_dir = vendored_gems("specifications/#{Gem.ruby_abi}")
405+
FileUtils.mkdir_p(abi_dir)
406+
orphaned_gemspec = File.join(abi_dir, "orphaned-1.0-deadbeef.gemspec")
407+
File.write(orphaned_gemspec, "orphaned")
408+
409+
bundle :clean
410+
411+
expect(File.exist?(orphaned_gemspec)).to be false
412+
should_have_gems "foo-1.0"
413+
end
414+
415+
it "does not remove gemspecs for content-addressed gems in the bundle", :compact_index, rubygems: ">= 4.1.0.dev" do
416+
skip "Gem::ContentAddress not available" if ruby_core?
417+
418+
simulate_platform "x86_64-linux" do
419+
build_repo2 do
420+
build_gem "mygem", "1.0" do |s|
421+
s.platform = Gem::Platform.new("x86_64-linux")
422+
s.write "lib/mygem.rb", "MYGEM = '1.0 not_content_addressed'"
423+
end
424+
end
425+
426+
build_gem "mygem", "1.0", ruby_abi: Gem.ruby_abi, path: gem_repo2("gems") do |s|
427+
s.platform = Gem::Platform.new("x86_64-linux")
428+
s.required_ruby_version = "~> #{Gem.ruby_abi}.0"
429+
s.write "lib/mygem.rb", "MYGEM = '1.0 content_addressed'"
430+
end
431+
432+
bundle_config "path vendor/bundle"
433+
install_gemfile <<~G, artifice: "compact_index_v2", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo2.to_s }
434+
source "https://gem.repo2"
435+
436+
gem "mygem"
437+
G
438+
439+
bundle :clean
440+
441+
abi_gemspecs = Dir.glob(vendored_gems("specifications/#{Gem.ruby_abi}/*.gemspec").to_s)
442+
expect(abi_gemspecs.size).to eq(1), "expected content-addressed gemspec to be preserved, found: #{abi_gemspecs}"
443+
end
444+
end
445+
394446
it "does not call clean automatically when using system gems" do
395447
bundle_config "path.system true"
396448

0 commit comments

Comments
 (0)