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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6be81cd8812d25bec243ccd7e0ebf5c5ca61ff4dbfa3cc312ee38dd5f4199576
4
- data.tar.gz: 44ff77dfafe81511dd56a2c7eb508ecccfcfffca1985aab4a048adeaf063f061
3
+ metadata.gz: be084687aeb1aa75ca642df834adb3f7bdcc2e14c55ce43bf65fc25a1aaa1853
4
+ data.tar.gz: 4c364d06f7396cf773beb868dffdf791a37861a218f6e0129c8631751432804c
5
5
  SHA512:
6
- metadata.gz: 9b8ed99236c76ef3e8c24778dfd06f7c35bb13700b22fab1f025996c712f50517e011323f0bf25066a919b5d5b4c4e685c229227a1210e30134fa8aa259b7d66
7
- data.tar.gz: 4291294d5cee7e331dc8b6626908fa7aeff05bce9379ab59b97a3e0552aaa6c8fb136113151db97105f9e527a541ff1362a5bf14077dd136ed455d46b18d2759
6
+ metadata.gz: eb8154799e4ffbd7558119749d5a8b79b0135784267130879e2b7c98ceb26e4c1542e607f8770b954dd27b3a54c264d21e95a16fb3980365bb5baae71215fae0
7
+ data.tar.gz: d6695fef513f98c355708242238299f8907049aeb796e8de700060256994de5cb0251e4dfa19a1ecbdcc30764e1616edb36e58ea11543d9650bc4ea6d10f30c2
data/bundler.gemspec CHANGED
@@ -42,11 +42,13 @@ Gem::Specification.new do |s|
42
42
  # Bundler reuses RubyGems' vendored URI, SecureRandom and PubGrub, its
43
43
  # pure-Ruby YAML serializer, its shared cooldown setting rules, its compact
44
44
  # index client and its credential store. Ship a copy under lib/rubygems so
45
- # Bundler stays self-contained on RubyGems versions that predate them.
46
- s.files += Dir.glob("lib/rubygems/vendor/uri/**/*", File::FNM_DOTMATCH).reject {|f| File.directory?(f) }
45
+ # Bundler stays self-contained on RubyGems versions that predate them. The
46
+ # URI and YAML serializer entry files stay out, see
47
+ # lib/rubygems/yaml_serializer/core.rb.
48
+ s.files += Dir.glob("lib/rubygems/vendor/uri/**/*", File::FNM_DOTMATCH).reject {|f| File.directory?(f) || f == "lib/rubygems/vendor/uri/lib/uri.rb" }
47
49
  s.files += Dir.glob("lib/rubygems/vendor/securerandom/**/*", File::FNM_DOTMATCH).reject {|f| File.directory?(f) }
48
50
  s.files += Dir.glob("lib/rubygems/vendor/pub_grub/**/*", File::FNM_DOTMATCH).reject {|f| File.directory?(f) }
49
- s.files += Dir.glob("lib/rubygems/yaml_serializer.rb")
51
+ s.files += Dir.glob("lib/rubygems/yaml_serializer/**/*", File::FNM_DOTMATCH).reject {|f| File.directory?(f) }
50
52
  s.files += Dir.glob("lib/rubygems/cooldown_settings.rb")
51
53
  s.files += Dir.glob("lib/rubygems/compact_index_client{.rb,/**/*}", File::FNM_DOTMATCH).reject {|f| File.directory?(f) }
52
54
  s.files += Dir.glob("lib/rubygems/credential_store{.rb,/**/*}", File::FNM_DOTMATCH).reject {|f| File.directory?(f) }
@@ -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-28".freeze
8
- @git_commit_sha = "cd7536a".freeze
7
+ @built_at = "2026-11-25".freeze
8
+ @git_commit_sha = "8a4df2c".freeze
9
9
  # end ivars
10
10
 
11
11
  # A hash representation of the build metadata.
@@ -205,14 +205,25 @@ module Bundler
205
205
  end
206
206
  end
207
207
 
208
+ # A content-addressed row without a digest is an empty entry, like a
209
+ # CHECKSUMS line without one, so it is filled only when a remote fetch
210
+ # can do so (see Definition#empty_checksums_actionable?).
208
211
  def missing?(spec)
209
- @store[spec.full_name].nil?
212
+ return false unless @store[spec.full_name].nil?
213
+
214
+ content_addressed_full_names(spec).empty?
215
+ end
216
+
217
+ def locked?(spec)
218
+ @store[spec.full_name]&.each_value&.any? {|checksum| checksum.sources.any? {|source| source.type == :lock } } || false
210
219
  end
211
220
 
212
221
  def empty?(spec)
213
222
  return false unless spec.source.is_a?(Bundler::Source::Rubygems)
214
223
 
215
- @store[spec.full_name].empty?
224
+ return true if @store[spec.full_name]&.empty?
225
+
226
+ content_addressed_full_names(spec).any? {|full_name| @store[full_name].nil? }
216
227
  end
217
228
 
218
229
  def register(spec, checksum)
@@ -246,6 +257,10 @@ module Bundler
246
257
 
247
258
  private
248
259
 
260
+ def content_addressed_full_names(spec)
261
+ spec.is_a?(LazySpecification) ? spec.content_addressed_full_names : []
262
+ end
263
+
249
264
  def platform_full_name(spec)
250
265
  Gem::NameTuple.new(spec.name, spec.version, spec.platform).full_name
251
266
  end
@@ -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
@@ -63,11 +63,23 @@ module Bundler
63
63
  raise InvalidOption, "Removing all platforms from the bundle is not allowed"
64
64
  end
65
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
+
66
76
  # Adding checksums resolves the bundle to fetch them, so it has to
67
77
  # run after every platform change above has been recorded, or the
68
78
  # new platforms are listed in the lockfile without their specs.
69
79
  definition.add_checksums if options["add-checksums"]
70
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?
71
83
  definition.remotely! unless options[:local]
72
84
 
73
85
  if options["normalize-platforms"]
@@ -308,10 +308,7 @@ module Bundler
308
308
  update_present = active_minor > current_minor if options["filter-minor"]
309
309
 
310
310
  if !update_present && options["filter-patch"] && current_minor == active_minor
311
- current_patch = get_version_semver_portion_value(current_spec, 2)
312
- active_patch = get_version_semver_portion_value(active_spec, 2)
313
-
314
- update_present = active_patch > current_patch
311
+ update_present = active_spec.version > current_spec.version
315
312
  end
316
313
  end
317
314
 
@@ -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
@@ -203,7 +213,8 @@ module Bundler
203
213
  sources.remote!
204
214
  true
205
215
  else
206
- Bundler.settings.set_command_option(:jobs, 1) unless install_needed? # to avoid the overhead of Bundler::Worker
216
+ # A locked local install skips the missing specs check that preloads Git sources.
217
+ preload_git_sources if options[:local] && no_resolve_needed?
207
218
  sources.local!
208
219
  false
209
220
  end
@@ -370,6 +381,7 @@ module Bundler
370
381
  start_resolution
371
382
  end
372
383
  warn_inert_overrides(@resolve)
384
+ @resolve.assign_content_addresses!(@ruby_abis, local: sources.local_mode?) if @removed_ruby_abis.any?
373
385
  @resolve
374
386
  end
375
387
 
@@ -543,6 +555,32 @@ module Bundler
543
555
  resolve.normalize_platforms!(current_dependencies, platforms)
544
556
 
545
557
  @resolve = SpecSet.new(resolve.for(current_dependencies, @platforms))
558
+ @resolve.assign_content_addresses!(@ruby_abis, normalize: true)
559
+ end
560
+
561
+ def ruby_abis
562
+ return [] unless content_addressing_supported? || content_addresses_carried_over?
563
+
564
+ @ruby_abis.sort_by {|ruby_abi| Gem::Version.new(ruby_abi) }
565
+ end
566
+
567
+ def add_ruby_abi(ruby_abi)
568
+ ensure_content_addressing_supported!
569
+ if @ruby_version && ruby_abi_excluded?(ruby_abi)
570
+ raise InvalidOption, "Unable to add the Ruby ABI `#{ruby_abi}` since your Gemfile requires #{@ruby_version}"
571
+ end
572
+ return if @locked_ruby_abis.include?(ruby_abi) || @new_ruby_abis.include?(ruby_abi)
573
+
574
+ @new_ruby_abis << ruby_abi
575
+ @ruby_abis |= [ruby_abi]
576
+ end
577
+
578
+ def remove_ruby_abi(ruby_abi)
579
+ ensure_content_addressing_supported!
580
+ 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)
581
+
582
+ @removed_ruby_abis << ruby_abi
583
+ @ruby_abis.delete(ruby_abi)
546
584
  end
547
585
 
548
586
  def add_platform(platform)
@@ -601,6 +639,8 @@ module Bundler
601
639
 
602
640
  added.concat @new_platforms.map {|p| "* platform: #{p}" }
603
641
  deleted.concat @removed_platforms.map {|p| "* platform: #{p}" }
642
+ added.concat @new_ruby_abis.map {|abi| "* ruby abi: #{abi}" }
643
+ deleted.concat @removed_ruby_abis.map {|abi| "* ruby abi: #{abi}" }
604
644
 
605
645
  added.concat new_deps.map {|d| "* #{pretty_dep(d)}" } if new_deps.any?
606
646
  deleted.concat deleted_deps.map {|d| "* #{pretty_dep(d)}" } if deleted_deps.any?
@@ -660,6 +700,9 @@ module Bundler
660
700
  @dependency_changes ||
661
701
  @current_platform_missing ||
662
702
  @new_platforms.any? ||
703
+ @current_ruby_abi_missing ||
704
+ @new_ruby_abis.any? ||
705
+ @excluded_ruby_abis.any? ||
663
706
  @path_changes ||
664
707
  @local_changes ||
665
708
  @missing_lockfile_dep ||
@@ -787,7 +830,9 @@ module Bundler
787
830
  loop do
788
831
  break if incomplete_specs.empty?
789
832
 
790
- Bundler.ui.debug("The lockfile does not have all gems needed for the current platform though, Bundler will still re-resolve dependencies")
833
+ Bundler.ui.debug("The lockfile does not have all gems needed for the current platform (#{Bundler.local_platform}) though, " \
834
+ "Bundler will still re-resolve dependencies. The following locked gems could not be materialized for it: " \
835
+ "#{incomplete_specs.map(&:full_name).join(", ")}")
791
836
  sources.remote!
792
837
  reresolve_without(incomplete_specs)
793
838
  specs = resolve.materialize(dependencies)
@@ -801,6 +846,8 @@ module Bundler
801
846
  incomplete_specs = still_incomplete_specs
802
847
  end
803
848
 
849
+ check_content_address_fallback_checksums!(specs)
850
+
804
851
  insecurely_materialized_specs = resolve.insecurely_materialized_specs
805
852
 
806
853
  if insecurely_materialized_specs.any?
@@ -816,6 +863,26 @@ module Bundler
816
863
  specs
817
864
  end
818
865
 
866
+ # The lockfile writes no CHECKSUMS entry for a platform gem it locks only
867
+ # content-addressed gems of, so nothing would verify the platform gem a
868
+ # frozen bundle falls back to under a Ruby ABI the lockfile does not cover.
869
+ def check_content_address_fallback_checksums!(specs)
870
+ return unless Bundler.frozen_bundle? && @locked_checksums
871
+
872
+ unchecksummed_specs = specs.select do |spec|
873
+ !spec.is_a?(StubSpecification) &&
874
+ !Gem::ContentAddress.content_addressed?(spec, validate_ruby_abi: false) &&
875
+ resolve[spec.name].any? {|locked_spec| locked_spec.content_addresses.any? } &&
876
+ !spec.source.checksum_store.locked?(spec)
877
+ end
878
+ return if unchecksummed_specs.empty?
879
+
880
+ raise ProductionError, "Your lockfile has no checksum for #{unchecksummed_specs.map(&:full_name).join(", ")}, " \
881
+ "which would be installed in place of the content-addressed gems it locks, " \
882
+ "but frozen mode is set.\n\n" \
883
+ "Run `bundle install` elsewhere and add the updated Gemfile.lock to version control."
884
+ end
885
+
819
886
  def reresolve_without(incomplete_specs)
820
887
  resolution_base.delete(incomplete_specs)
821
888
  @resolve = start_resolution
@@ -832,10 +899,10 @@ module Bundler
832
899
  @resolved_bundler_version = result.find {|spec| spec.name == "bundler" }&.version
833
900
 
834
901
  @new_platforms.each do |platform|
835
- incomplete_specs = result.incomplete_specs_for_platform(current_dependencies, platform)
902
+ incomplete_specs = result.incomplete_specs_for_platform(dependencies, platform)
836
903
 
837
904
  if incomplete_specs.any?
838
- resolver.raise_incomplete! incomplete_specs
905
+ resolver.raise_incomplete! incomplete_specs, platform
839
906
  end
840
907
  end
841
908
 
@@ -848,12 +915,27 @@ module Bundler
848
915
  end
849
916
 
850
917
  if should_add_extra_platforms?
851
- result.add_extra_platforms!(platforms)
918
+ result.add_extra_platforms!(platforms, prefer_local: @prefer_local)
852
919
  elsif @originally_invalid_platforms.any?
853
920
  result.add_originally_invalid_platforms!(platforms, @originally_invalid_platforms)
854
921
  end
855
922
 
856
- SpecSet.new(result.for(dependencies, @platforms | [Gem::Platform::RUBY]))
923
+ specs = SpecSet.new(result.for(dependencies, @platforms | [Gem::Platform::RUBY]))
924
+ specs.assign_content_addresses!(@ruby_abis, local: sources.local_mode?)
925
+
926
+ if sources.local_mode?
927
+ # Only installed gems are in reach, so a Ruby is recorded once every row
928
+ # has its gem; the running Ruby otherwise waits for the next online resolution.
929
+ @ruby_abis.delete(Gem.ruby_abi) if @current_ruby_abi_missing && !specs.content_addresses_cover?(Gem.ruby_abi)
930
+
931
+ @new_ruby_abis.each do |ruby_abi|
932
+ next if specs.content_addresses_cover?(ruby_abi)
933
+
934
+ raise GemNotFound, "Could not find content-addressed gems for Ruby ABI #{ruby_abi} in locally installed gems"
935
+ end
936
+ end
937
+
938
+ specs
857
939
  end
858
940
 
859
941
  def precompute_source_requirements_for_indirect_dependencies?
@@ -894,6 +976,66 @@ module Bundler
894
976
  true
895
977
  end
896
978
 
979
+ def add_current_ruby_abi
980
+ return unless content_addressing_supported?
981
+ return if @ruby_abis.include?(Gem.ruby_abi)
982
+
983
+ @ruby_abis << Gem.ruby_abi
984
+ @locked_specs.any? {|spec| spec.content_addresses.any? }
985
+ end
986
+
987
+ # RubyGems before 4.1 can't lock content-addressed gems, so changing the
988
+ # locked Ruby ABIs there would leave CONTENT ADDRESSES out of step with them.
989
+ def content_addressing_supported?
990
+ Bundler.rubygems.provides?(">= 4.1.0.a")
991
+ end
992
+
993
+ def ensure_content_addressing_supported!
994
+ return if content_addressing_supported?
995
+
996
+ raise InvalidOption, "Changing the Ruby ABIs in the lockfile requires RubyGems 4.1.0 or later, but you are using RubyGems #{Bundler.rubygems.version}"
997
+ end
998
+
999
+ # Older RubyGems resolves platform gems without the content addresses the
1000
+ # lockfile had for them, and may swap a locked one for its ruby variant. Unless
1001
+ # every platform gem comes through as locked, the lockfile then drops its Ruby
1002
+ # ABIs, so that RubyGems 4.1 resolves again and records the content addresses
1003
+ # instead of falling back.
1004
+ def content_addresses_carried_over?
1005
+ locked = @originally_locked_specs.select {|spec| spec.platform != Gem::Platform::RUBY && resolve[spec.name].any? }
1006
+ resolved = resolve.select {|spec| spec.platform != Gem::Platform::RUBY }
1007
+
1008
+ locked.to_h {|spec| [spec.full_name, spec.content_addresses] } == resolved.to_h {|spec| [spec.full_name, spec.content_addresses] }
1009
+ end
1010
+
1011
+ def ruby_abi_excluded?(ruby_abi)
1012
+ comparators = Gem::Requirement.new(@ruby_version.versions).requirements +
1013
+ Gem::ContentAddress.ruby_abi_requirement(ruby_abi).requirements
1014
+
1015
+ lower = []
1016
+ upper = []
1017
+ comparators.each do |op, version|
1018
+ case op
1019
+ when ">=" then lower << [version, true]
1020
+ when ">" then lower << [version, false]
1021
+ when "<=" then upper << [version, true]
1022
+ when "<" then upper << [version, false]
1023
+ when "="
1024
+ lower << [version, true]
1025
+ upper << [version, true]
1026
+ when "~>"
1027
+ lower << [version, true]
1028
+ upper << [Gem::Version.new("#{version.bump}.A"), false]
1029
+ end
1030
+ end
1031
+ return false if lower.empty? || upper.empty?
1032
+
1033
+ min, min_inclusive = lower.max_by {|version, inclusive| [version, inclusive ? 0 : 1] }
1034
+ max, max_inclusive = upper.min_by {|version, inclusive| [version, inclusive ? 1 : 0] }
1035
+
1036
+ min > max || (min == max && !(min_inclusive && max_inclusive))
1037
+ end
1038
+
897
1039
  def find_most_specific_locked_platform
898
1040
  return unless current_platform_locked?
899
1041
 
@@ -948,6 +1090,9 @@ module Bundler
948
1090
  [@dependency_changes, "the dependencies in your gemfile changed"],
949
1091
  [@current_platform_missing, "your lockfile is missing the current platform"],
950
1092
  [@new_platforms.any?, "you are adding a new platform to your lockfile"],
1093
+ [@new_ruby_abis.any?, "you are adding a new Ruby ABI to your lockfile"],
1094
+ [@current_ruby_abi_missing, "your lockfile does not cover the current Ruby ABI"],
1095
+ [@excluded_ruby_abis.any?, "your Gemfile's ruby directive rules out Ruby ABIs in your lockfile"],
951
1096
  [@path_changes, "the gemspecs for path gems changed"],
952
1097
  [@local_changes, "the gemspecs for git local gems changed"],
953
1098
  [@missing_lockfile_dep, "your lockfile is missing \"#{@missing_lockfile_dep}\""],
@@ -106,8 +106,8 @@ module Bundler
106
106
  @expanded_platforms ||= platforms.filter_map {|pl| CurrentRuby::PLATFORM_MAP[pl] }.flatten.uniq
107
107
  end
108
108
 
109
- def should_include?
110
- should_include && current_env? && current_platform?
109
+ def should_include?(platform = nil)
110
+ should_include && current_env? && (platform ? matches_platform?(platform) : current_platform?)
111
111
  end
112
112
 
113
113
  def gemspec_dev_dep?
@@ -151,5 +151,20 @@ module Bundler
151
151
  rescue NoMethodError
152
152
  requirement != ">= 0"
153
153
  end
154
+
155
+ private
156
+
157
+ def matches_platform?(platform)
158
+ return true if platforms.empty?
159
+
160
+ generic = Gem::Platform.generic(platform)
161
+ platforms.any? do |name|
162
+ next false unless [CurrentRuby::PLATFORM_MAP[name]].flatten.include?(generic)
163
+ next Bundler.current_ruby.public_send("#{name}?") if generic == Bundler.generic_local_platform
164
+
165
+ version = name.to_s[/_(\d+)\z/, 1]
166
+ !version || Bundler.current_ruby.public_send("on_#{version}?")
167
+ end
168
+ end
154
169
  end
155
170
  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}"
@@ -456,12 +460,15 @@ module Bundler
456
460
  end
457
461
 
458
462
  def with_gemfile(gemfile)
463
+ previous_evaluating_gemfile = Thread.current[:bundler_evaluating_gemfile]
459
464
  expanded_gemfile_path = Pathname.new(gemfile).expand_path(@gemfile&.parent)
460
465
  original_gemfile = @gemfile
461
466
  @gemfile = expanded_gemfile_path
462
467
  @gemfiles << expanded_gemfile_path
468
+ Thread.current[:bundler_evaluating_gemfile] = @gemfile
463
469
  yield @gemfile.to_s
464
470
  ensure
471
+ Thread.current[:bundler_evaluating_gemfile] = previous_evaluating_gemfile
465
472
  @gemfile = original_gemfile
466
473
  end
467
474
 
@@ -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,
@@ -72,9 +76,9 @@ module Bundler
72
76
  new_headers.delete("Range")
73
77
  fetch(uri, new_headers)
74
78
  when Gem::Net::HTTPRequestEntityTooLarge
75
- raise FallbackError, response.body
79
+ raise FallbackError, clean_text(response.body)
76
80
  when Gem::Net::HTTPTooManyRequests
77
- raise TooManyRequestsError, response.body
81
+ raise TooManyRequestsError, clean_text(response.body)
78
82
  when Gem::Net::HTTPUnauthorized
79
83
  raise BadAuthenticationError, uri.host if uri.userinfo
80
84
  raise AuthenticationRequiredError, uri.host
@@ -123,7 +127,7 @@ module Bundler
123
127
 
124
128
  def bad_response(response)
125
129
  message = "Gem::#{response.class.name.gsub(/\AGem::/, "")}"
126
- message += ": #{response.body}" unless response.body.empty?
130
+ message += ": #{clean_text(response.body)}" unless response.body.empty?
127
131
  HTTPError.new(message)
128
132
  end
129
133
 
data/lib/bundler/index.rb CHANGED
@@ -188,8 +188,13 @@ module Bundler
188
188
  EMPTY_SEARCH = [].freeze
189
189
 
190
190
  def search_by_spec(spec)
191
- spec = find_by_spec(spec)
192
- spec ? [spec] : EMPTY_SEARCH
191
+ specs_by_name = @specs[spec.name]
192
+ return EMPTY_SEARCH unless specs_by_name
193
+
194
+ full_names = [spec.full_name]
195
+ full_names.concat(spec.content_addressed_full_names) if spec.is_a?(LazySpecification)
196
+
197
+ full_names.filter_map {|full_name| specs_by_name[full_name] }
193
198
  end
194
199
 
195
200
  def find_by_spec(spec)
@@ -41,7 +41,7 @@ module Bundler
41
41
 
42
42
  # resolve to see if the new deps broke anything
43
43
  @definition = builder.to_definition(lockfile_path, {})
44
- @definition.remotely!
44
+ @definition.resolve_remotely!
45
45
 
46
46
  # since nothing broke, we can add those gems to the gemfile
47
47
  append_to(gemfile_path, build_gem_lines(@options[:conservative_versioning])) if @deps.any?
@@ -57,7 +57,8 @@ def gemfile(force_latest_compatible = false, options = {}, &gemfile)
57
57
  builder = Bundler::Dsl.new
58
58
  builder.instance_eval(&gemfile)
59
59
 
60
- Bundler.settings.temporary(deployment: false, frozen: false) do
60
+ settings = Bundler.settings
61
+ settings.temporary(deployment: false, frozen: false) do
61
62
  definition = builder.to_definition(nil, true)
62
63
  definition.validate_runtime!
63
64
 
@@ -72,19 +73,27 @@ def gemfile(force_latest_compatible = false, options = {}, &gemfile)
72
73
  end
73
74
 
74
75
  # When possible we do the install in a subprocess because to install
75
- # gems we need to require some default gems like `securerandom` etc
76
+ # gems we need to require some default gems like `tempfile` etc
76
77
  # which may later conflict with the Gemfile requirements.
77
78
  installed_in_fork = false
78
79
  if Process.respond_to?(:fork)
79
80
  Gem.load_yaml # Avoid NameError on Ruby 3.2's safe_yaml.rb after Gem::Specification.reset
80
- _, status = Process.waitpid2(Process.fork do
81
- $VERBOSE = nil
82
- do_install.call end)
83
- exit(status.exitstatus || status.to_i) unless status.success?
84
-
85
- installed_in_fork = true
81
+ # exit! leaves the script's at_exit hooks to this process, which installs again on failure to raise the error here
82
+ pid = Process.fork do
83
+ $VERBOSE = nil
84
+ do_install.call
85
+ $stdout.flush
86
+ $stderr.flush
87
+ exit!(true)
88
+ rescue Exception # rubocop:disable Lint/RescueException
89
+ exit!(false)
90
+ end
91
+ installed_in_fork = Process.waitpid2(pid).last.success?
92
+ end
86
93
 
94
+ if installed_in_fork
87
95
  Bundler.reset!
96
+ Bundler.instance_variable_set(:@settings, settings)
88
97
  Gem::Specification.reset
89
98
  Bundler.instance_variable_set(:@bundle_path, Pathname.new(Gem.dir))
90
99
 
@@ -110,7 +119,8 @@ def gemfile(force_latest_compatible = false, options = {}, &gemfile)
110
119
  configure_forked_definition.call(definition) if installed_in_fork
111
120
 
112
121
  begin
113
- runtime = Bundler::Runtime.new(nil, definition).setup
122
+ runtime = Bundler::Runtime.new(nil, definition)
123
+ installed_in_fork ? Bundler.ui.silence { runtime.setup } : runtime.setup
114
124
  rescue Gem::LoadError => e
115
125
  name = e.name
116
126
  version = e.requirement.requirements.first[1]