bundler 4.1.0.beta2 → 4.1.0

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 (51) hide show
  1. checksums.yaml +4 -4
  2. data/lib/bundler/build_metadata.rb +2 -2
  3. data/lib/bundler/checksum.rb +8 -2
  4. data/lib/bundler/cli/clean.rb +19 -3
  5. data/lib/bundler/cli/exec.rb +1 -1
  6. data/lib/bundler/cli/install.rb +1 -1
  7. data/lib/bundler/cli/lock.rb +17 -1
  8. data/lib/bundler/cli/update.rb +1 -1
  9. data/lib/bundler/cli.rb +2 -0
  10. data/lib/bundler/definition.rb +170 -12
  11. data/lib/bundler/dsl.rb +40 -23
  12. data/lib/bundler/errors.rb +8 -0
  13. data/lib/bundler/fetcher/downloader.rb +15 -5
  14. data/lib/bundler/fetcher.rb +4 -1
  15. data/lib/bundler/index.rb +7 -2
  16. data/lib/bundler/inline.rb +16 -8
  17. data/lib/bundler/installer.rb +19 -0
  18. data/lib/bundler/lazy_specification.rb +42 -25
  19. data/lib/bundler/lockfile_generator.rb +27 -9
  20. data/lib/bundler/lockfile_parser.rb +38 -6
  21. data/lib/bundler/man/bundle-lock.1 +7 -1
  22. data/lib/bundler/man/bundle-lock.1.ronn +10 -0
  23. data/lib/bundler/man/bundle-plugin.1 +61 -0
  24. data/lib/bundler/man/bundle-plugin.1.ronn +84 -0
  25. data/lib/bundler/man/gemfile.5 +21 -10
  26. data/lib/bundler/man/gemfile.5.ronn +39 -17
  27. data/lib/bundler/match_platform.rb +15 -6
  28. data/lib/bundler/mirror.rb +7 -5
  29. data/lib/bundler/override.rb +60 -7
  30. data/lib/bundler/resolver.rb +3 -1
  31. data/lib/bundler/ruby_dsl.rb +2 -1
  32. data/lib/bundler/rubygems_ext.rb +56 -13
  33. data/lib/bundler/rubygems_integration.rb +2 -4
  34. data/lib/bundler/runtime.rb +24 -10
  35. data/lib/bundler/source/git/git_proxy.rb +18 -6
  36. data/lib/bundler/source/git.rb +0 -2
  37. data/lib/bundler/source/rubygems.rb +2 -2
  38. data/lib/bundler/source_map.rb +1 -1
  39. data/lib/bundler/spec_set.rb +26 -7
  40. data/lib/bundler/stub_specification.rb +4 -0
  41. data/lib/bundler/vendor/fileutils/lib/fileutils.rb +54 -29
  42. data/lib/bundler/version.rb +1 -1
  43. data/lib/bundler/worker.rb +4 -0
  44. data/lib/bundler.rb +1 -1
  45. data/lib/rubygems/compact_index_client/http_fetcher.rb +3 -1
  46. data/lib/rubygems/compact_index_client/parser.rb +1 -0
  47. data/lib/rubygems/vendor/uri/lib/uri/common.rb +1 -1
  48. data/lib/rubygems/vendor/uri/lib/uri/generic.rb +15 -3
  49. data/lib/rubygems/vendor/uri/lib/uri/version.rb +1 -1
  50. data/lib/rubygems/yaml_serializer.rb +247 -137
  51. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3c0da83afaf51ba4984bf6afadad1dc16ba90dd523a7a70ed5ca4e353fb5a3ef
4
- data.tar.gz: 252ab201fa16d64d654b43f3f642d622dbaa94c653b90bddea01af7f8dfdf6a7
3
+ metadata.gz: 95379a1f0c09158c2837a8cf2907618f7e4699b95cc0d01782e253d3aafce23c
4
+ data.tar.gz: aebc9136db0a2e12eb306d0d3b5b21a3fb308f764895babb5204c163149b4cf7
5
5
  SHA512:
6
- metadata.gz: d3d0486d8ace2df28048406ccba0335f679c5d7bef8e3ab20c8c72628fb1500ddc3d80ac8ae897b63ecb268a33a7fcb9a826b5833414ee7e63fb46c37e674528
7
- data.tar.gz: e9e6a99a38ff138d0fb3bc992843384bf06f732513c65e015c7758fa72dd210c5d369aced9826813799ca189b073270499a109cc4b5290183e67db5010430d3c
6
+ metadata.gz: 2568864dcb864f9693e423011f21102bac7e405fc387363c704b0f37cedaf88c85ee32d9d3523cf23f4b4d78ffc8eed4ca33347dc5ffc8c96ebc19d5f0c9cb2f
7
+ data.tar.gz: 528ce6fac35a18bfb6d7de70769affc32870ef22377a83789a08734cbdd82a17132da30315897d8e4c2f5816b16f3c988e5ecc3b0c3a480fe6770c29242c8bf8
@@ -4,8 +4,8 @@ module Bundler
4
4
  # Represents metadata from when the Bundler gem was built.
5
5
  module BuildMetadata
6
6
  # begin ivars
7
- @built_at = "2026-10-08".freeze
8
- @git_commit_sha = "f8b8b02".freeze
7
+ @built_at = "2026-11-16".freeze
8
+ @git_commit_sha = "9af9267".freeze
9
9
  # end ivars
10
10
 
11
11
  # A hash representation of the build metadata.
@@ -206,13 +206,19 @@ module Bundler
206
206
  end
207
207
 
208
208
  def missing?(spec)
209
- @store[spec.full_name].nil?
209
+ return false unless @store[spec.full_name].nil?
210
+
211
+ if spec.is_a?(LazySpecification)
212
+ spec.content_addressed_full_names.all? {|full_name| @store[full_name].nil? }
213
+ else
214
+ true
215
+ end
210
216
  end
211
217
 
212
218
  def empty?(spec)
213
219
  return false unless spec.source.is_a?(Bundler::Source::Rubygems)
214
220
 
215
- @store[spec.full_name].empty?
221
+ @store[spec.full_name]&.empty? || false
216
222
  end
217
223
 
218
224
  def register(spec, checksum)
@@ -13,13 +13,29 @@ module Bundler
13
13
  Bundler.load.clean(options[:"dry-run"])
14
14
  return if options[:"dry-run"]
15
15
 
16
- # Pruning last, because cleaning decides which cached .gem files are
17
- # stale by reading them.
18
- Bundler::CLI::Common.prune(options)
16
+ prune
17
+ rescue CleanError
18
+ # Everything that could be removed is gone, so the cache can be pruned
19
+ prune
20
+ raise
21
+ end
22
+
23
+ # Cleaning is incidental to install and update, so leftovers must not fail
24
+ # a command that installed everything it was asked to.
25
+ def run_after_install
26
+ run
27
+ rescue CleanError => e
28
+ Bundler.ui.warn e.message
19
29
  end
20
30
 
21
31
  protected
22
32
 
33
+ # Pruning last, because cleaning decides which cached .gem files are
34
+ # stale by reading them.
35
+ def prune
36
+ Bundler::CLI::Common.prune(options)
37
+ end
38
+
23
39
  def require_path_or_force
24
40
  return unless Bundler.use_system_gems? && !options[:force]
25
41
  raise InvalidOption, "Cleaning all the gems on your system is dangerous! " \
@@ -24,7 +24,7 @@ module Bundler
24
24
  kernel_load(bin_path, *args)
25
25
  else
26
26
  bin_path = explicit_path(bin_path)
27
- kernel_exec(bin_path, *args)
27
+ kernel_exec([bin_path, bin_path], *args)
28
28
  end
29
29
  else
30
30
  # exec using the given command
@@ -68,7 +68,7 @@ module Bundler
68
68
 
69
69
  if CLI::Common.clean_after_install?
70
70
  require_relative "clean"
71
- Bundler::CLI::Clean.new(options).run
71
+ Bundler::CLI::Clean.new(options).run_after_install
72
72
  else
73
73
  CLI::Common.prune(options)
74
74
  end
@@ -42,7 +42,6 @@ module Bundler
42
42
 
43
43
  Bundler.settings.temporary(frozen: false) do
44
44
  definition = Bundler.definition(update, Bundler.default_lockfile)
45
- definition.add_checksums if options["add-checksums"]
46
45
 
47
46
  Bundler::CLI::Common.configure_gem_version_promoter(definition, options) if options[:update]
48
47
 
@@ -64,6 +63,23 @@ module Bundler
64
63
  raise InvalidOption, "Removing all platforms from the bundle is not allowed"
65
64
  end
66
65
 
66
+ options["remove-ruby-abi"].flatten.each do |ruby_abi|
67
+ definition.remove_ruby_abi(ruby_abi)
68
+ end
69
+
70
+ options["add-ruby-abi"].flatten.each do |ruby_abi|
71
+ raise InvalidOption, "Expected `--add-ruby-abi` to be a Ruby ABI like `X.Y`, got #{ruby_abi.inspect}" unless Gem::ContentAddress.valid_ruby_abi?(ruby_abi)
72
+
73
+ definition.add_ruby_abi(ruby_abi)
74
+ end
75
+
76
+ # Adding checksums resolves the bundle to fetch them, so it has to
77
+ # run after every platform change above has been recorded, or the
78
+ # new platforms are listed in the lockfile without their specs.
79
+ definition.add_checksums if options["add-checksums"]
80
+
81
+ # Adding a Ruby ABI offline takes its content-addressed gems from the installed ones.
82
+ definition.with_cache! if options[:local] && options["add-ruby-abi"].any?
67
83
  definition.remotely! unless options[:local]
68
84
 
69
85
  if options["normalize-platforms"]
@@ -90,7 +90,7 @@ module Bundler
90
90
 
91
91
  if CLI::Common.clean_after_install?
92
92
  require_relative "clean"
93
- Bundler::CLI::Clean.new(options).run
93
+ Bundler::CLI::Clean.new(options).run_after_install
94
94
  else
95
95
  CLI::Common.prune(options)
96
96
  end
data/lib/bundler/cli.rb CHANGED
@@ -653,6 +653,8 @@ module Bundler
653
653
  method_option "add-platform", type: :array, default: [], repeatable: true, banner: "Add a new platform to the lockfile"
654
654
  method_option "remove-platform", type: :array, default: [], repeatable: true, banner: "Remove a platform from the lockfile"
655
655
  method_option "normalize-platforms", type: :boolean, default: false, banner: "Normalize lockfile platforms"
656
+ method_option "add-ruby-abi", type: :array, default: [], repeatable: true, banner: "Lock the content-addressed gems for a Ruby ABI (X.Y)"
657
+ method_option "remove-ruby-abi", type: :array, default: [], repeatable: true, banner: "Drop the content-addressed gems for a Ruby ABI (X.Y) from the lockfile"
656
658
  method_option "patch", type: :boolean, banner: "If updating, prefer updating only to next patch version"
657
659
  method_option "minor", type: :boolean, banner: "If updating, prefer updating only to next minor version"
658
660
  method_option "major", type: :boolean, banner: "If updating, prefer updating to latest major version (default)"
@@ -104,6 +104,8 @@ module Bundler
104
104
  @new_platforms = []
105
105
  @removed_platforms = []
106
106
  @originally_invalid_platforms = []
107
+ @new_ruby_abis = []
108
+ @removed_ruby_abis = []
107
109
 
108
110
  if lockfile_exists?
109
111
  @lockfile_contents = Bundler.read_file(lockfile)
@@ -111,6 +113,8 @@ module Bundler
111
113
  @locked_platforms = @locked_gems.platforms
112
114
  @most_specific_locked_platform = @locked_gems.most_specific_locked_platform
113
115
  @platforms = @locked_platforms.dup
116
+ @locked_ruby_abis = @locked_gems.ruby_abis
117
+ @ruby_abis = @locked_ruby_abis.dup
114
118
  @locked_bundler_version = @locked_gems.bundler_version
115
119
  @locked_ruby_version = @locked_gems.ruby_version
116
120
  @locked_deps = @locked_gems.dependencies
@@ -139,7 +143,9 @@ module Bundler
139
143
  @locked_gems = nil
140
144
  @locked_platforms = []
141
145
  @most_specific_locked_platform = nil
142
- @platforms = []
146
+ @platforms = []
147
+ @locked_ruby_abis = []
148
+ @ruby_abis = []
143
149
  @locked_deps = {}
144
150
  @locked_specs = SpecSet.new([])
145
151
  @locked_sources = []
@@ -153,7 +159,11 @@ module Bundler
153
159
  end
154
160
  @unlocking ||= @unlocking_ruby ||= (!@locked_ruby_version ^ !@ruby_version)
155
161
 
162
+ @excluded_ruby_abis = @ruby_version && content_addressing_supported? ? @ruby_abis.select {|ruby_abi| ruby_abi_excluded?(ruby_abi) } : []
163
+ @ruby_abis -= @excluded_ruby_abis
164
+
156
165
  @current_platform_missing = add_current_platform unless Bundler.frozen_bundle?
166
+ @current_ruby_abi_missing = add_current_ruby_abi unless Bundler.frozen_bundle?
157
167
 
158
168
  @source_changes = converge_sources
159
169
  @path_changes = converge_paths
@@ -167,6 +177,7 @@ module Bundler
167
177
 
168
178
  @dependency_changes = converge_dependencies
169
179
  @local_changes = converge_locals
180
+ @override_changes = converge_overrides
170
181
 
171
182
  check_lockfile
172
183
  end
@@ -369,6 +380,7 @@ module Bundler
369
380
  start_resolution
370
381
  end
371
382
  warn_inert_overrides(@resolve)
383
+ @resolve.assign_content_addresses!(@ruby_abis, local: sources.local_mode?) if @removed_ruby_abis.any?
372
384
  @resolve
373
385
  end
374
386
 
@@ -477,6 +489,11 @@ module Bundler
477
489
  @resolved_bundler_version || Bundler.gem_version
478
490
  end
479
491
 
492
+ # The lines for the OVERRIDES section of Gemfile.lock.
493
+ def overrides_to_lock
494
+ @overrides.map(&:to_lock).uniq
495
+ end
496
+
480
497
  def to_lock
481
498
  require_relative "lockfile_generator"
482
499
  LockfileGenerator.generate(self)
@@ -537,6 +554,32 @@ module Bundler
537
554
  resolve.normalize_platforms!(current_dependencies, platforms)
538
555
 
539
556
  @resolve = SpecSet.new(resolve.for(current_dependencies, @platforms))
557
+ @resolve.assign_content_addresses!(@ruby_abis, normalize: true)
558
+ end
559
+
560
+ def ruby_abis
561
+ return [] unless content_addressing_supported? || content_addresses_carried_over?
562
+
563
+ @ruby_abis.sort_by {|ruby_abi| Gem::Version.new(ruby_abi) }
564
+ end
565
+
566
+ def add_ruby_abi(ruby_abi)
567
+ ensure_content_addressing_supported!
568
+ if @ruby_version && ruby_abi_excluded?(ruby_abi)
569
+ raise InvalidOption, "Unable to add the Ruby ABI `#{ruby_abi}` since your Gemfile requires #{@ruby_version}"
570
+ end
571
+ return if @locked_ruby_abis.include?(ruby_abi) || @new_ruby_abis.include?(ruby_abi)
572
+
573
+ @new_ruby_abis << ruby_abi
574
+ @ruby_abis |= [ruby_abi]
575
+ end
576
+
577
+ def remove_ruby_abi(ruby_abi)
578
+ ensure_content_addressing_supported!
579
+ raise InvalidOption, "Unable to remove the Ruby ABI `#{ruby_abi}` since the only Ruby ABIs are #{ruby_abis.join(", ")}" unless @ruby_abis.include?(ruby_abi)
580
+
581
+ @removed_ruby_abis << ruby_abi
582
+ @ruby_abis.delete(ruby_abi)
540
583
  end
541
584
 
542
585
  def add_platform(platform)
@@ -595,10 +638,17 @@ module Bundler
595
638
 
596
639
  added.concat @new_platforms.map {|p| "* platform: #{p}" }
597
640
  deleted.concat @removed_platforms.map {|p| "* platform: #{p}" }
641
+ added.concat @new_ruby_abis.map {|abi| "* ruby abi: #{abi}" }
642
+ deleted.concat @removed_ruby_abis.map {|abi| "* ruby abi: #{abi}" }
598
643
 
599
644
  added.concat new_deps.map {|d| "* #{pretty_dep(d)}" } if new_deps.any?
600
645
  deleted.concat deleted_deps.map {|d| "* #{pretty_dep(d)}" } if deleted_deps.any?
601
646
 
647
+ if @override_changes
648
+ added.concat((overrides_to_lock - locked_overrides_to_lock).sort.map {|o| "* override #{o}" })
649
+ deleted.concat((locked_overrides_to_lock - overrides_to_lock).sort.map {|o| "* override #{o}" })
650
+ end
651
+
602
652
  both_sources = Hash.new {|h, k| h[k] = [] }
603
653
  current_dependencies.each {|d| both_sources[d.name][0] = d }
604
654
  current_locked_dependencies.each {|d| both_sources[d.name][1] = d }
@@ -649,6 +699,9 @@ module Bundler
649
699
  @dependency_changes ||
650
700
  @current_platform_missing ||
651
701
  @new_platforms.any? ||
702
+ @current_ruby_abi_missing ||
703
+ @new_ruby_abis.any? ||
704
+ @excluded_ruby_abis.any? ||
652
705
  @path_changes ||
653
706
  @local_changes ||
654
707
  @missing_lockfile_dep ||
@@ -776,7 +829,9 @@ module Bundler
776
829
  loop do
777
830
  break if incomplete_specs.empty?
778
831
 
779
- Bundler.ui.debug("The lockfile does not have all gems needed for the current platform though, Bundler will still re-resolve dependencies")
832
+ Bundler.ui.debug("The lockfile does not have all gems needed for the current platform (#{Bundler.local_platform}) though, " \
833
+ "Bundler will still re-resolve dependencies. The following locked gems could not be materialized for it: " \
834
+ "#{incomplete_specs.map(&:full_name).join(", ")}")
780
835
  sources.remote!
781
836
  reresolve_without(incomplete_specs)
782
837
  specs = resolve.materialize(dependencies)
@@ -842,7 +897,22 @@ module Bundler
842
897
  result.add_originally_invalid_platforms!(platforms, @originally_invalid_platforms)
843
898
  end
844
899
 
845
- SpecSet.new(result.for(dependencies, @platforms | [Gem::Platform::RUBY]))
900
+ specs = SpecSet.new(result.for(dependencies, @platforms | [Gem::Platform::RUBY]))
901
+ specs.assign_content_addresses!(@ruby_abis, local: sources.local_mode?)
902
+
903
+ if sources.local_mode?
904
+ # Only installed gems are in reach, so a Ruby is recorded once every row
905
+ # has its gem; the running Ruby otherwise waits for the next online resolution.
906
+ @ruby_abis.delete(Gem.ruby_abi) if @current_ruby_abi_missing && !specs.content_addresses_cover?(Gem.ruby_abi)
907
+
908
+ @new_ruby_abis.each do |ruby_abi|
909
+ next if specs.content_addresses_cover?(ruby_abi)
910
+
911
+ raise GemNotFound, "Could not find content-addressed gems for Ruby ABI #{ruby_abi} in locally installed gems"
912
+ end
913
+ end
914
+
915
+ specs
846
916
  end
847
917
 
848
918
  def precompute_source_requirements_for_indirect_dependencies?
@@ -883,6 +953,66 @@ module Bundler
883
953
  true
884
954
  end
885
955
 
956
+ def add_current_ruby_abi
957
+ return unless content_addressing_supported?
958
+ return if @ruby_abis.include?(Gem.ruby_abi)
959
+
960
+ @ruby_abis << Gem.ruby_abi
961
+ @locked_specs.any? {|spec| spec.content_addresses.any? }
962
+ end
963
+
964
+ # RubyGems before 4.1 can't lock content-addressed gems, so changing the
965
+ # locked Ruby ABIs there would leave CONTENT ADDRESSES out of step with them.
966
+ def content_addressing_supported?
967
+ Bundler.rubygems.provides?(">= 4.1.0.a")
968
+ end
969
+
970
+ def ensure_content_addressing_supported!
971
+ return if content_addressing_supported?
972
+
973
+ raise InvalidOption, "Changing the Ruby ABIs in the lockfile requires RubyGems 4.1.0 or later, but you are using RubyGems #{Bundler.rubygems.version}"
974
+ end
975
+
976
+ # Older RubyGems resolves platform gems without the content addresses the
977
+ # lockfile had for them, and may swap a locked one for its ruby variant. Unless
978
+ # every platform gem comes through as locked, the lockfile then drops its Ruby
979
+ # ABIs, so that RubyGems 4.1 resolves again and records the content addresses
980
+ # instead of falling back.
981
+ def content_addresses_carried_over?
982
+ locked = @originally_locked_specs.select {|spec| spec.platform != Gem::Platform::RUBY && resolve[spec.name].any? }
983
+ resolved = resolve.select {|spec| spec.platform != Gem::Platform::RUBY }
984
+
985
+ locked.to_h {|spec| [spec.full_name, spec.content_addresses] } == resolved.to_h {|spec| [spec.full_name, spec.content_addresses] }
986
+ end
987
+
988
+ def ruby_abi_excluded?(ruby_abi)
989
+ comparators = Gem::Requirement.new(@ruby_version.versions).requirements +
990
+ Gem::ContentAddress.ruby_abi_requirement(ruby_abi).requirements
991
+
992
+ lower = []
993
+ upper = []
994
+ comparators.each do |op, version|
995
+ case op
996
+ when ">=" then lower << [version, true]
997
+ when ">" then lower << [version, false]
998
+ when "<=" then upper << [version, true]
999
+ when "<" then upper << [version, false]
1000
+ when "="
1001
+ lower << [version, true]
1002
+ upper << [version, true]
1003
+ when "~>"
1004
+ lower << [version, true]
1005
+ upper << [Gem::Version.new("#{version.bump}.A"), false]
1006
+ end
1007
+ end
1008
+ return false if lower.empty? || upper.empty?
1009
+
1010
+ min, min_inclusive = lower.max_by {|version, inclusive| [version, inclusive ? 0 : 1] }
1011
+ max, max_inclusive = upper.min_by {|version, inclusive| [version, inclusive ? 1 : 0] }
1012
+
1013
+ min > max || (min == max && !(min_inclusive && max_inclusive))
1014
+ end
1015
+
886
1016
  def find_most_specific_locked_platform
887
1017
  return unless current_platform_locked?
888
1018
 
@@ -908,6 +1038,8 @@ module Bundler
908
1038
  else
909
1039
  lockfile_changed_reason
910
1040
  end
1041
+ elsif @override_changes
1042
+ "the overrides in your gemfile changed"
911
1043
  else
912
1044
  "some dependencies were deleted from your gemfile"
913
1045
  end
@@ -935,6 +1067,9 @@ module Bundler
935
1067
  [@dependency_changes, "the dependencies in your gemfile changed"],
936
1068
  [@current_platform_missing, "your lockfile is missing the current platform"],
937
1069
  [@new_platforms.any?, "you are adding a new platform to your lockfile"],
1070
+ [@new_ruby_abis.any?, "you are adding a new Ruby ABI to your lockfile"],
1071
+ [@current_ruby_abi_missing, "your lockfile does not cover the current Ruby ABI"],
1072
+ [@excluded_ruby_abis.any?, "your Gemfile's ruby directive rules out Ruby ABIs in your lockfile"],
938
1073
  [@path_changes, "the gemspecs for path gems changed"],
939
1074
  [@local_changes, "the gemspecs for git local gems changed"],
940
1075
  [@missing_lockfile_dep, "your lockfile is missing \"#{@missing_lockfile_dep}\""],
@@ -943,6 +1078,7 @@ module Bundler
943
1078
  [@locked_spec_with_empty_checksums, "your lockfile has an empty CHECKSUMS entry for \"#{@locked_spec_with_empty_checksums}\""],
944
1079
  [@locked_spec_with_missing_deps, "your lockfile includes \"#{@locked_spec_with_missing_deps}\" but not some of its dependencies"],
945
1080
  [@locked_spec_with_invalid_deps, "your lockfile does not satisfy dependencies of \"#{@locked_spec_with_invalid_deps}\""],
1081
+ [@override_changes, "the overrides in your gemfile changed"],
946
1082
  ].select(&:first).map(&:last).join(", ")
947
1083
  end
948
1084
 
@@ -1115,7 +1251,7 @@ module Bundler
1115
1251
  end
1116
1252
 
1117
1253
  # The lockfile keeps the upstream dependencies of every gem, so a gem that
1118
- # a `from:`/`to:` override cut loose stays locked until a resolution drops
1254
+ # a `with:`/`in:` override cut loose stays locked until a resolution drops
1119
1255
  # it.
1120
1256
  def converge_rewritten_dependencies
1121
1257
  @overrides.each do |override|
@@ -1135,7 +1271,7 @@ module Bundler
1135
1271
  end
1136
1272
  end
1137
1273
 
1138
- # A misspelled `from:` gem leaves the override with nothing to rewrite.
1274
+ # A misspelled `in:` gem leaves the override with nothing to rewrite.
1139
1275
  def warn_inert_overrides(specs)
1140
1276
  @overrides.each do |override|
1141
1277
  next unless override.from
@@ -1145,13 +1281,29 @@ module Bundler
1145
1281
  end
1146
1282
  end
1147
1283
 
1284
+ # The lockfile records the Gemfile's overrides, so a change to them is a
1285
+ # change to the lockfile even when every locked version still satisfies
1286
+ # them. Rewriting the section needs no resolution, so this stays out of
1287
+ # #something_changed?. #write_lock rewrites it because the generated
1288
+ # contents differ, and the frozen check reports it.
1289
+ def converge_overrides
1290
+ return false unless @locked_gems
1291
+
1292
+ overrides_to_lock.sort != locked_overrides_to_lock.sort
1293
+ end
1294
+
1295
+ def locked_overrides_to_lock
1296
+ Array(@locked_gems&.overrides).map(&:to_lock).uniq
1297
+ end
1298
+
1148
1299
  def converge_overrides_outside_dependencies
1149
1300
  @overrides.each do |override|
1150
- # :all and metadata overrides are intentionally not pre-unlocked. The
1151
- # lockfile does not record overrides, so unlocking for them would
1152
- # re-resolve on every run and reject every frozen install. Install-time
1153
- # compatibility checks already honor them for locked specs, and they
1154
- # affect resolution on a fresh lock or when the user runs `bundle update`.
1301
+ # :all and metadata overrides are intentionally not pre-unlocked.
1302
+ # Unlocking for them would re-resolve gems the user did not ask to
1303
+ # move. Install-time compatibility checks already honor them for locked
1304
+ # specs, and they affect resolution on a fresh lock or when the user
1305
+ # runs `bundle update`. Changing one still rewrites the OVERRIDES
1306
+ # section (see #converge_overrides).
1155
1307
  next unless override.target.is_a?(String) && override.field == :version
1156
1308
 
1157
1309
  name = override.target
@@ -1266,7 +1418,7 @@ module Bundler
1266
1418
  def preload_git_source_worker
1267
1419
  workers = Bundler.settings.installation_parallelization
1268
1420
 
1269
- @preload_git_source_worker ||= Bundler::Worker.new(workers, "Git source preloading", ->(source, _) { source.specs })
1421
+ @preload_git_source_worker ||= Bundler::Worker.new(workers, "Git source preloading", ->(sources, _) { sources.each(&:specs) })
1270
1422
  end
1271
1423
 
1272
1424
  def preload_git_sources
@@ -1277,7 +1429,13 @@ module Bundler
1277
1429
  end
1278
1430
 
1279
1431
  begin
1280
- needed_git_sources.each {|source| preload_git_source_worker.enq(source) }
1432
+ # Sources from the same repository share one cache directory, and
1433
+ # running git in that directory from two workers at once makes the
1434
+ # fetches collide. Preload sources that share a cache in one job, one
1435
+ # after the other, and run the separate caches in parallel.
1436
+ needed_git_sources.group_by(&:cache_path).each_value do |sources|
1437
+ preload_git_source_worker.enq(sources)
1438
+ end
1281
1439
  ensure
1282
1440
  preload_git_source_worker.stop
1283
1441
  end
data/lib/bundler/dsl.rb CHANGED
@@ -81,11 +81,15 @@ module Bundler
81
81
  @gemspecs << spec
82
82
 
83
83
  path path, "glob" => glob, "name" => spec.name, "gemspec" => spec do
84
- add_dependency spec.name
84
+ options = {}
85
+ normalize_options(spec.name, [], options)
86
+ add_dependency spec.name, nil, options
85
87
  end
86
88
 
87
89
  spec.development_dependencies.each do |dep|
88
- add_dependency dep.name, dep.requirement.as_list, "gemspec_dev_dep" => true, "group" => development_group
90
+ options = {}
91
+ normalize_options(dep.name, dep.requirement.as_list, options)
92
+ add_dependency dep.name, dep.requirement.as_list, options.merge("gemspec_dev_dep" => true, "group" => development_group)
89
93
  end
90
94
  when 0
91
95
  raise InvalidOption, "There are no gemspecs at #{expanded_path}"
@@ -202,7 +206,12 @@ module Bundler
202
206
  validate_override_target!(target)
203
207
  source_location = caller_locations(1, 1)&.first
204
208
 
205
- if operations.key?(:from) || operations.key?(:to)
209
+ # 4.1.0.beta2 spelled `with:` and `in:` as `to:` and `from:`.
210
+ if operations.key?(:from)
211
+ raise ArgumentError, "`from:` and `to:` of `override` are now `in:` and `with:`; write `override #{target.inspect}, with: #{operations.fetch(:to, "<gem>").inspect}, in: #{operations[:from].inspect}`"
212
+ end
213
+
214
+ if operations.key?(:in) || operations.key?(:with)
206
215
  add_dependency_override(target, operations, source_location)
207
216
  return
208
217
  end
@@ -292,8 +301,16 @@ module Bundler
292
301
 
293
302
  def validate_override_target!(target)
294
303
  return if target == :all
295
- return if target.is_a?(String)
296
- raise ArgumentError, "override target must be :all or a gem name string, got #{target.inspect}"
304
+ raise ArgumentError, "override target must be :all or a gem name string, got #{target.inspect}" unless target.is_a?(String)
305
+ validate_override_gem_name!(target)
306
+ end
307
+
308
+ # Override names are recorded in the lockfile's OVERRIDES section, so they
309
+ # must be valid gem names.
310
+ def validate_override_gem_name!(name)
311
+ validate_gem_name!(name)
312
+ return if Gem::Specification::VALID_NAME_PATTERN.match?(name)
313
+ raise GemfileError, "#{name.inspect} is not a valid gem name"
297
314
  end
298
315
 
299
316
  def validate_override_field!(field)
@@ -324,40 +341,40 @@ module Bundler
324
341
  end
325
342
 
326
343
  def add_dependency_override(target, operations, source_location)
327
- unless operations.key?(:from)
328
- raise ArgumentError, "`override #{target.inspect}, to:` requires `from:` naming the gem whose dependency is rewritten"
344
+ unless operations.key?(:in)
345
+ raise ArgumentError, "`override #{target.inspect}, with:` requires `in:` naming the gem whose dependency is rewritten"
329
346
  end
330
- unless operations.key?(:to)
331
- raise ArgumentError, "`override #{target.inspect}, from:` requires `to:`; use `to: nil` to drop the dependency or `to: \"<gem>\"` to replace it"
347
+ unless operations.key?(:with)
348
+ raise ArgumentError, "`override #{target.inspect}, in:` requires `with:`; use `with: nil` to drop the dependency or `with: \"<gem>\"` to replace it"
332
349
  end
333
350
 
334
- from = operations[:from]
335
- to = operations[:to]
351
+ from = operations[:in]
352
+ with = operations[:with]
336
353
  requirement = operations[:version]
337
354
 
338
- raise ArgumentError, "`override :all` does not accept `from:`" if target == :all
339
- raise ArgumentError, "`from:` must be a gem name string, got #{from.inspect}" unless from.is_a?(String)
340
- raise ArgumentError, "`to:` must be a gem name string or nil, got #{to.inspect}" unless to.nil? || to.is_a?(String)
341
- raise ArgumentError, "`to:` must name a gem other than #{target.inspect} and #{from.inspect}" if to == target || to == from
342
- validate_gem_name!(from)
343
- validate_gem_name!(to) if to
355
+ raise ArgumentError, "`override :all` does not accept `in:`" if target == :all
356
+ raise ArgumentError, "`in:` must be a gem name string, got #{from.inspect}" unless from.is_a?(String)
357
+ raise ArgumentError, "`with:` must be a gem name string or nil, got #{with.inspect}" unless with.nil? || with.is_a?(String)
358
+ raise ArgumentError, "`with:` must name a gem other than #{target.inspect} and #{from.inspect}" if with == target || with == from
359
+ validate_override_gem_name!(from)
360
+ validate_override_gem_name!(with) if with
344
361
 
345
- unsupported = operations.keys - [:from, :to, :version]
362
+ unsupported = operations.keys - [:in, :with, :version]
346
363
  if unsupported.any?
347
- raise ArgumentError, "unsupported override field `#{unsupported.first}:` with `from:`; supported fields: `to:`, `version:`"
364
+ raise ArgumentError, "unsupported override field `#{unsupported.first}:` with `in:`; supported fields: `with:`, `version:`"
348
365
  end
349
366
 
350
367
  if operations.key?(:version)
351
- raise ArgumentError, "`version:` with `from:` requires `to:` to name a replacement gem" if to.nil?
352
- raise ArgumentError, "`version:` with `from:` must be a version requirement string, got #{requirement.inspect}" unless requirement.is_a?(String)
368
+ raise ArgumentError, "`version:` with `in:` requires `with:` to name a replacement gem" if with.nil?
369
+ raise ArgumentError, "`version:` with `in:` must be a version requirement string, got #{requirement.inspect}" unless requirement.is_a?(String)
353
370
  validate_override_operation!(requirement)
354
371
  end
355
372
 
356
373
  if @overrides.any? {|o| o.target == target && o.from == from }
357
- raise ArgumentError, "duplicate override for #{target.inspect} `from: #{from.inspect}`"
374
+ raise ArgumentError, "duplicate override for #{target.inspect} `in: #{from.inspect}`"
358
375
  end
359
376
 
360
- @overrides << Override.new(target, :to, to, from: from, requirement: requirement, source_location: source_location)
377
+ @overrides << Override.new(target, :with, with, from: from, requirement: requirement, source_location: source_location)
361
378
  end
362
379
 
363
380
  # Dropping a gem the Gemfile requires directly would leave it installed
@@ -303,4 +303,12 @@ module Bundler
303
303
 
304
304
  status_code(41)
305
305
  end
306
+
307
+ class CleanError < BundlerError
308
+ def initialize(errors)
309
+ super("Bundler could not remove some unused files:\n\n#{errors.map(&:message).uniq.join("\n")}")
310
+ end
311
+
312
+ status_code(44)
313
+ end
306
314
  end
@@ -1,8 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "rubygems/text"
4
+
3
5
  module Bundler
4
6
  class Fetcher
5
7
  class Downloader
8
+ include Gem::Text
9
+
6
10
  HTTP_NON_RETRYABLE_ERRORS = [
7
11
  SocketError,
8
12
  Errno::EADDRNOTAVAIL,
@@ -66,13 +70,15 @@ module Bundler
66
70
  end
67
71
  fetch(new_uri, headers, counter + 1)
68
72
  when Gem::Net::HTTPRequestedRangeNotSatisfiable
73
+ raise bad_response(response) unless headers.key?("Range")
74
+
69
75
  new_headers = headers.dup
70
76
  new_headers.delete("Range")
71
77
  fetch(uri, new_headers)
72
78
  when Gem::Net::HTTPRequestEntityTooLarge
73
- raise FallbackError, response.body
79
+ raise FallbackError, clean_text(response.body)
74
80
  when Gem::Net::HTTPTooManyRequests
75
- raise TooManyRequestsError, response.body
81
+ raise TooManyRequestsError, clean_text(response.body)
76
82
  when Gem::Net::HTTPUnauthorized
77
83
  raise BadAuthenticationError, uri.host if uri.userinfo
78
84
  raise AuthenticationRequiredError, uri.host
@@ -81,9 +87,7 @@ module Bundler
81
87
  when Gem::Net::HTTPNotFound
82
88
  raise FallbackError, "Gem::Net::HTTPNotFound: #{filtered_uri}"
83
89
  else
84
- message = "Gem::#{response.class.name.gsub(/\AGem::/, "")}"
85
- message += ": #{response.body}" unless response.body.empty?
86
- raise HTTPError, message
90
+ raise bad_response(response)
87
91
  end
88
92
  end
89
93
 
@@ -121,6 +125,12 @@ module Bundler
121
125
 
122
126
  private
123
127
 
128
+ def bad_response(response)
129
+ message = "Gem::#{response.class.name.gsub(/\AGem::/, "")}"
130
+ message += ": #{clean_text(response.body)}" unless response.body.empty?
131
+ HTTPError.new(message)
132
+ end
133
+
124
134
  def network_down_error(uri, filtered_uri)
125
135
  host = uri.host
126
136
  host_port = "#{host}:#{uri.port}"