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
@@ -79,6 +79,90 @@ Describe subcommands or one specific subcommand.
79
79
 
80
80
  No options.
81
81
 
82
+ ## HOOKS
83
+
84
+ A plugin can run code at defined points of Bundler's work by registering a
85
+ hook. In the plugin's `plugins.rb`, pass one of the event constants of
86
+ `Bundler::Plugin::Events` and a block to `Bundler::Plugin::API.hook`. Bundler
87
+ loads a plugin that registers a hook for an event when that event fires, and
88
+ calls the block with the arguments listed for the event below.
89
+
90
+ Bundler::Plugin::API.hook Bundler::Plugin::Events::GEM_BEFORE_INSTALL_ALL do |dependencies|
91
+ puts "about to install #{dependencies.map(&:name).join(", ")}"
92
+ end
93
+
94
+ The events fire in the order listed here.
95
+
96
+ **GEMFILE EVALUATION**
97
+
98
+ * `GEM_BEFORE_EVAL` (`before-eval`):
99
+ Called before the Gemfile is evaluated, with the path to the Gemfile and
100
+ the path to the lockfile (`nil` when there is no lockfile).
101
+
102
+ * `GEM_AFTER_EVAL` (`after-eval`):
103
+ Called after the Gemfile is evaluated, with the resulting
104
+ `Bundler::Definition`.
105
+
106
+ **INSTALLATION**
107
+
108
+ * `GEM_BEFORE_INSTALL_ALL` (`before-install-all`):
109
+ Called before any gem is installed, with an Array of the
110
+ `Bundler::Dependency` objects declared in the Gemfile.
111
+
112
+ * `GEM_BEFORE_FETCH` (`before-fetch`):
113
+ Called before each individual gem is downloaded from a remote source, with
114
+ a spec-like object responding to the `Gem::Specification` API (for example
115
+ a `Bundler::EndpointSpecification` or `Bundler::RemoteSpecification`).
116
+ Does not fire for a gem that is already present in the download cache.
117
+
118
+ * `GEM_AFTER_FETCH` (`after-fetch`):
119
+ Called after each individual gem is downloaded from a remote source, with
120
+ the same spec-like object as `GEM_BEFORE_FETCH`. Also fires when the
121
+ download fails.
122
+
123
+ * `GIT_BEFORE_FETCH` (`before-git-fetch`):
124
+ Called before a git source is fetched or checked out, with the
125
+ `Bundler::Source::Git` being fetched.
126
+
127
+ * `GIT_AFTER_FETCH` (`after-git-fetch`):
128
+ Called after a git source is fetched or checked out, with the same
129
+ `Bundler::Source::Git`. Also fires when the fetch or checkout fails.
130
+
131
+ * `GEM_BEFORE_INSTALL` (`before-install`):
132
+ Called before each individual gem is installed, with a
133
+ `Bundler::ParallelInstaller::SpecInstallation`. Its `state`, `error` and
134
+ `post_install_message` are not set yet, as nothing has been installed.
135
+
136
+ * `GEM_AFTER_INSTALL` (`after-install`):
137
+ Called after each individual gem is installed, with the same
138
+ `Bundler::ParallelInstaller::SpecInstallation`. If its `state` is
139
+ `failed`, `error` holds the exception; if the `state` is `success`, a
140
+ `post_install_message` may be present.
141
+
142
+ * `GEM_AFTER_INSTALL_ALL` (`after-install-all`):
143
+ Called after all gems are installed, with an Array of the
144
+ `Bundler::Dependency` objects declared in the Gemfile.
145
+
146
+ **REQUIRE**
147
+
148
+ These events fire from `Bundler.require`.
149
+
150
+ * `GEM_BEFORE_REQUIRE_ALL` (`before-require-all`):
151
+ Called before any gem is required, with an Array of the
152
+ `Bundler::Dependency` objects being required.
153
+
154
+ * `GEM_BEFORE_REQUIRE` (`before-require`):
155
+ Called before each individual gem is required, with its
156
+ `Bundler::Dependency`.
157
+
158
+ * `GEM_AFTER_REQUIRE` (`after-require`):
159
+ Called after each individual gem is required, with its
160
+ `Bundler::Dependency`.
161
+
162
+ * `GEM_AFTER_REQUIRE_ALL` (`after-require-all`):
163
+ Called after all gems are required, with an Array of the
164
+ `Bundler::Dependency` objects that were required.
165
+
82
166
  ## SEE ALSO
83
167
 
84
168
  * [How to write a Bundler plugin](https://guides.rubygems.org/bundler_plugins/)
@@ -82,7 +82,7 @@ ruby "2\.6\.8", engine: "jruby", engine_version: "9\.3\.8\.0"
82
82
  .fi
83
83
  .IP "" 0
84
84
  .SS "PATCHLEVEL"
85
- Each application \fImay\fR specify a Ruby patchlevel\. Specifying the patchlevel has been meaningless since Ruby 2\.1\.0 was released as the patchlevel is now uniquely determined by a combination of major, minor, and teeny version numbers\.
85
+ Each application \fImay\fR specify a Ruby patchlevel\. The option is accepted for compatibility with existing Gemfiles and ignored: the patchlevel has been uniquely determined by the combination of major, minor, and teeny version numbers since Ruby 2\.1\.0 was released, so Bundler does not compare it against the patchlevel of the running Ruby\.
86
86
  .P
87
87
  This option was implemented in Bundler 1\.4\.0 for Ruby 2\.0 or earlier\.
88
88
  .IP "" 4
@@ -468,6 +468,8 @@ The \fBgemspec\fR method adds any runtime dependencies as gem requirements in th
468
468
  .P
469
469
  The \fBgemspec\fR method supports optional \fB:path\fR, \fB:glob\fR, \fB:name\fR, and \fB:development_group\fR options, which control where bundler looks for the \fB\.gemspec\fR, the glob it uses to look for the gemspec (defaults to: \fB{,*,*/*}\.gemspec\fR), what named \fB\.gemspec\fR it uses (if more than one is present), and which group development dependencies are included in\.
470
470
  .P
471
+ When \fBgemspec\fR is called inside a \fBgroup\fR block, the gem requirement on your project goes into that group instead of the default group, and so do its runtime dependencies\. Development dependencies stay in the \fBdevelopment\fR group, or the group given by \fB:development_group\fR\. An enclosing \fBplatforms\fR or \fBinstall_if\fR block applies to the project and its development dependencies alike\.
472
+ .P
471
473
  When a \fBgemspec\fR dependency encounters version conflicts during resolution, the local version under development will always be selected \-\- even if there are remote versions that better match other requirements for the \fBgemspec\fR gem\.
472
474
  .SH "EVAL_GEMFILE"
473
475
  A Gemfile \fBMAY\fR be split across multiple files\. The \fBeval_gemfile\fR method reads the contents of another file as if they appeared in the current Gemfile\. A relative path is resolved against the directory of the file containing the call\.
@@ -521,32 +523,41 @@ gem "rails", "~> 7\.0"
521
523
  .fi
522
524
  .IP "" 0
523
525
  .P
524
- The override only affects resolution and the install\-time Ruby/RubyGems compatibility checks; \fBGemfile\.lock\fR continues to reflect the resolved versions, not the rewritten requirements\. When resolution still fails, Bundler appends the active overrides (with their Gemfile location) to the error message so it is clear which override shaped the constraint set\.
526
+ The override only affects resolution and the install\-time Ruby/RubyGems compatibility checks; the gems in \fBGemfile\.lock\fR continue to reflect the resolved versions, not the rewritten requirements\. The overrides themselves are recorded in the lockfile's \fBOVERRIDES\fR section, one line per field, sorted:
527
+ .IP "" 4
528
+ .nf
529
+ OVERRIDES
530
+ "rails", version: ">= 8\.0"
531
+ :all, required_ruby_version: :ignore_upper
532
+ .fi
533
+ .IP "" 0
534
+ .P
535
+ Requirements are recorded in normalized form, so \fB">=8\.0"\fR and \fB">= 8\.0"\fR are the same override\. A frozen install fails when the Gemfile's overrides differ from the recorded ones\. Adding or removing a \fB:all\fR or metadata override rewrites the section and keeps the locked versions\. The exception is a locked gem that is not installed and whose metadata rejects the current Ruby\. Bundler re\-resolves it, as it does without the override\. Run \fBbundle update\fR to re\-resolve under the override\. When resolution still fails, Bundler appends the active overrides (with their Gemfile location) to the error message so it is clear which override shaped the constraint set\.
525
536
  .SS "DROPPING OR REPLACING A DEPENDENCY"
526
- \fBfrom:\fR and \fBto:\fR rewrite a single dependency of a single gem:
537
+ \fBwith:\fR and \fBin:\fR rewrite a single dependency of a single gem:
527
538
  .IP "" 4
528
539
  .nf
529
- override <target>, from: <gem>, to: nil
530
- override <target>, from: <gem>, to: <replacement>, version: <requirement>
540
+ override <target>, with: nil, in: <gem>
541
+ override <target>, with: <replacement>, in: <gem>, version: <requirement>
531
542
  .fi
532
543
  .IP "" 0
533
544
  .P
534
- \fBto: nil\fR removes the dependency of \fB<gem>\fR on \fB<target>\fR, so \fB<target>\fR is not installed unless something else still requires it\. \fBto: <replacement>\fR makes \fB<gem>\fR depend on \fB<replacement>\fR instead of \fB<target>\fR\. The requirement \fB<gem>\fR put on \fB<target>\fR is discarded, and the optional \fBversion:\fR gives the replacement its own\. Both forms apply whether \fB<gem>\fR is a direct or a transitive dependency\.
545
+ \fBwith: nil\fR removes the dependency of \fB<gem>\fR on \fB<target>\fR, so \fB<target>\fR is not installed unless something else still requires it\. \fBwith: <replacement>\fR makes \fB<gem>\fR depend on \fB<replacement>\fR instead of \fB<target>\fR\. The requirement \fB<gem>\fR put on \fB<target>\fR is discarded, and the optional \fBversion:\fR gives the replacement its own\. Both forms apply whether \fB<gem>\fR is a direct or a transitive dependency\.
535
546
  .P
536
- \fBfrom:\fR is required, and so is \fBto:\fR once \fBfrom:\fR is given\. To rewrite the same dependency of several gems, write one \fBoverride\fR per gem\. It is an error to declare the same \fB<target>\fR and \fBfrom:\fR twice, to drop a gem that the Gemfile requires directly, or to replace a gem that another gem still requires, since both would then be in the bundle\.
547
+ \fBin:\fR is required, and so is \fBwith:\fR once \fBin:\fR is given\. To rewrite the same dependency of several gems, write one \fBoverride\fR per gem\. It is an error to declare the same \fB<target>\fR and \fBin:\fR twice, to drop a gem that the Gemfile requires directly, or to replace a gem that another gem still requires, since both would then be in the bundle\.
537
548
  .IP "" 4
538
549
  .nf
539
550
  # jekyll only loads em\-websocket for `jekyll serve \-\-livereload`\.
540
- override "em\-websocket", from: "jekyll", to: nil
551
+ override "em\-websocket", with: nil, in: "jekyll"
541
552
 
542
553
  # Use an API\-compatible gem that provides the same files\.
543
- override "foo", from: "bar", to: "foo\-lite"
554
+ override "foo", with: "foo\-lite", in: "bar"
544
555
  .fi
545
556
  .IP "" 0
546
557
  .P
547
558
  Bundler does not check what a gem loads at runtime\. If \fB<gem>\fR requires \fB<target>\fR unconditionally, dropping it makes that require raise \fBLoadError\fR, as with jekyll's dependency on jekyll\-sass\-converter or the adapters that faraday 1\.x requires on load\. A replacement only works when it provides the files \fB<gem>\fR requires, and it does not take over the name of \fB<target>\fR: \fBGem\.loaded_specs\fR has no entry for \fB<target>\fR, and \fBgem "<target>"\fR fails\.
548
559
  .P
549
- \fBGemfile\.lock\fR keeps listing \fB<target>\fR under \fB<gem>\fR as the gem publishes it, while the locked gems leave \fB<target>\fR out or include \fB<replacement>\fR\. A frozen install accepts that lockfile as long as the Gemfile still has the override\. Removing the override makes Bundler resolve \fB<target>\fR again\.
560
+ \fBGemfile\.lock\fR keeps listing \fB<target>\fR under \fB<gem>\fR as the gem publishes it, while the locked gems leave \fB<target>\fR out or include \fB<replacement>\fR, and the \fBOVERRIDES\fR section records the rewrite so tools that read the lockfile can apply it\. A frozen install accepts that lockfile as long as the Gemfile still has the override\. Removing the override makes Bundler resolve \fB<target>\fR again\.
550
561
  .SH "SOURCE PRIORITY"
551
562
  When attempting to locate a gem to satisfy a gem requirement, bundler uses the following priority order:
552
563
  .IP "1." 4
@@ -111,9 +111,11 @@ engine version specified _must_ match the Ruby version.
111
111
 
112
112
  ### PATCHLEVEL
113
113
 
114
- Each application _may_ specify a Ruby patchlevel. Specifying the patchlevel has
115
- been meaningless since Ruby 2.1.0 was released as the patchlevel is now
116
- uniquely determined by a combination of major, minor, and teeny version numbers.
114
+ Each application _may_ specify a Ruby patchlevel. The option is accepted for
115
+ compatibility with existing Gemfiles and ignored: the patchlevel has been
116
+ uniquely determined by the combination of major, minor, and teeny version
117
+ numbers since Ruby 2.1.0 was released, so Bundler does not compare it against
118
+ the patchlevel of the running Ruby.
117
119
 
118
120
  This option was implemented in Bundler 1.4.0 for Ruby 2.0 or earlier.
119
121
 
@@ -560,6 +562,12 @@ options, which control where bundler looks for the `.gemspec`, the glob it uses
560
562
  for the gemspec (defaults to: `{,*,*/*}.gemspec`), what named `.gemspec` it uses
561
563
  (if more than one is present), and which group development dependencies are included in.
562
564
 
565
+ When `gemspec` is called inside a `group` block, the gem requirement on your
566
+ project goes into that group instead of the default group, and so do its runtime
567
+ dependencies. Development dependencies stay in the `development` group, or the
568
+ group given by `:development_group`. An enclosing `platforms` or `install_if`
569
+ block applies to the project and its development dependencies alike.
570
+
563
571
  When a `gemspec` dependency encounters version conflicts during resolution, the
564
572
  local version under development will always be selected -- even if there are
565
573
  remote versions that better match other requirements for the `gemspec` gem.
@@ -623,36 +631,49 @@ Declaring the same `target` and `field` twice is an error.
623
631
  gem "rails", "~> 7.0"
624
632
 
625
633
  The override only affects resolution and the install-time Ruby/RubyGems
626
- compatibility checks; `Gemfile.lock` continues to reflect the resolved
627
- versions, not the rewritten requirements. When resolution still fails,
634
+ compatibility checks; the gems in `Gemfile.lock` continue to reflect the
635
+ resolved versions, not the rewritten requirements. The overrides themselves are
636
+ recorded in the lockfile's `OVERRIDES` section, one line per field, sorted:
637
+
638
+ OVERRIDES
639
+ "rails", version: ">= 8.0"
640
+ :all, required_ruby_version: :ignore_upper
641
+
642
+ Requirements are recorded in normalized form, so `">=8.0"` and `">= 8.0"` are
643
+ the same override. A frozen install fails when the Gemfile's overrides differ
644
+ from the recorded ones. Adding or removing a `:all` or metadata override
645
+ rewrites the section and keeps the locked versions. The exception is a locked
646
+ gem that is not installed and whose metadata rejects the current Ruby. Bundler
647
+ re-resolves it, as it does without the override. Run `bundle update` to
648
+ re-resolve under the override. When resolution still fails,
628
649
  Bundler appends the active overrides (with their Gemfile location) to the
629
650
  error message so it is clear which override shaped the constraint set.
630
651
 
631
652
  ### DROPPING OR REPLACING A DEPENDENCY
632
653
 
633
- `from:` and `to:` rewrite a single dependency of a single gem:
654
+ `with:` and `in:` rewrite a single dependency of a single gem:
634
655
 
635
- override <target>, from: <gem>, to: nil
636
- override <target>, from: <gem>, to: <replacement>, version: <requirement>
656
+ override <target>, with: nil, in: <gem>
657
+ override <target>, with: <replacement>, in: <gem>, version: <requirement>
637
658
 
638
- `to: nil` removes the dependency of `<gem>` on `<target>`, so `<target>` is
639
- not installed unless something else still requires it. `to: <replacement>`
659
+ `with: nil` removes the dependency of `<gem>` on `<target>`, so `<target>` is
660
+ not installed unless something else still requires it. `with: <replacement>`
640
661
  makes `<gem>` depend on `<replacement>` instead of `<target>`. The requirement
641
662
  `<gem>` put on `<target>` is discarded, and the optional `version:` gives the
642
663
  replacement its own. Both forms apply whether `<gem>` is a direct or a
643
664
  transitive dependency.
644
665
 
645
- `from:` is required, and so is `to:` once `from:` is given. To rewrite the
666
+ `in:` is required, and so is `with:` once `in:` is given. To rewrite the
646
667
  same dependency of several gems, write one `override` per gem. It is an error
647
- to declare the same `<target>` and `from:` twice, to drop a gem that the
668
+ to declare the same `<target>` and `in:` twice, to drop a gem that the
648
669
  Gemfile requires directly, or to replace a gem that another gem still
649
670
  requires, since both would then be in the bundle.
650
671
 
651
672
  # jekyll only loads em-websocket for `jekyll serve --livereload`.
652
- override "em-websocket", from: "jekyll", to: nil
673
+ override "em-websocket", with: nil, in: "jekyll"
653
674
 
654
675
  # Use an API-compatible gem that provides the same files.
655
- override "foo", from: "bar", to: "foo-lite"
676
+ override "foo", with: "foo-lite", in: "bar"
656
677
 
657
678
  Bundler does not check what a gem loads at runtime. If `<gem>` requires
658
679
  `<target>` unconditionally, dropping it makes that require raise `LoadError`,
@@ -662,9 +683,10 @@ files `<gem>` requires, and it does not take over the name of `<target>`:
662
683
  `Gem.loaded_specs` has no entry for `<target>`, and `gem "<target>"` fails.
663
684
 
664
685
  `Gemfile.lock` keeps listing `<target>` under `<gem>` as the gem publishes it,
665
- while the locked gems leave `<target>` out or include `<replacement>`. A
666
- frozen install accepts that lockfile as long as the Gemfile still has the
667
- override. Removing the override makes Bundler resolve `<target>` again.
686
+ while the locked gems leave `<target>` out or include `<replacement>`, and the
687
+ `OVERRIDES` section records the rewrite so tools that read the lockfile can
688
+ apply it. A frozen install accepts that lockfile as long as the Gemfile still
689
+ has the override. Removing the override makes Bundler resolve `<target>` again.
668
690
 
669
691
  ## SOURCE PRIORITY
670
692
 
@@ -20,16 +20,25 @@ module Bundler
20
20
  Gem::Platform.sort_and_filter_best_platform_match(matching, platform)
21
21
  end
22
22
 
23
- def self.select_all_content_address_match(specs, content_address)
24
- return specs unless Gem::ContentAddress.match?(content_address)
23
+ def self.select_all_content_address_match(specs, content_addresses)
24
+ return specs if content_addresses.empty?
25
25
 
26
- specs.select {|spec| spec.content_address == content_address }
26
+ specs.reject {|spec| Gem::ContentAddress.match?(spec.content_address) && !content_addresses.include?(spec.content_address) }
27
27
  end
28
28
 
29
29
  def self.prefer_content_addressable(matching)
30
- addressable, non_addressable = matching.partition {|s| Gem::ContentAddress.content_addressed?(s, validate_ruby_abi: false) }
31
- return matching if addressable.empty?
32
-
30
+ first = matching.index {|s| Gem::ContentAddress.content_addressed?(s, validate_ruby_abi: false) }
31
+ return matching unless first
32
+
33
+ addressable = [matching[first]]
34
+ non_addressable = matching.take(first)
35
+ matching.drop(first + 1).each do |s|
36
+ if Gem::ContentAddress.content_addressed?(s, validate_ruby_abi: false)
37
+ addressable << s
38
+ else
39
+ non_addressable << s
40
+ end
41
+ end
33
42
  compatible = addressable.select(&:matches_current_metadata?)
34
43
  return compatible if compatible.any?
35
44
 
@@ -151,9 +151,11 @@ module Bundler
151
151
  socket.connect_nonblock(address)
152
152
  rescue Errno::EINPROGRESS
153
153
  wait_for_writtable_socket(socket, address, timeout)
154
- rescue RuntimeError # Connection failed somehow, again
154
+ rescue SystemCallError # Connection failed somehow, again
155
155
  false
156
156
  end
157
+ rescue SocketError # The mirror host does not resolve
158
+ false
157
159
  end
158
160
 
159
161
  private
@@ -185,7 +187,7 @@ module Bundler
185
187
  class MirrorSockets
186
188
  def initialize(mirror)
187
189
  @timeout = mirror.fallback_timeout
188
- @addresses = Socket.getaddrinfo(mirror.uri.host, mirror.uri.port).map do |address|
190
+ @addresses = Socket.getaddrinfo(mirror.uri.hostname, mirror.uri.port, nil, Socket::SOCK_STREAM).map do |address|
189
191
  SocketAddress.new(address[0], address[3], address[1])
190
192
  end
191
193
  end
@@ -194,9 +196,9 @@ module Bundler
194
196
  @addresses.any? do |address|
195
197
  socket = Socket.new(Socket.const_get(address.type), Socket::SOCK_STREAM, 0)
196
198
  socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
197
- value = yield socket, address.to_socket_address, @timeout
198
- socket.close unless socket.closed?
199
- value
199
+ yield socket, address.to_socket_address, @timeout
200
+ ensure
201
+ socket&.close
200
202
  end
201
203
  end
202
204
  end
@@ -9,8 +9,8 @@ module Bundler
9
9
  overrides.find {|o| o.target == :all && o.field == field }
10
10
  end
11
11
 
12
- # Drops or replaces the dependencies of the gem named `from` that a
13
- # `from:`/`to:` override targets. The requirement `from` put on the
12
+ # Drops or replaces the dependencies of the `in:` gem, passed as `from`,
13
+ # that a `with:`/`in:` override targets. The requirement `from` put on the
14
14
  # replaced gem is discarded.
15
15
  def self.rewrite_dependencies(overrides, from, dependencies)
16
16
  return dependencies if overrides.nil? || overrides.none? {|o| o.from == from }
@@ -50,13 +50,66 @@ module Bundler
50
50
  end
51
51
 
52
52
  def to_s
53
- options = if @from
54
- ["from: #{@from.inspect}", "to: #{@operation.inspect}", *("version: #{@requirement.inspect}" if @requirement)].join(", ")
53
+ location = source_location_label
54
+ "override #{to_lock}#{" (declared at #{location})" if location}"
55
+ end
56
+
57
+ # The override as recorded in the OVERRIDES section of Gemfile.lock: the
58
+ # `override` arguments with requirements normalized, so equivalent
59
+ # spellings ("<=3", "<= 3") record the same line.
60
+ def to_lock
61
+ target = @target == :all ? ":all" : @target.inspect
62
+ fields = if @from
63
+ ["with: #{@operation.inspect}", "in: #{@from.inspect}", *("version: #{self.class.normalize(@requirement).inspect}" if @requirement)]
55
64
  else
56
- "#{@field}: #{@operation.inspect}"
65
+ ["#{@field}: #{self.class.normalize(@operation).inspect}"]
57
66
  end
58
- location = source_location_label
59
- "override #{@target == :all ? ":all" : @target.inspect}, #{options}#{" (declared at #{location})" if location}"
67
+ [target, *fields].join(", ")
68
+ end
69
+
70
+ LOCK_VALUE = /"[^"\\]*"|:[a-z_]+|nil/
71
+ LOCK_FIELD = /, ([a-z_]+): (#{LOCK_VALUE})/
72
+ LOCK_LINE = /\A(:all|"[a-zA-Z0-9._-]+")((?:#{LOCK_FIELD})+)\z/
73
+ private_constant :LOCK_VALUE, :LOCK_FIELD, :LOCK_LINE
74
+
75
+ # Parses a line written by #to_lock. The DSL only accepts valid gem names,
76
+ # and requirements are normalized, so no recorded value contains a quote
77
+ # or a backslash and the line can be read without evaluating it.
78
+ def self.from_lock(line)
79
+ match = LOCK_LINE.match(line)
80
+ raise ArgumentError, "invalid override in lockfile: #{line.inspect}" unless match
81
+
82
+ target = match[1] == ":all" ? :all : match[1][1..-2]
83
+ fields = match[2].scan(LOCK_FIELD).map {|key, value| [key.to_sym, parse_lock_value(value)] }
84
+ keys = fields.map(&:first)
85
+ raise ArgumentError, "invalid override in lockfile: #{line.inspect}" unless keys.uniq.size == keys.size
86
+ fields = fields.to_h
87
+
88
+ if fields.key?(:in)
89
+ unless (keys - [:in, :with, :version]).empty? && fields.key?(:with) && fields[:in].is_a?(String)
90
+ raise ArgumentError, "invalid override in lockfile: #{line.inspect}"
91
+ end
92
+ new(target, :with, fields[:with], from: fields[:in], requirement: normalize(fields[:version]))
93
+ else
94
+ field, operation = fields.first
95
+ unless fields.size == 1 && Dsl::SUPPORTED_OVERRIDE_FIELDS.include?(field)
96
+ raise ArgumentError, "invalid override in lockfile: #{line.inspect}"
97
+ end
98
+ new(target, field, normalize(operation))
99
+ end
100
+ end
101
+
102
+ def self.parse_lock_value(value)
103
+ case value
104
+ when "nil" then nil
105
+ when /\A:/ then value[1..].to_sym
106
+ else value[1..-2]
107
+ end
108
+ end
109
+ private_class_method :parse_lock_value
110
+
111
+ def self.normalize(operation)
112
+ operation.is_a?(String) ? Gem::Requirement.new(operation).to_s : operation
60
113
  end
61
114
 
62
115
  def apply_to(requirement)
@@ -158,7 +158,7 @@ module Bundler
158
158
  lines.concat(dependents.map {|name| " #{name}" })
159
159
  if dependents.any?
160
160
  lines << "Replace it for each of them, for example:"
161
- lines << " #{Override.new(override.target, :to, override.operation, from: dependents.first)}"
161
+ lines << " #{Override.new(override.target, :with, override.operation, from: dependents.first)}"
162
162
  end
163
163
  raise GemfileError, lines.join("\n")
164
164
  end
@@ -546,6 +546,8 @@ module Bundler
546
546
  @cooldown_skipped_specs.each do |(name, version), spec|
547
547
  resolved = resolved_versions[name]
548
548
  next unless resolved && version > resolved
549
+ package = @base.get_package(name)
550
+ next if !package.unlock? && package.locked_version == resolved
549
551
  next unless requirements[name].all? {|req| req.satisfied_by?(version) }
550
552
  newest = newest_skipped[name]
551
553
  newest_skipped[name] = spec if newest.nil? || version > newest.version
@@ -42,11 +42,12 @@ module Bundler
42
42
  # Loads the file relative to the dirname of the Gemfile itself.
43
43
  def normalize_ruby_file(filename)
44
44
  file_content = Bundler.read_file(gemfile.dirname.join(filename))
45
- # match "ruby-3.2.2", ruby = "3.2.2", ruby = '3.2.2' or "ruby 3.2.2" capturing version string up to the first space or comment
45
+ # match "ruby-3.2.2", ruby = "3.2.2", ruby = '3.2.2', ruby = { version = "3.2.2" } or "ruby 3.2.2" capturing version string up to the first space or comment
46
46
  version_match = /^ # Start of line
47
47
  ruby # Literal "ruby"
48
48
  [\s-]* # Optional whitespace or hyphens (for "ruby-3.2.2" format)
49
49
  (?:=\s*)? # Optional equals sign with whitespace (for ruby = "3.2.2" format)
50
+ (?:\{[^}]*?\bversion\s*=\s*)? # Optional inline table up to its version key (for ruby = { version = "3.2.2" } format)
50
51
  (?:
51
52
  "([^"]+)" # Double quoted version
52
53
  |
@@ -42,6 +42,29 @@ module Gem
42
42
  def self.content_addressed_row?(suffix, platform, required_ruby_version = nil, validate_ruby_abi: true)
43
43
  false
44
44
  end
45
+
46
+ def self.platform_eligible?(platform)
47
+ false
48
+ end
49
+
50
+ def self.ruby_abi_for(required_ruby_version)
51
+ nil
52
+ end
53
+
54
+ def self.valid_ruby_abi?(value)
55
+ value.is_a?(String) && /\A\d+\.\d+\z/.match?(value)
56
+ end
57
+
58
+ def self.ruby_abi_requirement(ruby_abi)
59
+ Gem::Requirement.new("~> #{ruby_abi}.0")
60
+ end
61
+ end
62
+ end
63
+
64
+ # Can be removed once RubyGems 4.0.0 support is dropped
65
+ unless respond_to?(:ruby_abi)
66
+ def self.ruby_abi
67
+ ruby_version.segments.first(2).join(".")
45
68
  end
46
69
  end
47
70
 
@@ -86,11 +109,22 @@ module Gem
86
109
  end
87
110
  end
88
111
 
89
- def open_file_with_lock(path, &block)
112
+ def open_file_with_lock(path)
90
113
  file_lock = "#{path}.lock"
91
- open_file_with_flock(file_lock, &block)
92
- ensure
93
- FileUtils.rm_f file_lock
114
+
115
+ loop do
116
+ open_file_with_flock(file_lock) do |io|
117
+ # The previous holder removed the file while we were waiting on it,
118
+ # so leave this block and try again on the file now at the lock path
119
+ next unless File.identical?(io, file_lock)
120
+
121
+ begin
122
+ return yield io
123
+ ensure
124
+ FileUtils.rm_f file_lock
125
+ end
126
+ end
127
+ end
94
128
  end
95
129
  end
96
130
  end
@@ -487,15 +521,6 @@ module Gem
487
521
  end
488
522
  end
489
523
 
490
- unless instance_method(:initialize).parameters.any? {|kind, name| kind == :key && name == :content_address }
491
- alias_method :initialize_without_content_address, :initialize
492
-
493
- def initialize(name, version, platform = Gem::Platform::RUBY, content_address: nil)
494
- initialize_without_content_address(name, version, platform)
495
- @content_address = content_address
496
- end
497
- end
498
-
499
524
  def lock_name
500
525
  if platform == Gem::Platform::RUBY
501
526
  "#{name} (#{version})"
@@ -505,6 +530,24 @@ module Gem
505
530
  end
506
531
  end
507
532
 
533
+ # Defined unconditionally for testability, see SplitCompactIndexEntryOnFirstColon.
534
+ module NameTupleContentAddress
535
+ def initialize(name, version, platform = Gem::Platform::RUBY, content_address: nil)
536
+ super(name, version, platform)
537
+ @content_address = content_address
538
+ end
539
+
540
+ def full_name
541
+ return super unless @content_address
542
+
543
+ "#{@name}-#{@version}-#{@content_address}"
544
+ end
545
+ end
546
+
547
+ unless NameTuple.instance_method(:initialize).parameters.any? {|kind, name| kind == :key && name == :content_address }
548
+ NameTuple.prepend(NameTupleContentAddress)
549
+ end
550
+
508
551
  unless Gem.rubygems_version >= Gem::Version.new("3.5.19")
509
552
  class Resolver::ActivationRequest
510
553
  remove_method :installed?
@@ -289,11 +289,9 @@ module Bundler
289
289
  end
290
290
 
291
291
  Bundler.rubygems.default_stubs.each do |stub|
292
- default_spec = stub.to_spec
293
- default_spec_name = default_spec.name
294
- next if specs_by_name.key?(default_spec_name)
292
+ next if specs_by_name.key?(stub.name)
295
293
 
296
- specs_by_name[default_spec_name] = default_spec
294
+ specs_by_name[stub.name] = stub.to_spec
297
295
  end
298
296
 
299
297
  specs_by_name
@@ -210,26 +210,25 @@ module Bundler
210
210
  stale_gemspec_files = gemspec_files - spec_gemspec_paths
211
211
  stale_extension_dirs = extension_dirs - spec_extension_paths
212
212
 
213
- removed_stale_gem_dirs = stale_gem_dirs.collect {|dir| remove_dir(dir, dry_run) }
214
- removed_stale_git_dirs = stale_git_dirs.collect {|dir| remove_dir(dir, dry_run) }
213
+ failures = []
214
+ removed_stale_gem_dirs = stale_gem_dirs.filter_map {|dir| remove_dir(dir, dry_run, failures) }
215
+ removed_stale_git_dirs = stale_git_dirs.filter_map {|dir| remove_dir(dir, dry_run, failures) }
215
216
  output = removed_stale_gem_dirs + removed_stale_git_dirs
216
217
 
217
218
  unless dry_run
218
219
  stale_files = stale_gem_bins + stale_gem_files + stale_gemspec_files
219
220
  stale_files.each do |file|
220
- SharedHelpers.filesystem_access(File.dirname(file)) do |_p|
221
- FileUtils.rm(file) if File.exist?(file)
222
- end
221
+ remove_path(file, failures, File.dirname(file))
223
222
  end
224
223
 
225
224
  stale_dirs = stale_git_cache_dirs + stale_extension_dirs
226
225
  stale_dirs.each do |stale_dir|
227
- SharedHelpers.filesystem_access(stale_dir) do |dir|
228
- FileUtils.rm_rf(dir) if File.exist?(dir)
229
- end
226
+ remove_path(stale_dir, failures)
230
227
  end
231
228
  end
232
229
 
230
+ raise CleanError.new(failures) unless failures.empty?
231
+
233
232
  output
234
233
  end
235
234
 
@@ -359,7 +358,7 @@ module Bundler
359
358
  ).uniq.join(File::PATH_SEPARATOR)
360
359
  end
361
360
 
362
- def remove_dir(dir, dry_run)
361
+ def remove_dir(dir, dry_run, failures)
363
362
  full_name = Pathname.new(dir).basename.to_s
364
363
 
365
364
  parts = full_name.split("-")
@@ -370,13 +369,28 @@ module Bundler
370
369
  if dry_run
371
370
  Bundler.ui.info "Would have removed #{output}"
372
371
  else
372
+ return unless remove_path(dir, failures)
373
373
  Bundler.ui.info "Removing #{output}"
374
- FileUtils.rm_rf(dir)
375
374
  end
376
375
 
377
376
  output
378
377
  end
379
378
 
379
+ # Collects the error instead of raising it, so that one path that cannot be
380
+ # removed does not stop the rest of the bundle from being cleaned.
381
+ def remove_path(path, failures, access_path = path)
382
+ SharedHelpers.filesystem_access(access_path) do
383
+ FileUtils.rm_r(path)
384
+ end
385
+ true
386
+ rescue Errno::ENOENT
387
+ # Removed by something else since the bundle was scanned
388
+ true
389
+ rescue BundlerError => e
390
+ failures << e
391
+ false
392
+ end
393
+
380
394
  def check_for_activated_spec!(spec)
381
395
  return unless activated_spec = Bundler.rubygems.loaded_specs(spec.name)
382
396
  return if activated_spec.version == spec.version