bundler 2.2.26 → 2.3.26

Sign up to get free protection for your applications and to get access to all the features.
Files changed (197) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +501 -1
  3. data/README.md +1 -1
  4. data/bundler.gemspec +6 -8
  5. data/exe/bundle +7 -8
  6. data/exe/bundler +1 -1
  7. data/lib/bundler/.document +1 -0
  8. data/lib/bundler/build_metadata.rb +3 -3
  9. data/lib/bundler/cli/check.rb +1 -1
  10. data/lib/bundler/cli/common.rb +3 -2
  11. data/lib/bundler/cli/config.rb +10 -1
  12. data/lib/bundler/cli/doctor.rb +12 -3
  13. data/lib/bundler/cli/gem.rb +98 -9
  14. data/lib/bundler/cli/info.rb +27 -6
  15. data/lib/bundler/cli/init.rb +5 -1
  16. data/lib/bundler/cli/install.rb +13 -30
  17. data/lib/bundler/cli/issue.rb +4 -3
  18. data/lib/bundler/cli/outdated.rb +12 -3
  19. data/lib/bundler/cli/platform.rb +2 -2
  20. data/lib/bundler/cli/remove.rb +1 -2
  21. data/lib/bundler/cli/show.rb +1 -1
  22. data/lib/bundler/cli/update.rb +8 -4
  23. data/lib/bundler/cli.rb +23 -19
  24. data/lib/bundler/compact_index_client/cache.rb +0 -9
  25. data/lib/bundler/compact_index_client/updater.rb +16 -8
  26. data/lib/bundler/compact_index_client.rb +2 -8
  27. data/lib/bundler/current_ruby.rb +16 -6
  28. data/lib/bundler/definition.rb +204 -217
  29. data/lib/bundler/dependency.rb +23 -71
  30. data/lib/bundler/digest.rb +71 -0
  31. data/lib/bundler/dsl.rb +28 -45
  32. data/lib/bundler/endpoint_specification.rb +19 -13
  33. data/lib/bundler/env.rb +1 -1
  34. data/lib/bundler/environment_preserver.rb +4 -1
  35. data/lib/bundler/errors.rb +28 -2
  36. data/lib/bundler/feature_flag.rb +0 -1
  37. data/lib/bundler/fetcher/base.rb +6 -8
  38. data/lib/bundler/fetcher/compact_index.rb +9 -14
  39. data/lib/bundler/fetcher/index.rb +0 -26
  40. data/lib/bundler/fetcher.rb +20 -22
  41. data/lib/bundler/friendly_errors.rb +26 -34
  42. data/lib/bundler/gem_helper.rb +7 -18
  43. data/lib/bundler/gem_helpers.rb +9 -2
  44. data/lib/bundler/gem_version_promoter.rb +14 -25
  45. data/lib/bundler/index.rb +10 -40
  46. data/lib/bundler/injector.rb +16 -2
  47. data/lib/bundler/inline.rb +2 -12
  48. data/lib/bundler/installer/gem_installer.rb +13 -5
  49. data/lib/bundler/installer/standalone.rb +30 -3
  50. data/lib/bundler/installer.rb +18 -29
  51. data/lib/bundler/lazy_specification.rb +52 -35
  52. data/lib/bundler/lockfile_generator.rb +2 -2
  53. data/lib/bundler/lockfile_parser.rb +12 -10
  54. data/lib/bundler/man/bundle-add.1 +21 -5
  55. data/lib/bundler/man/bundle-add.1.ronn +16 -4
  56. data/lib/bundler/man/bundle-binstubs.1 +1 -1
  57. data/lib/bundler/man/bundle-cache.1 +7 -1
  58. data/lib/bundler/man/bundle-cache.1.ronn +7 -0
  59. data/lib/bundler/man/bundle-check.1 +1 -1
  60. data/lib/bundler/man/bundle-clean.1 +2 -2
  61. data/lib/bundler/man/bundle-clean.1.ronn +1 -1
  62. data/lib/bundler/man/bundle-config.1 +33 -14
  63. data/lib/bundler/man/bundle-config.1.ronn +30 -18
  64. data/lib/bundler/man/bundle-console.1 +53 -0
  65. data/lib/bundler/man/bundle-console.1.ronn +44 -0
  66. data/lib/bundler/man/bundle-doctor.1 +1 -1
  67. data/lib/bundler/man/bundle-exec.1 +2 -2
  68. data/lib/bundler/man/bundle-exec.1.ronn +1 -1
  69. data/lib/bundler/man/bundle-gem.1 +14 -1
  70. data/lib/bundler/man/bundle-gem.1.ronn +16 -0
  71. data/lib/bundler/man/bundle-help.1 +13 -0
  72. data/lib/bundler/man/bundle-help.1.ronn +12 -0
  73. data/lib/bundler/man/bundle-info.1 +1 -1
  74. data/lib/bundler/man/bundle-init.1 +1 -1
  75. data/lib/bundler/man/bundle-inject.1 +5 -2
  76. data/lib/bundler/man/bundle-inject.1.ronn +3 -1
  77. data/lib/bundler/man/bundle-install.1 +6 -2
  78. data/lib/bundler/man/bundle-install.1.ronn +8 -2
  79. data/lib/bundler/man/bundle-list.1 +1 -1
  80. data/lib/bundler/man/bundle-lock.1 +1 -1
  81. data/lib/bundler/man/bundle-open.1 +1 -1
  82. data/lib/bundler/man/bundle-outdated.1 +3 -10
  83. data/lib/bundler/man/bundle-outdated.1.ronn +1 -10
  84. data/lib/bundler/man/bundle-platform.1 +16 -6
  85. data/lib/bundler/man/bundle-platform.1.ronn +14 -7
  86. data/lib/bundler/man/bundle-plugin.1 +81 -0
  87. data/lib/bundler/man/bundle-plugin.1.ronn +59 -0
  88. data/lib/bundler/man/bundle-pristine.1 +1 -1
  89. data/lib/bundler/man/bundle-remove.1 +1 -1
  90. data/lib/bundler/man/bundle-show.1 +1 -1
  91. data/lib/bundler/man/bundle-update.1 +2 -2
  92. data/lib/bundler/man/bundle-update.1.ronn +2 -1
  93. data/lib/bundler/man/bundle-version.1 +35 -0
  94. data/lib/bundler/man/bundle-version.1.ronn +24 -0
  95. data/lib/bundler/man/bundle-viz.1 +4 -1
  96. data/lib/bundler/man/bundle-viz.1.ronn +2 -0
  97. data/lib/bundler/man/bundle.1 +15 -10
  98. data/lib/bundler/man/bundle.1.ronn +12 -7
  99. data/lib/bundler/man/gemfile.5 +117 -80
  100. data/lib/bundler/man/gemfile.5.ronn +105 -84
  101. data/lib/bundler/man/index.txt +4 -0
  102. data/lib/bundler/match_metadata.rb +13 -0
  103. data/lib/bundler/match_platform.rb +0 -1
  104. data/lib/bundler/match_remote_metadata.rb +29 -0
  105. data/lib/bundler/plugin/api/source.rb +4 -9
  106. data/lib/bundler/plugin/installer/git.rb +0 -4
  107. data/lib/bundler/plugin/installer/rubygems.rb +0 -4
  108. data/lib/bundler/plugin/installer.rb +3 -1
  109. data/lib/bundler/plugin.rb +25 -6
  110. data/lib/bundler/process_lock.rb +1 -1
  111. data/lib/bundler/remote_specification.rb +10 -4
  112. data/lib/bundler/resolver/base.rb +50 -0
  113. data/lib/bundler/resolver/spec_group.rb +31 -49
  114. data/lib/bundler/resolver.rb +183 -192
  115. data/lib/bundler/ruby_dsl.rb +1 -1
  116. data/lib/bundler/ruby_version.rb +5 -18
  117. data/lib/bundler/rubygems_ext.rb +138 -20
  118. data/lib/bundler/rubygems_gem_installer.rb +42 -16
  119. data/lib/bundler/rubygems_integration.rb +42 -90
  120. data/lib/bundler/runtime.rb +2 -3
  121. data/lib/bundler/self_manager.rb +168 -0
  122. data/lib/bundler/settings.rb +13 -4
  123. data/lib/bundler/shared_helpers.rb +15 -24
  124. data/lib/bundler/source/git/git_proxy.rb +7 -4
  125. data/lib/bundler/source/git.rb +29 -13
  126. data/lib/bundler/source/metadata.rb +3 -3
  127. data/lib/bundler/source/path.rb +1 -1
  128. data/lib/bundler/source/rubygems.rb +148 -161
  129. data/lib/bundler/source/rubygems_aggregate.rb +1 -1
  130. data/lib/bundler/source.rb +6 -5
  131. data/lib/bundler/source_list.rb +15 -29
  132. data/lib/bundler/source_map.rb +15 -2
  133. data/lib/bundler/spec_set.rb +52 -32
  134. data/lib/bundler/stub_specification.rb +5 -3
  135. data/lib/bundler/templates/Executable +2 -4
  136. data/lib/bundler/templates/Executable.bundler +2 -2
  137. data/lib/bundler/templates/Executable.standalone +2 -4
  138. data/lib/bundler/templates/Gemfile +0 -2
  139. data/lib/bundler/templates/gems.rb +0 -3
  140. data/lib/bundler/templates/newgem/Gemfile.tt +5 -2
  141. data/lib/bundler/templates/newgem/README.md.tt +3 -9
  142. data/lib/bundler/templates/newgem/Rakefile.tt +15 -2
  143. data/lib/bundler/templates/newgem/github/workflows/main.yml.tt +5 -4
  144. data/lib/bundler/templates/newgem/gitlab-ci.yml.tt +5 -4
  145. data/lib/bundler/templates/newgem/newgem.gemspec.tt +16 -16
  146. data/lib/bundler/templates/newgem/sig/newgem.rbs.tt +8 -0
  147. data/lib/bundler/templates/newgem/standard.yml.tt +3 -0
  148. data/lib/bundler/templates/newgem/test/minitest/{newgem_test.rb.tt → test_newgem.rb.tt} +1 -1
  149. data/lib/bundler/ui/shell.rb +1 -1
  150. data/lib/bundler/vendor/.document +1 -0
  151. data/lib/bundler/vendor/connection_pool/LICENSE +20 -0
  152. data/lib/bundler/vendor/connection_pool/lib/connection_pool/timed_stack.rb +19 -21
  153. data/lib/bundler/vendor/connection_pool/lib/connection_pool/version.rb +1 -1
  154. data/lib/bundler/vendor/connection_pool/lib/connection_pool/wrapper.rb +57 -0
  155. data/lib/bundler/vendor/connection_pool/lib/connection_pool.rb +39 -74
  156. data/lib/bundler/vendor/fileutils/LICENSE.txt +22 -0
  157. data/lib/bundler/vendor/molinillo/LICENSE +9 -0
  158. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb +3 -3
  159. data/lib/bundler/vendor/molinillo/lib/molinillo/errors.rb +32 -26
  160. data/lib/bundler/vendor/molinillo/lib/molinillo/gem_metadata.rb +1 -1
  161. data/lib/bundler/vendor/net-http-persistent/README.rdoc +82 -0
  162. data/lib/bundler/vendor/thor/LICENSE.md +20 -0
  163. data/lib/bundler/vendor/thor/lib/thor/actions/file_manipulation.rb +6 -6
  164. data/lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb +1 -2
  165. data/lib/bundler/vendor/thor/lib/thor/actions.rb +6 -2
  166. data/lib/bundler/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb +6 -0
  167. data/lib/bundler/vendor/thor/lib/thor/error.rb +9 -4
  168. data/lib/bundler/vendor/thor/lib/thor/parser/options.rb +19 -1
  169. data/lib/bundler/vendor/thor/lib/thor/shell/basic.rb +22 -4
  170. data/lib/bundler/vendor/thor/lib/thor/shell.rb +1 -1
  171. data/lib/bundler/vendor/thor/lib/thor/util.rb +1 -1
  172. data/lib/bundler/vendor/thor/lib/thor/version.rb +1 -1
  173. data/lib/bundler/vendor/tsort/LICENSE.txt +22 -0
  174. data/lib/bundler/vendor/tsort/lib/tsort.rb +452 -0
  175. data/lib/bundler/vendor/uri/LICENSE.txt +22 -0
  176. data/lib/bundler/vendor/uri/lib/uri/common.rb +17 -80
  177. data/lib/bundler/vendor/uri/lib/uri/ftp.rb +0 -1
  178. data/lib/bundler/vendor/uri/lib/uri/generic.rb +5 -6
  179. data/lib/bundler/vendor/uri/lib/uri/http.rb +0 -1
  180. data/lib/bundler/vendor/uri/lib/uri/https.rb +0 -1
  181. data/lib/bundler/vendor/uri/lib/uri/ldap.rb +1 -1
  182. data/lib/bundler/vendor/uri/lib/uri/mailto.rb +0 -1
  183. data/lib/bundler/vendor/uri/lib/uri/rfc2396_parser.rb +1 -14
  184. data/lib/bundler/vendor/uri/lib/uri/rfc3986_parser.rb +1 -12
  185. data/lib/bundler/vendor/uri/lib/uri/version.rb +1 -1
  186. data/lib/bundler/vendor/uri/lib/uri/ws.rb +84 -0
  187. data/lib/bundler/vendor/uri/lib/uri/wss.rb +22 -0
  188. data/lib/bundler/vendor/uri/lib/uri.rb +0 -1
  189. data/lib/bundler/vendored_tsort.rb +4 -0
  190. data/lib/bundler/version.rb +1 -1
  191. data/lib/bundler/worker.rb +2 -2
  192. data/lib/bundler.rb +40 -29
  193. metadata +37 -12
  194. data/lib/bundler/dep_proxy.rb +0 -55
  195. data/lib/bundler/gemdeps.rb +0 -29
  196. data/lib/bundler/psyched_yaml.rb +0 -22
  197. data/lib/bundler/vendor/connection_pool/lib/connection_pool/monotonic_time.rb +0 -66
@@ -32,12 +32,12 @@ module Bundler
32
32
  @engine = engine && engine.to_s || "ruby"
33
33
  @engine_versions = (engine_version && Array(engine_version)) || @versions
34
34
  @engine_gem_version = Gem::Requirement.create(@engine_versions.first).requirements.first.last
35
- @patchlevel = patchlevel
35
+ @patchlevel = patchlevel || (@gem_version.prerelease? ? "-1" : nil)
36
36
  end
37
37
 
38
38
  def to_s(versions = self.versions)
39
39
  output = String.new("ruby #{versions_string(versions)}")
40
- output << "p#{patchlevel}" if patchlevel
40
+ output << "p#{patchlevel}" if patchlevel && patchlevel != "-1"
41
41
  output << " (#{engine} #{versions_string(engine_versions)})" unless engine == "ruby"
42
42
 
43
43
  output
@@ -46,7 +46,7 @@ module Bundler
46
46
  # @private
47
47
  PATTERN = /
48
48
  ruby\s
49
- ([\d.]+) # ruby version
49
+ (\d+\.\d+\.\d+(?:\.\S+)?) # ruby version
50
50
  (?:p(-?\d+))? # optional patchlevel
51
51
  (?:\s\((\S+)\s(.+)\))? # optional engine info
52
52
  /xo.freeze
@@ -103,26 +103,13 @@ module Bundler
103
103
 
104
104
  def self.system
105
105
  ruby_engine = RUBY_ENGINE.dup
106
- ruby_version = ENV.fetch("BUNDLER_SPEC_RUBY_VERSION") { RUBY_VERSION }.dup
107
- ruby_engine_version = RUBY_ENGINE_VERSION.dup
106
+ ruby_version = Gem.ruby_version.to_s
107
+ ruby_engine_version = RUBY_ENGINE == "ruby" ? ruby_version : RUBY_ENGINE_VERSION.dup
108
108
  patchlevel = RUBY_PATCHLEVEL.to_s
109
109
 
110
110
  @ruby_version ||= RubyVersion.new(ruby_version, patchlevel, ruby_engine, ruby_engine_version)
111
111
  end
112
112
 
113
- def to_gem_version_with_patchlevel
114
- @gem_version_with_patch ||= begin
115
- Gem::Version.create("#{@gem_version}.#{@patchlevel}")
116
- rescue ArgumentError
117
- @gem_version
118
- end
119
- end
120
-
121
- def exact?
122
- return @exact if defined?(@exact)
123
- @exact = versions.all? {|v| Gem::Requirement.create(v).exact? }
124
- end
125
-
126
113
  private
127
114
 
128
115
  def matches?(requirements, version)
@@ -4,14 +4,34 @@ require "pathname"
4
4
 
5
5
  require "rubygems/specification"
6
6
 
7
- # Possible use in Gem::Specification#source below and require
8
- # shouldn't be deferred.
7
+ # We can't let `Gem::Source` be autoloaded in the `Gem::Specification#source`
8
+ # redefinition below, so we need to load it upfront. The reason is that if
9
+ # Bundler monkeypatches are loaded before RubyGems activates an executable (for
10
+ # example, through `ruby -rbundler -S irb`), gem activation might end up calling
11
+ # the redefined `Gem::Specification#source` and triggering the `Gem::Source`
12
+ # autoload. That would result in requiring "rubygems/source" inside another
13
+ # require, which would trigger a monitor error and cause the `autoload` to
14
+ # eventually fail. A better solution is probably to completely avoid autoloading
15
+ # `Gem::Source` from the redefined `Gem::Specification#source`.
9
16
  require "rubygems/source"
10
17
 
18
+ require_relative "match_metadata"
11
19
  require_relative "match_platform"
12
20
 
21
+ # Cherry-pick fixes to `Gem.ruby_version` to be useful for modern Bundler
22
+ # versions and ignore patchlevels
23
+ # (https://github.com/rubygems/rubygems/pull/5472,
24
+ # https://github.com/rubygems/rubygems/pull/5486). May be removed once RubyGems
25
+ # 3.3.12 support is dropped.
26
+ unless Gem.ruby_version.to_s == RUBY_VERSION || RUBY_PATCHLEVEL == -1
27
+ Gem.instance_variable_set(:@ruby_version, Gem::Version.new(RUBY_VERSION))
28
+ end
29
+
13
30
  module Gem
14
31
  class Specification
32
+ include ::Bundler::MatchMetadata
33
+ include ::Bundler::MatchPlatform
34
+
15
35
  attr_accessor :remote, :location, :relative_loaded_from
16
36
 
17
37
  remove_method :source
@@ -24,12 +44,8 @@ module Gem
24
44
  alias_method :rg_loaded_from, :loaded_from
25
45
 
26
46
  def full_gem_path
27
- # this cannot check source.is_a?(Bundler::Plugin::API::Source)
28
- # because that _could_ trip the autoload, and if there are unresolved
29
- # gems at that time, this method could be called inside another require,
30
- # thus raising with that constant being undefined. Better to check a method
31
- if source.respond_to?(:path) || (source.respond_to?(:bundler_plugin_api_source?) && source.bundler_plugin_api_source?)
32
- Pathname.new(loaded_from).dirname.expand_path(source.root).to_s.tap{|x| x.untaint if RUBY_VERSION < "2.7" }
47
+ if source.respond_to?(:root)
48
+ Pathname.new(loaded_from).dirname.expand_path(source.root).to_s.tap {|x| x.untaint if RUBY_VERSION < "2.7" }
33
49
  else
34
50
  rg_full_gem_path
35
51
  end
@@ -62,6 +78,23 @@ module Gem
62
78
  full_gem_path
63
79
  end
64
80
 
81
+ unless const_defined?(:LATEST_RUBY_WITHOUT_PATCH_VERSIONS)
82
+ LATEST_RUBY_WITHOUT_PATCH_VERSIONS = Gem::Version.new("2.1")
83
+
84
+ alias_method :rg_required_ruby_version=, :required_ruby_version=
85
+ def required_ruby_version=(req)
86
+ self.rg_required_ruby_version = req
87
+
88
+ @required_ruby_version.requirements.map! do |op, v|
89
+ if v >= LATEST_RUBY_WITHOUT_PATCH_VERSIONS && v.release.segments.size == 4
90
+ [op == "~>" ? "=" : op, Gem::Version.new(v.segments.tap {|s| s.delete_at(3) }.join("."))]
91
+ else
92
+ [op, v]
93
+ end
94
+ end
95
+ end
96
+ end
97
+
65
98
  def groups
66
99
  @groups ||= []
67
100
  end
@@ -81,10 +114,25 @@ module Gem
81
114
  gemfile
82
115
  end
83
116
 
117
+ # Backfill missing YAML require when not defined. Fixed since 3.1.0.pre1.
118
+ module YamlBackfiller
119
+ def to_yaml(opts = {})
120
+ Gem.load_yaml unless defined?(::YAML)
121
+
122
+ super(opts)
123
+ end
124
+ end
125
+
126
+ prepend YamlBackfiller
127
+
84
128
  def nondevelopment_dependencies
85
129
  dependencies - development_dependencies
86
130
  end
87
131
 
132
+ def deleted_gem?
133
+ !default_gem? && !File.directory?(full_gem_path)
134
+ end
135
+
88
136
  private
89
137
 
90
138
  def dependencies_to_gemfile(dependencies, group = nil)
@@ -109,6 +157,10 @@ module Gem
109
157
 
110
158
  alias_method :eql?, :==
111
159
 
160
+ def force_ruby_platform
161
+ false
162
+ end
163
+
112
164
  def encode_with(coder)
113
165
  to_yaml_properties.each do |ivar|
114
166
  coder[ivar.to_s.sub(/^@/, "")] = instance_variable_get(ivar)
@@ -134,6 +186,8 @@ module Gem
134
186
  class Requirement
135
187
  module OrderIndependentComparison
136
188
  def ==(other)
189
+ return unless Gem::Requirement === other
190
+
137
191
  if _requirements_sorted? && other._requirements_sorted?
138
192
  super
139
193
  else
@@ -177,11 +231,52 @@ module Gem
177
231
  require "rubygems/platform"
178
232
 
179
233
  class Platform
180
- JAVA = Gem::Platform.new("java") unless defined?(JAVA)
181
- MSWIN = Gem::Platform.new("mswin32") unless defined?(MSWIN)
182
- MSWIN64 = Gem::Platform.new("mswin64") unless defined?(MSWIN64)
183
- MINGW = Gem::Platform.new("x86-mingw32") unless defined?(MINGW)
184
- X64_MINGW = Gem::Platform.new("x64-mingw32") unless defined?(X64_MINGW)
234
+ JAVA = Gem::Platform.new("java")
235
+ MSWIN = Gem::Platform.new("mswin32")
236
+ MSWIN64 = Gem::Platform.new("mswin64")
237
+ MINGW = Gem::Platform.new("x86-mingw32")
238
+ X64_MINGW = [Gem::Platform.new("x64-mingw32"),
239
+ Gem::Platform.new("x64-mingw-ucrt")].freeze
240
+ WINDOWS = [MSWIN, MSWIN64, MINGW, X64_MINGW].flatten.freeze
241
+ X64_LINUX = Gem::Platform.new("x86_64-linux")
242
+ X64_LINUX_MUSL = Gem::Platform.new("x86_64-linux-musl")
243
+
244
+ if X64_LINUX === X64_LINUX_MUSL
245
+ remove_method :===
246
+
247
+ def ===(other)
248
+ return nil unless Gem::Platform === other
249
+
250
+ # universal-mingw32 matches x64-mingw-ucrt
251
+ return true if (@cpu == "universal" || other.cpu == "universal") &&
252
+ @os.start_with?("mingw") && other.os.start_with?("mingw")
253
+
254
+ # cpu
255
+ ([nil,"universal"].include?(@cpu) || [nil, "universal"].include?(other.cpu) || @cpu == other.cpu ||
256
+ (@cpu == "arm" && other.cpu.start_with?("arm"))) &&
257
+
258
+ # os
259
+ @os == other.os &&
260
+
261
+ # version
262
+ (
263
+ (@os != "linux" && (@version.nil? || other.version.nil?)) ||
264
+ (@os == "linux" && (normalized_linux_version_ext == other.normalized_linux_version_ext || ["musl#{@version}", "musleabi#{@version}", "musleabihf#{@version}"].include?(other.version))) ||
265
+ @version == other.version
266
+ )
267
+ end
268
+
269
+ # This is a copy of RubyGems 3.3.23 or higher `normalized_linux_method`.
270
+ # Once only 3.3.23 is supported, we can use the method in RubyGems.
271
+ def normalized_linux_version_ext
272
+ return nil unless @version
273
+
274
+ without_gnu_nor_abi_modifiers = @version.sub(/\Agnu/, "").sub(/eabi(hf)?\Z/, "")
275
+ return nil if without_gnu_nor_abi_modifiers.empty?
276
+
277
+ without_gnu_nor_abi_modifiers
278
+ end
279
+ end
185
280
  end
186
281
 
187
282
  Platform.singleton_class.module_eval do
@@ -193,14 +288,43 @@ module Gem
193
288
  def match_gem?(platform, gem_name)
194
289
  match_platforms?(platform, Gem.platforms)
195
290
  end
291
+ end
292
+
293
+ match_platforms_defined = Gem::Platform.respond_to?(:match_platforms?, true)
294
+
295
+ if !match_platforms_defined || Gem::Platform.send(:match_platforms?, Gem::Platform::X64_LINUX_MUSL, [Gem::Platform::X64_LINUX])
196
296
 
197
297
  private
198
298
 
299
+ remove_method :match_platforms? if match_platforms_defined
300
+
199
301
  def match_platforms?(platform, platforms)
200
302
  platforms.any? do |local_platform|
201
303
  platform.nil? ||
202
304
  local_platform == platform ||
203
- (local_platform != Gem::Platform::RUBY && local_platform =~ platform)
305
+ (local_platform != Gem::Platform::RUBY && platform =~ local_platform)
306
+ end
307
+ end
308
+ end
309
+ end
310
+
311
+ # On universal Rubies, resolve the "universal" arch to the real CPU arch, without changing the extension directory.
312
+ class Specification
313
+ if /^universal\.(?<arch>.*?)-/ =~ (CROSS_COMPILING || RUBY_PLATFORM)
314
+ local_platform = Platform.local
315
+ if local_platform.cpu == "universal"
316
+ ORIGINAL_LOCAL_PLATFORM = local_platform.to_s.freeze
317
+
318
+ local_platform.cpu = if arch == "arm64e" # arm64e is only permitted for Apple system binaries
319
+ "arm64"
320
+ else
321
+ arch
322
+ end
323
+
324
+ def extensions_dir
325
+ Gem.default_ext_dir_for(base_dir) ||
326
+ File.join(base_dir, "extensions", ORIGINAL_LOCAL_PLATFORM,
327
+ Gem.extension_api_version)
204
328
  end
205
329
  end
206
330
  end
@@ -222,9 +346,3 @@ module Gem
222
346
  end
223
347
  end
224
348
  end
225
-
226
- module Gem
227
- class Specification
228
- include ::Bundler::MatchPlatform
229
- end
230
- end
@@ -16,14 +16,16 @@ module Bundler
16
16
  spec.loaded_from = spec_file
17
17
 
18
18
  # Completely remove any previous gem files
19
- FileUtils.rm_rf gem_dir
20
- FileUtils.rm_rf spec.extension_dir
19
+ strict_rm_rf gem_dir
20
+ strict_rm_rf spec.extension_dir
21
21
 
22
- FileUtils.mkdir_p gem_dir, :mode => 0o755
22
+ SharedHelpers.filesystem_access(gem_dir, :create) do
23
+ FileUtils.mkdir_p gem_dir, :mode => 0o755
24
+ end
23
25
 
24
26
  extract_files
25
27
 
26
- build_extensions
28
+ build_extensions if spec.extensions.any?
27
29
  write_build_info_file
28
30
  run_post_build_hooks
29
31
 
@@ -31,7 +33,10 @@ module Bundler
31
33
  generate_plugins
32
34
 
33
35
  write_spec
34
- write_cache_file
36
+
37
+ SharedHelpers.filesystem_access("#{gem_home}/cache", :write) do
38
+ write_cache_file
39
+ end
35
40
 
36
41
  say spec.post_install_message unless spec.post_install_message.nil?
37
42
 
@@ -61,32 +66,53 @@ module Bundler
61
66
 
62
67
  def build_extensions
63
68
  extension_cache_path = options[:bundler_extension_cache_path]
64
- unless extension_cache_path && extension_dir = spec.extension_dir
65
- require "shellwords" # compensate missing require in rubygems before version 3.2.25
69
+ extension_dir = spec.extension_dir
70
+ unless extension_cache_path && extension_dir
71
+ prepare_extension_build(extension_dir)
66
72
  return super
67
73
  end
68
74
 
69
- extension_dir = Pathname.new(extension_dir)
70
75
  build_complete = SharedHelpers.filesystem_access(extension_cache_path.join("gem.build_complete"), :read, &:file?)
71
76
  if build_complete && !options[:force]
72
- SharedHelpers.filesystem_access(extension_dir.parent, &:mkpath)
77
+ SharedHelpers.filesystem_access(File.dirname(extension_dir)) do |p|
78
+ FileUtils.mkpath p
79
+ end
73
80
  SharedHelpers.filesystem_access(extension_cache_path) do
74
- FileUtils.cp_r extension_cache_path, spec.extension_dir
81
+ FileUtils.cp_r extension_cache_path, extension_dir
75
82
  end
76
83
  else
77
- require "shellwords" # compensate missing require in rubygems before version 3.2.25
84
+ prepare_extension_build(extension_dir)
78
85
  super
79
- if extension_dir.directory? # not made for gems without extensions
80
- SharedHelpers.filesystem_access(extension_cache_path.parent, &:mkpath)
81
- SharedHelpers.filesystem_access(extension_cache_path) do
82
- FileUtils.cp_r extension_dir, extension_cache_path
83
- end
86
+ SharedHelpers.filesystem_access(extension_cache_path.parent, &:mkpath)
87
+ SharedHelpers.filesystem_access(extension_cache_path) do
88
+ FileUtils.cp_r extension_dir, extension_cache_path
84
89
  end
85
90
  end
86
91
  end
87
92
 
93
+ def spec
94
+ if Bundler.rubygems.provides?("< 3.3.12") # RubyGems implementation rescues and re-raises errors before 3.3.12 and we don't want that
95
+ @package.spec
96
+ else
97
+ super
98
+ end
99
+ end
100
+
88
101
  private
89
102
 
103
+ def prepare_extension_build(extension_dir)
104
+ SharedHelpers.filesystem_access(extension_dir, :create) do
105
+ FileUtils.mkdir_p extension_dir
106
+ end
107
+ require "shellwords" unless Bundler.rubygems.provides?(">= 3.2.25")
108
+ end
109
+
110
+ def strict_rm_rf(dir)
111
+ Bundler.rm_rf dir
112
+ rescue Errno::ENOTEMPTY => e
113
+ raise DirectoryRemovalError.new(e.cause, "Could not delete previous installation of `#{dir}`")
114
+ end
115
+
90
116
  def validate_bundler_checksum(checksum)
91
117
  return true if Bundler.settings[:disable_checksum_validation]
92
118
  return true unless checksum
@@ -12,32 +12,30 @@ module Bundler
12
12
  EXT_LOCK = Monitor.new
13
13
  end
14
14
 
15
- def self.version
16
- @version ||= Gem::Version.new(Gem::VERSION)
17
- end
18
-
19
- def self.provides?(req_str)
20
- Gem::Requirement.new(req_str).satisfied_by?(version)
21
- end
22
-
23
15
  def initialize
24
16
  @replaced_methods = {}
25
17
  backport_ext_builder_monitor
26
18
  end
27
19
 
28
20
  def version
29
- self.class.version
21
+ @version ||= Gem.rubygems_version
30
22
  end
31
23
 
32
24
  def provides?(req_str)
33
- self.class.provides?(req_str)
25
+ Gem::Requirement.new(req_str).satisfied_by?(version)
26
+ end
27
+
28
+ def supports_bundler_trampolining?
29
+ provides?(">= 3.3.0.a")
34
30
  end
35
31
 
36
32
  def build_args
33
+ require "rubygems/command"
37
34
  Gem::Command.build_args
38
35
  end
39
36
 
40
37
  def build_args=(args)
38
+ require "rubygems/command"
41
39
  Gem::Command.build_args = args
42
40
  end
43
41
 
@@ -84,16 +82,12 @@ module Bundler
84
82
  def spec_missing_extensions?(spec, default = true)
85
83
  return spec.missing_extensions? if spec.respond_to?(:missing_extensions?)
86
84
 
87
- return false if spec_default_gem?(spec)
85
+ return false if spec.default_gem?
88
86
  return false if spec.extensions.empty?
89
87
 
90
88
  default
91
89
  end
92
90
 
93
- def spec_default_gem?(spec)
94
- spec.respond_to?(:default_gem?) && spec.default_gem?
95
- end
96
-
97
91
  def spec_matches_for_glob(spec, glob)
98
92
  return spec.matches_for_glob(glob) if spec.respond_to?(:matches_for_glob)
99
93
 
@@ -110,18 +104,6 @@ module Bundler
110
104
  obj.to_s
111
105
  end
112
106
 
113
- def configuration
114
- require_relative "psyched_yaml"
115
- Gem.configuration
116
- rescue Gem::SystemExitException, LoadError => e
117
- Bundler.ui.error "#{e.class}: #{e.message}"
118
- Bundler.ui.trace e
119
- raise
120
- rescue YamlLibrarySyntaxError => e
121
- raise YamlSyntaxError.new(e, "Your RubyGems configuration, which is " \
122
- "usually located in ~/.gemrc, contains invalid YAML syntax.")
123
- end
124
-
125
107
  def ruby_engine
126
108
  Gem.ruby_engine
127
109
  end
@@ -144,19 +126,6 @@ module Bundler
144
126
  end
145
127
  end
146
128
 
147
- def sources=(val)
148
- # Gem.configuration creates a new Gem::ConfigFile, which by default will read ~/.gemrc
149
- # If that file exists, its settings (including sources) will overwrite the values we
150
- # are about to set here. In order to avoid that, we force memoizing the config file now.
151
- configuration
152
-
153
- Gem.sources = val
154
- end
155
-
156
- def sources
157
- Gem.sources
158
- end
159
-
160
129
  def gem_dir
161
130
  Gem.dir
162
131
  end
@@ -234,32 +203,9 @@ module Bundler
234
203
  EXT_LOCK
235
204
  end
236
205
 
237
- def with_build_args(args)
238
- ext_lock.synchronize do
239
- old_args = build_args
240
- begin
241
- self.build_args = args
242
- yield
243
- ensure
244
- self.build_args = old_args
245
- end
246
- end
247
- end
248
-
249
- def spec_from_gem(path, policy = nil)
250
- require "rubygems/security"
251
- require_relative "psyched_yaml"
252
- gem_from_path(path, security_policies[policy]).spec
253
- rescue Exception, Gem::Exception, Gem::Security::Exception => e # rubocop:disable Lint/RescueException
254
- if e.is_a?(Gem::Security::Exception) ||
255
- e.message =~ /unknown trust policy|unsigned gem/i ||
256
- e.message =~ /couldn't verify (meta)?data signature/i
257
- raise SecurityError,
258
- "The gem #{File.basename(path, ".gem")} can't be installed because " \
259
- "the security policy didn't allow it, with the message: #{e.message}"
260
- else
261
- raise e
262
- end
206
+ def spec_from_gem(path)
207
+ require "rubygems/package"
208
+ Gem::Package.new(path).spec
263
209
  end
264
210
 
265
211
  def build_gem(gem_dir, spec)
@@ -502,14 +448,15 @@ module Bundler
502
448
  end
503
449
 
504
450
  def fetch_specs(remote, name)
451
+ require "rubygems/remote_fetcher"
505
452
  path = remote.uri.to_s + "#{name}.#{Gem.marshal_version}.gz"
506
453
  fetcher = gem_remote_fetcher
507
454
  fetcher.headers = { "X-Gemfile-Source" => remote.original_uri.to_s } if remote.original_uri
508
455
  string = fetcher.fetch_path(path)
509
456
  Bundler.load_marshal(string)
510
- rescue Gem::RemoteFetcher::FetchError => e
457
+ rescue Gem::RemoteFetcher::FetchError
511
458
  # it's okay for prerelease to fail
512
- raise e unless name == "prerelease_specs"
459
+ raise unless name == "prerelease_specs"
513
460
  end
514
461
 
515
462
  def fetch_all_remote_specs(remote)
@@ -519,12 +466,32 @@ module Bundler
519
466
  specs.concat(pres)
520
467
  end
521
468
 
522
- def download_gem(spec, uri, path)
469
+ def download_gem(spec, uri, cache_dir)
470
+ require "rubygems/remote_fetcher"
523
471
  uri = Bundler.settings.mirror_for(uri)
524
472
  fetcher = gem_remote_fetcher
525
473
  fetcher.headers = { "X-Gemfile-Source" => spec.remote.original_uri.to_s } if spec.remote.original_uri
526
474
  Bundler::Retry.new("download gem from #{uri}").attempts do
527
- fetcher.download(spec, uri, path)
475
+ gem_file_name = spec.file_name
476
+ local_gem_path = File.join cache_dir, gem_file_name
477
+ return if File.exist? local_gem_path
478
+
479
+ begin
480
+ remote_gem_path = uri + "gems/#{gem_file_name}"
481
+ remote_gem_path = remote_gem_path.to_s if provides?("< 3.2.0.rc.1")
482
+
483
+ SharedHelpers.filesystem_access(local_gem_path) do
484
+ fetcher.cache_update_path remote_gem_path, local_gem_path
485
+ end
486
+ rescue Gem::RemoteFetcher::FetchError
487
+ raise if spec.original_platform == spec.platform
488
+
489
+ original_gem_file_name = "#{spec.original_name}.gem"
490
+ raise if gem_file_name == original_gem_file_name
491
+
492
+ gem_file_name = original_gem_file_name
493
+ retry
494
+ end
528
495
  end
529
496
  rescue Gem::RemoteFetcher::FetchError => e
530
497
  raise Bundler::HTTPError, "Could not download gem from #{uri} due to underlying error <#{e.message}>"
@@ -532,17 +499,10 @@ module Bundler
532
499
 
533
500
  def gem_remote_fetcher
534
501
  require "rubygems/remote_fetcher"
535
- proxy = configuration[:http_proxy]
502
+ proxy = Gem.configuration[:http_proxy]
536
503
  Gem::RemoteFetcher.new(proxy)
537
504
  end
538
505
 
539
- def gem_from_path(path, policy = nil)
540
- require "rubygems/package"
541
- p = Gem::Package.new(path)
542
- p.security_policy = policy if policy
543
- p
544
- end
545
-
546
506
  def build(spec, skip_validation = false)
547
507
  require "rubygems/package"
548
508
  Gem::Package.build(spec, skip_validation)
@@ -552,10 +512,6 @@ module Bundler
552
512
  Gem::REPOSITORY_SUBDIRECTORIES
553
513
  end
554
514
 
555
- def install_with_build_args(args)
556
- yield
557
- end
558
-
559
515
  def path_separator
560
516
  Gem.path_separator
561
517
  end
@@ -585,6 +541,10 @@ module Bundler
585
541
  end
586
542
  end
587
543
 
544
+ def find_bundler(version)
545
+ find_name("bundler").find {|s| s.version.to_s == version }
546
+ end
547
+
588
548
  def find_name(name)
589
549
  Gem::Specification.stubs_for(name).map(&:to_spec)
590
550
  end
@@ -598,14 +558,6 @@ module Bundler
598
558
  Gem::Specification.send(:default_stubs, "*.gemspec")
599
559
  end
600
560
  end
601
-
602
- def use_gemdeps(gemfile)
603
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path(gemfile)
604
- require_relative "gemdeps"
605
- runtime = Bundler.setup
606
- activated_spec_names = runtime.requested_specs.map(&:to_spec).sort_by(&:name)
607
- [Gemdeps.new(runtime), activated_spec_names]
608
- end
609
561
  end
610
562
 
611
563
  def self.rubygems
@@ -125,7 +125,6 @@ module Bundler
125
125
  specs_to_cache.each do |spec|
126
126
  next if spec.name == "bundler"
127
127
  next if spec.source.is_a?(Source::Gemspec)
128
- spec.source.send(:fetch_gem, spec) if Bundler.settings[:cache_all_platforms] && spec.source.respond_to?(:fetch_gem, true)
129
128
  spec.source.cache(spec, custom_path) if spec.source.respond_to?(:cache)
130
129
  end
131
130
 
@@ -265,7 +264,7 @@ module Bundler
265
264
 
266
265
  return if manuals.empty?
267
266
  Bundler::SharedHelpers.set_env "MANPATH", manuals.concat(
268
- ENV["MANPATH"].to_s.split(File::PATH_SEPARATOR)
267
+ ENV["MANPATH"] ? ENV["MANPATH"].to_s.split(File::PATH_SEPARATOR) : [""]
269
268
  ).uniq.join(File::PATH_SEPARATOR)
270
269
  end
271
270
 
@@ -291,7 +290,7 @@ module Bundler
291
290
  return unless activated_spec = Bundler.rubygems.loaded_specs(spec.name)
292
291
  return if activated_spec.version == spec.version
293
292
 
294
- suggestion = if Bundler.rubygems.spec_default_gem?(activated_spec)
293
+ suggestion = if activated_spec.default_gem?
295
294
  "Since #{spec.name} is a default gem, you can either remove your dependency on it" \
296
295
  " or try updating to a newer version of bundler that supports #{spec.name} as a default gem."
297
296
  else