bundler 4.1.0.beta3 → 4.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/bundler.gemspec +5 -3
  3. data/lib/bundler/build_metadata.rb +2 -2
  4. data/lib/bundler/checksum.rb +17 -2
  5. data/lib/bundler/cli/clean.rb +19 -3
  6. data/lib/bundler/cli/exec.rb +1 -1
  7. data/lib/bundler/cli/install.rb +1 -1
  8. data/lib/bundler/cli/lock.rb +12 -0
  9. data/lib/bundler/cli/outdated.rb +1 -4
  10. data/lib/bundler/cli/update.rb +1 -1
  11. data/lib/bundler/cli.rb +2 -0
  12. data/lib/bundler/definition.rb +152 -7
  13. data/lib/bundler/dependency.rb +17 -2
  14. data/lib/bundler/dsl.rb +9 -2
  15. data/lib/bundler/errors.rb +8 -0
  16. data/lib/bundler/fetcher/downloader.rb +7 -3
  17. data/lib/bundler/index.rb +7 -2
  18. data/lib/bundler/injector.rb +1 -1
  19. data/lib/bundler/inline.rb +19 -9
  20. data/lib/bundler/installer.rb +19 -0
  21. data/lib/bundler/lazy_specification.rb +46 -25
  22. data/lib/bundler/lockfile_generator.rb +21 -9
  23. data/lib/bundler/lockfile_parser.rb +21 -5
  24. data/lib/bundler/man/bundle-lock.1 +8 -2
  25. data/lib/bundler/man/bundle-lock.1.ronn +15 -1
  26. data/lib/bundler/man/bundle-plugin.1 +61 -0
  27. data/lib/bundler/man/bundle-plugin.1.ronn +84 -0
  28. data/lib/bundler/man/gemfile.5 +3 -1
  29. data/lib/bundler/man/gemfile.5.ronn +11 -3
  30. data/lib/bundler/match_platform.rb +3 -3
  31. data/lib/bundler/match_remote_metadata.rb +6 -0
  32. data/lib/bundler/mirror.rb +7 -5
  33. data/lib/bundler/plugin/index.rb +14 -11
  34. data/lib/bundler/remote_specification.rb +5 -0
  35. data/lib/bundler/resolver/candidate.rb +5 -0
  36. data/lib/bundler/resolver.rb +89 -7
  37. data/lib/bundler/ruby_dsl.rb +2 -1
  38. data/lib/bundler/rubygems_ext.rb +54 -9
  39. data/lib/bundler/rubygems_integration.rb +2 -4
  40. data/lib/bundler/runtime.rb +29 -11
  41. data/lib/bundler/settings.rb +2 -3
  42. data/lib/bundler/source/git/git_proxy.rb +18 -6
  43. data/lib/bundler/source/git.rb +0 -2
  44. data/lib/bundler/spec_set.rb +54 -14
  45. data/lib/bundler/stub_specification.rb +4 -0
  46. data/lib/bundler/vendored_securerandom.rb +5 -2
  47. data/lib/bundler/vendored_uri.rb +18 -3
  48. data/lib/bundler/version.rb +1 -1
  49. data/lib/bundler/worker.rb +4 -0
  50. data/lib/bundler.rb +1 -1
  51. data/lib/rubygems/compact_index_client/http_fetcher.rb +3 -1
  52. data/lib/rubygems/vendor/pub_grub/lib/pub_grub/term.rb +1 -1
  53. data/lib/rubygems/yaml_serializer/builder.rb +261 -0
  54. data/lib/rubygems/yaml_serializer/core.rb +41 -0
  55. data/lib/rubygems/yaml_serializer/emitter.rb +197 -0
  56. data/lib/rubygems/yaml_serializer/nodes.rb +10 -0
  57. data/lib/rubygems/yaml_serializer/parser.rb +531 -0
  58. data/lib/rubygems/yaml_serializer/psych_errors.rb +11 -0
  59. metadata +8 -4
  60. data/lib/rubygems/vendor/uri/lib/uri.rb +0 -108
  61. data/lib/rubygems/yaml_serializer.rb +0 -908
@@ -40,5 +40,11 @@ module Bundler
40
40
  include MatchMetadata
41
41
 
42
42
  prepend FetchMetadata
43
+
44
+ # Return the original dependency so the resolver can apply the same override to it.
45
+ def incompatible_metadata_dependency(overrides)
46
+ return Gem::Dependency.new("Ruby\0", @required_ruby_version) unless matches_current_ruby_with_overrides?(overrides)
47
+ Gem::Dependency.new("RubyGems\0", @required_rubygems_version) unless matches_current_rubygems_with_overrides?(overrides)
48
+ end
43
49
  end
44
50
  end
@@ -151,9 +151,11 @@ module Bundler
151
151
  socket.connect_nonblock(address)
152
152
  rescue Errno::EINPROGRESS
153
153
  wait_for_writtable_socket(socket, address, timeout)
154
- rescue RuntimeError # Connection failed somehow, again
154
+ rescue SystemCallError # Connection failed somehow, again
155
155
  false
156
156
  end
157
+ rescue SocketError # The mirror host does not resolve
158
+ false
157
159
  end
158
160
 
159
161
  private
@@ -185,7 +187,7 @@ module Bundler
185
187
  class MirrorSockets
186
188
  def initialize(mirror)
187
189
  @timeout = mirror.fallback_timeout
188
- @addresses = Socket.getaddrinfo(mirror.uri.host, mirror.uri.port).map do |address|
190
+ @addresses = Socket.getaddrinfo(mirror.uri.hostname, mirror.uri.port, nil, Socket::SOCK_STREAM).map do |address|
189
191
  SocketAddress.new(address[0], address[3], address[1])
190
192
  end
191
193
  end
@@ -194,9 +196,9 @@ module Bundler
194
196
  @addresses.any? do |address|
195
197
  socket = Socket.new(Socket.const_get(address.type), Socket::SOCK_STREAM, 0)
196
198
  socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
197
- value = yield socket, address.to_socket_address, @timeout
198
- socket.close unless socket.closed?
199
- value
199
+ yield socket, address.to_socket_address, @timeout
200
+ ensure
201
+ socket&.close
200
202
  end
201
203
  end
202
204
  end
@@ -171,20 +171,25 @@ module Bundler
171
171
 
172
172
  data = index_f.read
173
173
 
174
- require "rubygems/yaml_serializer"
175
- # Empty sections load as nil, e.g. from index files written by
176
- # older Bundler versions, which dumped empty hashes as a bare key.
177
- index = Gem::YAMLSerializer.load(data) || {}
174
+ require_relative "../../rubygems/yaml_serializer/core"
175
+ loaded = Gem::YAMLSerializer.load(data) || {}
176
+ # Empty sections load as nil from index files written by older
177
+ # Bundler versions, which dumped empty hashes as a bare key, and as
178
+ # the string "{}" once a gemrc has made RubyGems < 4.1 load its
179
+ # minimal serializer over the copy shipped with Bundler.
180
+ index = %w[commands hooks load_paths plugin_paths sources].to_h do |key|
181
+ [key, loaded[key].is_a?(Hash) ? loaded[key] : {}]
182
+ end
178
183
 
179
184
  escaping = escaping_plugins(index, base)
180
- hooks = (index["hooks"] || {}).transform_values {|names| Array(names) - escaping }
185
+ hooks = index["hooks"].transform_values {|names| Array(names) - escaping }
181
186
 
182
- @commands.merge!(owned_by(index["commands"] || {}, escaping))
187
+ @commands.merge!(owned_by(index["commands"], escaping))
183
188
  # An event whose plugins all escaped is left out rather than merged in empty.
184
189
  @hooks.merge!(hooks.reject {|_, names| names.empty? })
185
190
  @load_paths.merge!(named(transform_index_paths(index["load_paths"]) {|p| absolutize_path(p, base) }, escaping))
186
191
  @plugin_paths.merge!(named(transform_index_paths(index["plugin_paths"]) {|p| absolutize_path(p, base) }, escaping))
187
- @sources.merge!(owned_by(index["sources"] || {}, escaping)) unless global
192
+ @sources.merge!(owned_by(index["sources"], escaping)) unless global
188
193
  end
189
194
  end
190
195
 
@@ -202,7 +207,7 @@ module Bundler
202
207
  "sources" => @sources,
203
208
  }
204
209
 
205
- require "rubygems/yaml_serializer"
210
+ require_relative "../../rubygems/yaml_serializer/core"
206
211
  SharedHelpers.filesystem_access(index_file) do |index_f|
207
212
  FileUtils.mkdir_p(index_f.dirname)
208
213
  File.open(index_f, "w") {|f| f.puts Gem::YAMLSerializer.dump(index) }
@@ -218,7 +223,7 @@ module Bundler
218
223
  names = []
219
224
 
220
225
  %w[load_paths plugin_paths].each do |key|
221
- (index[key] || {}).each do |name, value|
226
+ index[key].each do |name, value|
222
227
  escapes = Array(value).any? do |path|
223
228
  !Pathname.new(path).absolute? && !contained_in?(absolutize_path(path, base), base)
224
229
  end
@@ -249,8 +254,6 @@ module Bundler
249
254
  end
250
255
 
251
256
  def transform_index_paths(paths)
252
- return {} unless paths
253
-
254
257
  paths.transform_values do |value|
255
258
  if value.is_a?(Array)
256
259
  value.map {|path| yield path }
@@ -25,6 +25,11 @@ module Bundler
25
25
  @content_address = content_address
26
26
  end
27
27
 
28
+ # Whether the full index gemspec is already available without a fetch.
29
+ def gemspec_loaded?
30
+ !@_remote_specification.nil?
31
+ end
32
+
28
33
  def insecurely_materialized?
29
34
  @locked_platform.to_s != @platform.to_s
30
35
  end
@@ -30,6 +30,11 @@ module Bundler
30
30
  @priority = priority
31
31
  end
32
32
 
33
+ # The specifications selected together for this version and its platforms.
34
+ def specs
35
+ @spec_group.specs
36
+ end
37
+
33
38
  def dependencies
34
39
  @spec_group.dependencies
35
40
  end
@@ -28,6 +28,7 @@ module Bundler
28
28
  def start
29
29
  @requirements = @base.requirements
30
30
  @packages = @base.packages
31
+ @incompatible_specs = {}
31
32
 
32
33
  root, logger = setup_solver
33
34
 
@@ -71,6 +72,9 @@ module Bundler
71
72
  @cached_dependencies = Hash.new do |dependencies, package|
72
73
  dependencies[package] = Hash.new do |versions, version|
73
74
  deps = version.dependencies.reject {|d| d.name == package.name }
75
+ if incompatible = @incompatible_specs[package.name]
76
+ deps.concat(version.specs.filter_map {|s| incompatible[s.full_name] })
77
+ end
74
78
  deps = Override.rewrite_dependencies(@base.overrides, package.name, deps)
75
79
  deps = apply_metadata_overrides(deps, package.name)
76
80
  versions[version] = to_dependency_hash(deps, @packages)
@@ -86,8 +90,23 @@ module Bundler
86
90
  end
87
91
 
88
92
  def solve_versions(root:, logger:)
89
- solver = Gem::PubGrub::VersionSolver.new(source: self, root: root, strategy: Strategy.new(self), logger: logger)
90
- result = solver.solve
93
+ result = loop do
94
+ solver = Gem::PubGrub::VersionSolver.new(source: self, root: root, strategy: Strategy.new(self), logger: logger)
95
+ solution = solver.solve
96
+
97
+ # Some indexes omit Ruby and RubyGems requirements. Fetch them only for
98
+ # selected versions, then solve again if the new requirements conflict.
99
+ incompatible = solution.values.flat_map(&:specs).filter_map do |s|
100
+ next unless s.is_a?(MatchRemoteMetadata)
101
+ dependency = s.incompatible_metadata_dependency(@base.overrides)
102
+ [s, dependency] if dependency
103
+ end
104
+ break solution if incompatible.empty?
105
+
106
+ incompatible.each {|s, dep| (@incompatible_specs[s.name] ||= {})[s.full_name] = dep }
107
+ root, logger = setup_solver
108
+ end
109
+
91
110
  resolved_specs = result.flat_map {|package, version| version.to_specs(package, @most_specific_locked_platform) }
92
111
  check_replaced_gems(resolved_specs)
93
112
  Override.attach(resolved_specs, @base.overrides)
@@ -180,8 +199,10 @@ module Bundler
180
199
  names_to_allow_remote_specs_for = []
181
200
  extended_explanation = nil
182
201
 
202
+ satisfiers = []
183
203
  while incompatibility.conflict?
184
204
  cause = incompatibility.cause
205
+ satisfiers << cause.satisfier
185
206
  incompatibility = cause.incompatibility
186
207
 
187
208
  incompatibility.terms.each do |term|
@@ -190,7 +211,7 @@ module Bundler
190
211
 
191
212
  if base_requirements[name]
192
213
  names_to_unlock << name
193
- elsif package.ignores_prereleases? && @all_specs[name].any? {|s| s.version.prerelease? }
214
+ elsif filtered_prereleases?(package)
194
215
  names_to_allow_prereleases_for << name
195
216
  elsif package.prefer_local? && @all_specs[name].any? {|s| !s.is_a?(StubSpecification) }
196
217
  names_to_allow_remote_specs_for << name
@@ -203,6 +224,11 @@ module Bundler
203
224
  end
204
225
  end
205
226
 
227
+ # Preserve the usual retry order when it can already resolve the conflict.
228
+ if names_to_unlock.empty? && names_to_allow_prereleases_for.empty? && names_to_allow_remote_specs_for.empty?
229
+ names_to_allow_prereleases_for = prerelease_names_in(satisfiers)
230
+ end
231
+
206
232
  [names_to_unlock.uniq, names_to_allow_prereleases_for.uniq, names_to_allow_remote_specs_for.uniq, extended_explanation]
207
233
  end
208
234
 
@@ -310,6 +336,17 @@ module Bundler
310
336
  results = filter_matching_specs(results, locked_requirement) if locked_requirement
311
337
 
312
338
  results.group_by(&:version).reduce([]) do |groups, (version, specs)|
339
+ if rejected = @incompatible_specs[name]
340
+ compatible = specs.reject do |s|
341
+ if s.is_a?(RemoteSpecification) && s.gemspec_loaded?
342
+ rejected[s.full_name] ||= s.incompatible_metadata_dependency(@base.overrides)
343
+ end
344
+ rejected[s.full_name]
345
+ end
346
+ # Keep the conflicting dependencies when PubGrub needs to explain why no build works.
347
+ specs = compatible unless compatible.empty?
348
+ end
349
+
313
350
  platform_specs = package.platform_specs(specs)
314
351
 
315
352
  # If package is a top-level dependency,
@@ -368,8 +405,10 @@ module Bundler
368
405
  "Gemfile"
369
406
  end
370
407
 
371
- def raise_incomplete!(incomplete_specs)
372
- raise_not_found!(@base.get_package(incomplete_specs.first.name))
408
+ def raise_incomplete!(incomplete_specs, platform = nil)
409
+ spec = incomplete_specs.first
410
+ # An unresolved dependency may be missing for a different resolution platform.
411
+ raise_not_found!(@base.get_package(spec.name), spec.version && platform)
373
412
  end
374
413
 
375
414
  def sort_versions_by_preferred(package, versions)
@@ -378,7 +417,7 @@ module Bundler
378
417
 
379
418
  private
380
419
 
381
- def raise_not_found!(package)
420
+ def raise_not_found!(package, platform = nil)
382
421
  name = package.name
383
422
  source = source_for(name)
384
423
  specs = @all_specs[name]
@@ -394,7 +433,7 @@ module Bundler
394
433
  not_found_message = if specs_matching_requirement.any?
395
434
  specs = specs_matching_requirement
396
435
  matching_part = requirement_label
397
- platforms = package.platforms
436
+ platforms = platform ? [platform] : package.platforms
398
437
 
399
438
  if platforms.size == 1
400
439
  "Could not find gem '#{requirement_label}' with platform '#{platforms.first}'"
@@ -461,6 +500,30 @@ module Bundler
461
500
  filter_remote_specs(filter_cooldown(filter_prereleases(specs, package)), package)
462
501
  end
463
502
 
503
+ def prerelease_names_in(incompatibilities)
504
+ seen = {}.compare_by_identity
505
+ packages = []
506
+ while (incompatibility = incompatibilities.pop)
507
+ next if seen[incompatibility]
508
+ seen[incompatibility] = true
509
+
510
+ if incompatibility.conflict?
511
+ cause = incompatibility.cause
512
+ incompatibilities.push(cause.incompatibility, cause.satisfier)
513
+ else
514
+ incompatibility.terms.each {|term| packages << term.package }
515
+ end
516
+ end
517
+
518
+ packages.uniq.filter_map do |package|
519
+ package.name if !base_requirements[package.name] && filtered_prereleases?(package)
520
+ end
521
+ end
522
+
523
+ def filtered_prereleases?(package)
524
+ package.ignores_prereleases? && @all_specs[package.name].any? {|s| s.version.prerelease? }
525
+ end
526
+
464
527
  def filter_prereleases(specs, package)
465
528
  return specs unless package.ignores_prereleases? && specs.size > 1
466
529
 
@@ -546,6 +609,8 @@ module Bundler
546
609
  @cooldown_skipped_specs.each do |(name, version), spec|
547
610
  resolved = resolved_versions[name]
548
611
  next unless resolved && version > resolved
612
+ package = @base.get_package(name)
613
+ next if !package.unlock? && package.locked_version == resolved
549
614
  next unless requirements[name].all? {|req| req.satisfied_by?(version) }
550
615
  newest = newest_skipped[name]
551
616
  newest_skipped[name] = spec if newest.nil? || version > newest.version
@@ -618,6 +683,13 @@ module Bundler
618
683
  versions = versions_for(dep_package, dep_range)
619
684
  end
620
685
 
686
+ if versions.empty? && locked_version_missing?(dep_package)
687
+ @base.unlock_names([name])
688
+ @all_versions.delete(dep_package)
689
+ @sorted_versions.delete(dep_package)
690
+ versions = versions_for(dep_package, dep_range)
691
+ end
692
+
621
693
  if versions.empty? && select_all_versions(dep_package, dep_range).any?
622
694
  raise_all_versions_filtered_out!(dep_package)
623
695
  end
@@ -630,6 +702,16 @@ module Bundler
630
702
  end.to_h
631
703
  end
632
704
 
705
+ def locked_version_missing?(package)
706
+ return false unless package.unlock?
707
+
708
+ name = package.name
709
+ version = package.locked_version
710
+ return false unless base_requirements[name]&.requirements == [[">=", version]]
711
+
712
+ source_for(name).specs.search([name, version]).empty?
713
+ end
714
+
633
715
  def select_all_versions(package, range)
634
716
  range.select_versions(@all_versions[package])
635
717
  end
@@ -42,11 +42,12 @@ module Bundler
42
42
  # Loads the file relative to the dirname of the Gemfile itself.
43
43
  def normalize_ruby_file(filename)
44
44
  file_content = Bundler.read_file(gemfile.dirname.join(filename))
45
- # match "ruby-3.2.2", ruby = "3.2.2", ruby = '3.2.2' or "ruby 3.2.2" capturing version string up to the first space or comment
45
+ # match "ruby-3.2.2", ruby = "3.2.2", ruby = '3.2.2', ruby = { version = "3.2.2" } or "ruby 3.2.2" capturing version string up to the first space or comment
46
46
  version_match = /^ # Start of line
47
47
  ruby # Literal "ruby"
48
48
  [\s-]* # Optional whitespace or hyphens (for "ruby-3.2.2" format)
49
49
  (?:=\s*)? # Optional equals sign with whitespace (for ruby = "3.2.2" format)
50
+ (?:\{[^}]*?\bversion\s*=\s*)? # Optional inline table up to its version key (for ruby = { version = "3.2.2" } format)
50
51
  (?:
51
52
  "([^"]+)" # Double quoted version
52
53
  |
@@ -42,6 +42,29 @@ module Gem
42
42
  def self.content_addressed_row?(suffix, platform, required_ruby_version = nil, validate_ruby_abi: true)
43
43
  false
44
44
  end
45
+
46
+ def self.platform_eligible?(platform)
47
+ false
48
+ end
49
+
50
+ def self.ruby_abi_for(required_ruby_version)
51
+ nil
52
+ end
53
+
54
+ def self.valid_ruby_abi?(value)
55
+ value.is_a?(String) && /\A\d+\.\d+\z/.match?(value)
56
+ end
57
+
58
+ def self.ruby_abi_requirement(ruby_abi)
59
+ Gem::Requirement.new("~> #{ruby_abi}.0")
60
+ end
61
+ end
62
+ end
63
+
64
+ # Can be removed once RubyGems 4.0.0 support is dropped
65
+ unless respond_to?(:ruby_abi)
66
+ def self.ruby_abi
67
+ ruby_version.segments.first(2).join(".")
45
68
  end
46
69
  end
47
70
 
@@ -257,6 +280,19 @@ module Gem
257
280
 
258
281
  prepend AllowSettingSource
259
282
 
283
+ module TrackGemfileActivation
284
+ # The Gemfile being evaluated when RubyGems activated this spec.
285
+ attr_reader :bundler_activating_gemfile
286
+
287
+ def activate
288
+ activated = super
289
+ @bundler_activating_gemfile = Thread.current[:bundler_evaluating_gemfile] if activated
290
+ activated
291
+ end
292
+ end
293
+
294
+ prepend TrackGemfileActivation
295
+
260
296
  alias_method :rg_full_gem_path, :full_gem_path
261
297
  alias_method :rg_loaded_from, :loaded_from
262
298
 
@@ -498,15 +534,6 @@ module Gem
498
534
  end
499
535
  end
500
536
 
501
- unless instance_method(:initialize).parameters.any? {|kind, name| kind == :key && name == :content_address }
502
- alias_method :initialize_without_content_address, :initialize
503
-
504
- def initialize(name, version, platform = Gem::Platform::RUBY, content_address: nil)
505
- initialize_without_content_address(name, version, platform)
506
- @content_address = content_address
507
- end
508
- end
509
-
510
537
  def lock_name
511
538
  if platform == Gem::Platform::RUBY
512
539
  "#{name} (#{version})"
@@ -516,6 +543,24 @@ module Gem
516
543
  end
517
544
  end
518
545
 
546
+ # Defined unconditionally for testability, see SplitCompactIndexEntryOnFirstColon.
547
+ module NameTupleContentAddress
548
+ def initialize(name, version, platform = Gem::Platform::RUBY, content_address: nil)
549
+ super(name, version, platform)
550
+ @content_address = content_address
551
+ end
552
+
553
+ def full_name
554
+ return super unless @content_address
555
+
556
+ "#{@name}-#{@version}-#{@content_address}"
557
+ end
558
+ end
559
+
560
+ unless NameTuple.instance_method(:initialize).parameters.any? {|kind, name| kind == :key && name == :content_address }
561
+ NameTuple.prepend(NameTupleContentAddress)
562
+ end
563
+
519
564
  unless Gem.rubygems_version >= Gem::Version.new("3.5.19")
520
565
  class Resolver::ActivationRequest
521
566
  remove_method :installed?
@@ -289,11 +289,9 @@ module Bundler
289
289
  end
290
290
 
291
291
  Bundler.rubygems.default_stubs.each do |stub|
292
- default_spec = stub.to_spec
293
- default_spec_name = default_spec.name
294
- next if specs_by_name.key?(default_spec_name)
292
+ next if specs_by_name.key?(stub.name)
295
293
 
296
- specs_by_name[default_spec_name] = default_spec
294
+ specs_by_name[stub.name] = stub.to_spec
297
295
  end
298
296
 
299
297
  specs_by_name
@@ -210,26 +210,25 @@ module Bundler
210
210
  stale_gemspec_files = gemspec_files - spec_gemspec_paths
211
211
  stale_extension_dirs = extension_dirs - spec_extension_paths
212
212
 
213
- removed_stale_gem_dirs = stale_gem_dirs.collect {|dir| remove_dir(dir, dry_run) }
214
- removed_stale_git_dirs = stale_git_dirs.collect {|dir| remove_dir(dir, dry_run) }
213
+ failures = []
214
+ removed_stale_gem_dirs = stale_gem_dirs.filter_map {|dir| remove_dir(dir, dry_run, failures) }
215
+ removed_stale_git_dirs = stale_git_dirs.filter_map {|dir| remove_dir(dir, dry_run, failures) }
215
216
  output = removed_stale_gem_dirs + removed_stale_git_dirs
216
217
 
217
218
  unless dry_run
218
219
  stale_files = stale_gem_bins + stale_gem_files + stale_gemspec_files
219
220
  stale_files.each do |file|
220
- SharedHelpers.filesystem_access(File.dirname(file)) do |_p|
221
- FileUtils.rm(file) if File.exist?(file)
222
- end
221
+ remove_path(file, failures, File.dirname(file))
223
222
  end
224
223
 
225
224
  stale_dirs = stale_git_cache_dirs + stale_extension_dirs
226
225
  stale_dirs.each do |stale_dir|
227
- SharedHelpers.filesystem_access(stale_dir) do |dir|
228
- FileUtils.rm_rf(dir) if File.exist?(dir)
229
- end
226
+ remove_path(stale_dir, failures)
230
227
  end
231
228
  end
232
229
 
230
+ raise CleanError.new(failures) unless failures.empty?
231
+
233
232
  output
234
233
  end
235
234
 
@@ -359,7 +358,7 @@ module Bundler
359
358
  ).uniq.join(File::PATH_SEPARATOR)
360
359
  end
361
360
 
362
- def remove_dir(dir, dry_run)
361
+ def remove_dir(dir, dry_run, failures)
363
362
  full_name = Pathname.new(dir).basename.to_s
364
363
 
365
364
  parts = full_name.split("-")
@@ -370,18 +369,37 @@ module Bundler
370
369
  if dry_run
371
370
  Bundler.ui.info "Would have removed #{output}"
372
371
  else
372
+ return unless remove_path(dir, failures)
373
373
  Bundler.ui.info "Removing #{output}"
374
- FileUtils.rm_rf(dir)
375
374
  end
376
375
 
377
376
  output
378
377
  end
379
378
 
379
+ # Collects the error instead of raising it, so that one path that cannot be
380
+ # removed does not stop the rest of the bundle from being cleaned.
381
+ def remove_path(path, failures, access_path = path)
382
+ SharedHelpers.filesystem_access(access_path) do
383
+ FileUtils.rm_r(path)
384
+ end
385
+ true
386
+ rescue Errno::ENOENT
387
+ # Removed by something else since the bundle was scanned
388
+ true
389
+ rescue BundlerError => e
390
+ failures << e
391
+ false
392
+ end
393
+
380
394
  def check_for_activated_spec!(spec)
381
395
  return unless activated_spec = Bundler.rubygems.loaded_specs(spec.name)
382
396
  return if activated_spec.version == spec.version
383
397
 
384
- suggestion = if activated_spec.default_gem?
398
+ activating_gemfile = activated_spec.bundler_activating_gemfile if activated_spec.respond_to?(:bundler_activating_gemfile)
399
+ suggestion = if @definition.gemfiles.include?(activating_gemfile)
400
+ "#{spec.name} was activated while evaluating your Gemfile. If a `require` in your Gemfile loads it, " \
401
+ "remove that call or move it outside the Gemfile, after `Bundler.setup`."
402
+ elsif activated_spec.default_gem?
385
403
  "Since #{spec.name} is a default gem, you can either remove your dependency on it" \
386
404
  " or try updating to a newer version of bundler that supports #{spec.name} as a default gem."
387
405
  else
@@ -826,9 +826,8 @@ module Bundler
826
826
  end
827
827
 
828
828
  def serializer_class
829
- # The Bundler gem ships its own copy of Gem::YAMLSerializer, so this
830
- # resolves even on RubyGems versions that predate it.
831
- require "rubygems/yaml_serializer"
829
+ # See lib/rubygems/yaml_serializer/core.rb.
830
+ require_relative "../rubygems/yaml_serializer/core"
832
831
  Gem::YAMLSerializer
833
832
  end
834
833
 
@@ -169,13 +169,25 @@ module Bundler
169
169
  git "fetch", "--force", "--quiet", *extra_fetch_args(ref), dir: destination
170
170
  end
171
171
 
172
- git "reset", "--hard", revision, dir: destination
172
+ # A checkout that already had a working tree may be a local override, which
173
+ # is the user's own working copy, so a failure only discards one that had none.
174
+ checked_out = installed_to?(destination)
175
+ begin
176
+ git "reset", "--hard", revision, dir: destination
173
177
 
174
- if submodules
175
- git_retry "submodule", "update", "--init", "--recursive", dir: destination
176
- elsif Gem::Version.create(version) >= Gem::Version.create("2.9.0")
177
- inner_command = "git -C $toplevel submodule deinit --force $sm_path"
178
- git_retry "submodule", "foreach", "--quiet", inner_command, dir: destination
178
+ if submodules
179
+ git_retry "submodule", "update", "--init", "--recursive", dir: destination
180
+ elsif Gem::Version.create(version) >= Gem::Version.create("2.9.0")
181
+ inner_command = "git -C $toplevel submodule deinit --force $sm_path"
182
+ git_retry "submodule", "foreach", "--quiet", inner_command, dir: destination
183
+ end
184
+ rescue GitCommandError
185
+ unless checked_out
186
+ SharedHelpers.filesystem_access(destination) do |p|
187
+ FileUtils.rm_rf(p)
188
+ end
189
+ end
190
+ raise
179
191
  end
180
192
  end
181
193
 
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../vendored_fileutils"
4
-
5
3
  module Bundler
6
4
  class Source
7
5
  class Git < Path