rubygems-update 4.1.0 → 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 (44) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +46 -0
  3. data/Manifest.txt +6 -0
  4. data/bundler.gemspec +5 -3
  5. data/lib/bundler/build_metadata.rb +2 -2
  6. data/lib/bundler/checksum.rb +15 -6
  7. data/lib/bundler/cli/outdated.rb +1 -4
  8. data/lib/bundler/definition.rb +27 -4
  9. data/lib/bundler/dependency.rb +17 -2
  10. data/lib/bundler/dsl.rb +3 -0
  11. data/lib/bundler/injector.rb +1 -1
  12. data/lib/bundler/inline.rb +3 -1
  13. data/lib/bundler/lazy_specification.rb +4 -0
  14. data/lib/bundler/man/bundle-lock.1 +1 -1
  15. data/lib/bundler/man/bundle-lock.1.ronn +5 -1
  16. data/lib/bundler/match_remote_metadata.rb +6 -0
  17. data/lib/bundler/plugin/index.rb +14 -11
  18. data/lib/bundler/remote_specification.rb +5 -0
  19. data/lib/bundler/resolver/candidate.rb +5 -0
  20. data/lib/bundler/resolver.rb +87 -7
  21. data/lib/bundler/rubygems_ext.rb +13 -0
  22. data/lib/bundler/runtime.rb +5 -1
  23. data/lib/bundler/settings.rb +2 -3
  24. data/lib/bundler/spec_set.rb +28 -7
  25. data/lib/bundler/vendored_securerandom.rb +5 -2
  26. data/lib/bundler/vendored_uri.rb +18 -3
  27. data/lib/bundler/version.rb +1 -1
  28. data/lib/rubygems/commands/push_command.rb +3 -1
  29. data/lib/rubygems/core_ext/tcpsocket_init.rb +2 -2
  30. data/lib/rubygems/doctor.rb +1 -0
  31. data/lib/rubygems/installer.rb +23 -19
  32. data/lib/rubygems/package/old.rb +2 -2
  33. data/lib/rubygems/package.rb +45 -12
  34. data/lib/rubygems/request_set.rb +1 -3
  35. data/lib/rubygems/vendor/pub_grub/lib/pub_grub/term.rb +1 -1
  36. data/lib/rubygems/yaml_serializer/builder.rb +261 -0
  37. data/lib/rubygems/yaml_serializer/core.rb +41 -0
  38. data/lib/rubygems/yaml_serializer/emitter.rb +197 -0
  39. data/lib/rubygems/yaml_serializer/nodes.rb +10 -0
  40. data/lib/rubygems/yaml_serializer/parser.rb +531 -0
  41. data/lib/rubygems/yaml_serializer/psych_errors.rb +11 -0
  42. data/lib/rubygems/yaml_serializer.rb +1 -988
  43. data/lib/rubygems.rb +1 -1
  44. metadata +8 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c879666cb1c4a2400671c7cbb29953f2fbbae02e3f9eaa7a38e125727eef844
4
- data.tar.gz: 18e7a85d0ceed52d86672bb48642d2a8cc6dec5cabf2cf16744cfc6b50e6bf31
3
+ metadata.gz: fa3262a330bd98c74075d9e2d769d4cedad971f029046984950a7258379486fc
4
+ data.tar.gz: b75f6aca6e24276ae53670e21b9f76f4825ad423ceb74a86289b7937638983ca
5
5
  SHA512:
6
- metadata.gz: c6f491d00d0e92237aec539d6bc24f49c7ccf8580266ecb721f97553965520fe90992715f11cdfc165eb35f60391043beb29a8c00e9ceb5ff1b301cafe86574f
7
- data.tar.gz: da61e6c25fdf2e78293eb00b9afcff9dadd51d6bf49607167efcebe062b9ff82b86874548eb5c323c68fe18190b7f2a684bd77541ef4f703f19c9195e99c1219
6
+ metadata.gz: da834de19b8ef94f9f76cfeb6a48a2af5685cdb8e8ca7a9515dafafae39c2634fbe5d183413489b0bff25cb6c5ba445450653fb21cc6d8b48355db038a4a57cb
7
+ data.tar.gz: c3e707d4af5f0582303e849369de8e0f4367d40c4e4d6b3c4139b7d32084264870a84edbb9ea62059fef0185f116dcb7ea9a30881fb19a6405d7f11b22f17f3f
data/CHANGELOG.md CHANGED
@@ -2,6 +2,52 @@
2
2
 
3
3
  Bundler's changelog before 4.0.0, when it was versioned separately from RubyGems, is in [doc/CHANGELOG-bundler-2.x.md](https://github.com/ruby/rubygems/blob/master/doc/CHANGELOG-bundler-2.x.md).
4
4
 
5
+ ## 4.1.1 / 2026-11-25
6
+
7
+ ### RubyGems
8
+
9
+ #### Enhancements:
10
+
11
+ * Installs bundler 4.1.1 as a default gem.
12
+
13
+ #### Bug fixes:
14
+
15
+ * Fix file permissions during gem extraction. Pull request [#10128](https://github.com/ruby/rubygems/pull/10128) by Hiroshi SHIBATA
16
+ * Resolve chained symlink targets before creating them during extraction. Pull request [#10119](https://github.com/ruby/rubygems/pull/10119) by Hiroshi SHIBATA
17
+ * Keep negative any terms when PubGrub resolves conflicts. Pull request [#10112](https://github.com/ruby/rubygems/pull/10112) by Hiroshi SHIBATA
18
+ * Serialize concurrent installs of the same gem. Pull request [#10107](https://github.com/ruby/rubygems/pull/10107) by Hiroshi SHIBATA
19
+ * Keep resolved prereleases when sorting install requests. Pull request [#10100](https://github.com/ruby/rubygems/pull/10100) by Hiroshi SHIBATA
20
+ * Forward keyword arguments in the IPv4 fallback TCPSocket#initialize. Pull request [#10098](https://github.com/ruby/rubygems/pull/10098) by Hiroshi SHIBATA
21
+ * Push attestations with non-ASCII bytes on Ruby 3.2 and 3.3. Pull request [#10097](https://github.com/ruby/rubygems/pull/10097) by Hiroshi SHIBATA
22
+ * Gem::YAMLSerializer::Parser only reads the first document of a YAML stream. Pull request [#10088](https://github.com/ruby/rubygems/pull/10088) by Ben Sheldon and Hiroshi SHIBATA
23
+
24
+ ### Bundler
25
+
26
+ #### Bug fixes:
27
+
28
+ * Assign the specs missing from the shard list to shard_d. Pull request [#10127](https://github.com/ruby/rubygems/pull/10127) by Hiroshi SHIBATA
29
+ * Require a digest on every content-addressed row of a checksummed lockfile. Pull request [#10122](https://github.com/ruby/rubygems/pull/10122) by Hiroshi SHIBATA
30
+ * Keep frozen installs to gems the lockfile covers for content-addressed rows. Pull request [#10120](https://github.com/ruby/rubygems/pull/10120) by Hiroshi SHIBATA
31
+ * Stop shipping the URI and YAML serializer entry files in the Bundler gem. Pull request [#10113](https://github.com/ruby/rubygems/pull/10113) by Hiroshi SHIBATA
32
+ * Keep negative any terms when PubGrub resolves conflicts. Pull request [#10112](https://github.com/ruby/rubygems/pull/10112) by Hiroshi SHIBATA
33
+ * Check gem requirements when locking from legacy indexes. Pull request [#10111](https://github.com/ruby/rubygems/pull/10111) by Hiroshi SHIBATA
34
+ * Retry resolution with transitive prereleases. Pull request [#10110](https://github.com/ruby/rubygems/pull/10110) by Hiroshi SHIBATA
35
+ * Explain activation conflicts caused by a Gemfile require. Pull request [#10109](https://github.com/ruby/rubygems/pull/10109) by Hiroshi SHIBATA
36
+ * Allow full updates to downgrade a yanked gem. Pull request [#10106](https://github.com/ruby/rubygems/pull/10106) by Hiroshi SHIBATA
37
+ * Honor `--prefer-local` when locking platform variants. Pull request [#10108](https://github.com/ruby/rubygems/pull/10108) by Hiroshi SHIBATA
38
+ * Honor `--jobs` when installing from `vendor/cache`. Pull request [#10102](https://github.com/ruby/rubygems/pull/10102) by Hiroshi SHIBATA
39
+ * Allow `bundle lock --add-platform` to add native platforms from JRuby. Pull request [#10105](https://github.com/ruby/rubygems/pull/10105) by Hiroshi SHIBATA
40
+ * Show fourth-segment and prerelease updates in `bundle outdated --filter-patch`. Pull request [#10103](https://github.com/ruby/rubygems/pull/10103) by Hiroshi SHIBATA
41
+ * Preserve inline settings after a forked install. Pull request [#10099](https://github.com/ruby/rubygems/pull/10099) by Hiroshi SHIBATA
42
+ * Resolve dependencies before `bundle add` updates the Gemfile. Pull request [#10101](https://github.com/ruby/rubygems/pull/10101) by Hiroshi SHIBATA
43
+ * Keep mirror settings readable by Bundler 4.0. Pull request [#10075](https://github.com/ruby/rubygems/pull/10075) by Paul Wille
44
+ * Fix Gem::URI redefinition warnings on older RubyGems. Pull request [#10074](https://github.com/ruby/rubygems/pull/10074) by Paul Wille and Hiroshi SHIBATA
45
+ * Read plugin index sections that are not hashes as empty. Pull request [#10076](https://github.com/ruby/rubygems/pull/10076) by Hiroshi SHIBATA
46
+
47
+ #### Documentation:
48
+
49
+ * Document that bundle lock --add-checksums leaves entries for uninstalled gems empty. Pull request [#10121](https://github.com/ruby/rubygems/pull/10121) by Hiroshi SHIBATA
50
+
5
51
  ## 4.1.0 / 2026-11-16
6
52
 
7
53
  ### RubyGems
data/Manifest.txt CHANGED
@@ -565,5 +565,11 @@ lib/rubygems/version.rb
565
565
  lib/rubygems/version_option.rb
566
566
  lib/rubygems/win_platform.rb
567
567
  lib/rubygems/yaml_serializer.rb
568
+ lib/rubygems/yaml_serializer/builder.rb
569
+ lib/rubygems/yaml_serializer/core.rb
570
+ lib/rubygems/yaml_serializer/emitter.rb
571
+ lib/rubygems/yaml_serializer/nodes.rb
572
+ lib/rubygems/yaml_serializer/parser.rb
573
+ lib/rubygems/yaml_serializer/psych_errors.rb
568
574
  rubygems-update.gemspec
569
575
  setup.rb
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-11-16".freeze
8
- @git_commit_sha = "9af9267".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,20 +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
212
  return false unless @store[spec.full_name].nil?
210
213
 
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
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
216
219
  end
217
220
 
218
221
  def empty?(spec)
219
222
  return false unless spec.source.is_a?(Bundler::Source::Rubygems)
220
223
 
221
- @store[spec.full_name]&.empty? || false
224
+ return true if @store[spec.full_name]&.empty?
225
+
226
+ content_addressed_full_names(spec).any? {|full_name| @store[full_name].nil? }
222
227
  end
223
228
 
224
229
  def register(spec, checksum)
@@ -252,6 +257,10 @@ module Bundler
252
257
 
253
258
  private
254
259
 
260
+ def content_addressed_full_names(spec)
261
+ spec.is_a?(LazySpecification) ? spec.content_addressed_full_names : []
262
+ end
263
+
255
264
  def platform_full_name(spec)
256
265
  Gem::NameTuple.new(spec.name, spec.version, spec.platform).full_name
257
266
  end
@@ -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
 
@@ -213,7 +213,8 @@ module Bundler
213
213
  sources.remote!
214
214
  true
215
215
  else
216
- 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?
217
218
  sources.local!
218
219
  false
219
220
  end
@@ -845,6 +846,8 @@ module Bundler
845
846
  incomplete_specs = still_incomplete_specs
846
847
  end
847
848
 
849
+ check_content_address_fallback_checksums!(specs)
850
+
848
851
  insecurely_materialized_specs = resolve.insecurely_materialized_specs
849
852
 
850
853
  if insecurely_materialized_specs.any?
@@ -860,6 +863,26 @@ module Bundler
860
863
  specs
861
864
  end
862
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
+
863
886
  def reresolve_without(incomplete_specs)
864
887
  resolution_base.delete(incomplete_specs)
865
888
  @resolve = start_resolution
@@ -876,10 +899,10 @@ module Bundler
876
899
  @resolved_bundler_version = result.find {|spec| spec.name == "bundler" }&.version
877
900
 
878
901
  @new_platforms.each do |platform|
879
- incomplete_specs = result.incomplete_specs_for_platform(current_dependencies, platform)
902
+ incomplete_specs = result.incomplete_specs_for_platform(dependencies, platform)
880
903
 
881
904
  if incomplete_specs.any?
882
- resolver.raise_incomplete! incomplete_specs
905
+ resolver.raise_incomplete! incomplete_specs, platform
883
906
  end
884
907
  end
885
908
 
@@ -892,7 +915,7 @@ module Bundler
892
915
  end
893
916
 
894
917
  if should_add_extra_platforms?
895
- result.add_extra_platforms!(platforms)
918
+ result.add_extra_platforms!(platforms, prefer_local: @prefer_local)
896
919
  elsif @originally_invalid_platforms.any?
897
920
  result.add_originally_invalid_platforms!(platforms, @originally_invalid_platforms)
898
921
  end
@@ -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
@@ -460,12 +460,15 @@ module Bundler
460
460
  end
461
461
 
462
462
  def with_gemfile(gemfile)
463
+ previous_evaluating_gemfile = Thread.current[:bundler_evaluating_gemfile]
463
464
  expanded_gemfile_path = Pathname.new(gemfile).expand_path(@gemfile&.parent)
464
465
  original_gemfile = @gemfile
465
466
  @gemfile = expanded_gemfile_path
466
467
  @gemfiles << expanded_gemfile_path
468
+ Thread.current[:bundler_evaluating_gemfile] = @gemfile
467
469
  yield @gemfile.to_s
468
470
  ensure
471
+ Thread.current[:bundler_evaluating_gemfile] = previous_evaluating_gemfile
469
472
  @gemfile = original_gemfile
470
473
  end
471
474
 
@@ -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
 
@@ -92,6 +93,7 @@ def gemfile(force_latest_compatible = false, options = {}, &gemfile)
92
93
 
93
94
  if installed_in_fork
94
95
  Bundler.reset!
96
+ Bundler.instance_variable_set(:@settings, settings)
95
97
  Gem::Specification.reset
96
98
  Bundler.instance_variable_set(:@bundle_path, Pathname.new(Gem.dir))
97
99
 
@@ -209,8 +209,12 @@ module Bundler
209
209
  # Try platforms in order of preference until finding a compatible spec.
210
210
  # Used for legacy lockfiles and as a fallback when the exact locked spec
211
211
  # is incompatible. Falls back to frozen bundle behavior if none match.
212
+ #
213
+ # Restricting the candidate platforms is not enough to keep a frozen bundle
214
+ # to the locked platforms, since a ruby gem is installable on any of them.
212
215
  def resolve_best_platform(specs, locked_platforms: nil)
213
216
  specs = MatchPlatform.select_all_content_address_match(specs, content_addresses)
217
+ specs = specs.select {|spec| locked_platforms.include?(spec.platform) } if locked_platforms
214
218
 
215
219
  find_compatible_platform_spec(specs, locked_platforms: locked_platforms) || frozen_bundle_fallback(specs)
216
220
  end
@@ -31,7 +31,7 @@ Fall back to using the single\-file index of all gems\.
31
31
  Use the specified gemfile instead of [\fBGemfile(5)\fR][Gemfile(5)]\.
32
32
  .TP
33
33
  \fB\-\-add\-checksums\fR
34
- Add checksums to the lockfile\.
34
+ Add checksums to the lockfile\. Checksums are taken from the source's index, or computed from the \fB\.gem\fR file of a gem installed on this machine\. With a source that does not publish checksums, entries for gems not installed here, such as gems for other platforms or content\-addressed gems for other Ruby ABIs, stay empty, and frozen installs reject them\.
35
35
  .TP
36
36
  \fB\-\-add\-platform=<list>\fR
37
37
  Add a new platform to the lockfile, re\-resolving for the addition of that platform\.
@@ -58,7 +58,11 @@ Lock the gems specified in Gemfile.
58
58
  Use the specified gemfile instead of [`Gemfile(5)`][Gemfile(5)].
59
59
 
60
60
  * `--add-checksums`:
61
- Add checksums to the lockfile.
61
+ Add checksums to the lockfile. Checksums are taken from the source's index,
62
+ or computed from the `.gem` file of a gem installed on this machine. With a
63
+ source that does not publish checksums, entries for gems not installed here,
64
+ such as gems for other platforms or content-addressed gems for other Ruby
65
+ ABIs, stay empty, and frozen installs reject them.
62
66
 
63
67
  * `--add-platform=<list>`:
64
68
  Add a new platform to the lockfile, re-resolving for the addition of that
@@ -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
@@ -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
 
@@ -620,6 +683,13 @@ module Bundler
620
683
  versions = versions_for(dep_package, dep_range)
621
684
  end
622
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
+
623
693
  if versions.empty? && select_all_versions(dep_package, dep_range).any?
624
694
  raise_all_versions_filtered_out!(dep_package)
625
695
  end
@@ -632,6 +702,16 @@ module Bundler
632
702
  end.to_h
633
703
  end
634
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
+
635
715
  def select_all_versions(package, range)
636
716
  range.select_versions(@all_versions[package])
637
717
  end
@@ -280,6 +280,19 @@ module Gem
280
280
 
281
281
  prepend AllowSettingSource
282
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
+
283
296
  alias_method :rg_full_gem_path, :full_gem_path
284
297
  alias_method :rg_loaded_from, :loaded_from
285
298