bundler 2.2.33 → 2.4.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (263) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +682 -1
  3. data/README.md +3 -6
  4. data/bundler.gemspec +8 -10
  5. data/exe/bundle +12 -24
  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/add.rb +1 -1
  10. data/lib/bundler/cli/binstubs.rb +5 -1
  11. data/lib/bundler/cli/check.rb +1 -1
  12. data/lib/bundler/cli/common.rb +4 -2
  13. data/lib/bundler/cli/config.rb +10 -1
  14. data/lib/bundler/cli/console.rb +2 -2
  15. data/lib/bundler/cli/doctor.rb +7 -1
  16. data/lib/bundler/cli/gem.rb +73 -41
  17. data/lib/bundler/cli/info.rb +11 -2
  18. data/lib/bundler/cli/init.rb +6 -2
  19. data/lib/bundler/cli/install.rb +15 -33
  20. data/lib/bundler/cli/lock.rb +8 -5
  21. data/lib/bundler/cli/open.rb +6 -4
  22. data/lib/bundler/cli/outdated.rb +13 -6
  23. data/lib/bundler/cli/platform.rb +2 -2
  24. data/lib/bundler/cli/show.rb +1 -1
  25. data/lib/bundler/cli/update.rb +6 -2
  26. data/lib/bundler/cli/viz.rb +1 -1
  27. data/lib/bundler/cli.rb +63 -20
  28. data/lib/bundler/compact_index_client/cache.rb +1 -10
  29. data/lib/bundler/compact_index_client/updater.rb +53 -39
  30. data/lib/bundler/compact_index_client.rb +0 -6
  31. data/lib/bundler/constants.rb +1 -1
  32. data/lib/bundler/current_ruby.rb +18 -6
  33. data/lib/bundler/definition.rb +289 -165
  34. data/lib/bundler/dependency.rb +24 -71
  35. data/lib/bundler/digest.rb +1 -1
  36. data/lib/bundler/dsl.rb +13 -45
  37. data/lib/bundler/endpoint_specification.rb +15 -13
  38. data/lib/bundler/env.rb +2 -2
  39. data/lib/bundler/environment_preserver.rb +3 -2
  40. data/lib/bundler/errors.rb +15 -15
  41. data/lib/bundler/feature_flag.rb +0 -2
  42. data/lib/bundler/fetcher/base.rb +6 -8
  43. data/lib/bundler/fetcher/compact_index.rb +18 -25
  44. data/lib/bundler/fetcher/dependency.rb +2 -6
  45. data/lib/bundler/fetcher/downloader.rb +2 -5
  46. data/lib/bundler/fetcher/index.rb +0 -26
  47. data/lib/bundler/fetcher.rb +22 -29
  48. data/lib/bundler/force_platform.rb +18 -0
  49. data/lib/bundler/friendly_errors.rb +21 -7
  50. data/lib/bundler/gem_helper.rb +2 -2
  51. data/lib/bundler/gem_helpers.rb +9 -2
  52. data/lib/bundler/gem_version_promoter.rb +53 -98
  53. data/lib/bundler/graph.rb +3 -3
  54. data/lib/bundler/index.rb +13 -51
  55. data/lib/bundler/injector.rb +18 -4
  56. data/lib/bundler/inline.rb +9 -21
  57. data/lib/bundler/installer/gem_installer.rb +13 -5
  58. data/lib/bundler/installer/parallel_installer.rb +3 -33
  59. data/lib/bundler/installer/standalone.rb +42 -11
  60. data/lib/bundler/installer.rb +21 -45
  61. data/lib/bundler/lazy_specification.rb +55 -54
  62. data/lib/bundler/lockfile_generator.rb +3 -3
  63. data/lib/bundler/lockfile_parser.rb +29 -27
  64. data/lib/bundler/man/bundle-add.1 +21 -5
  65. data/lib/bundler/man/bundle-add.1.ronn +16 -4
  66. data/lib/bundler/man/bundle-binstubs.1 +1 -1
  67. data/lib/bundler/man/bundle-cache.1 +9 -3
  68. data/lib/bundler/man/bundle-cache.1.ronn +9 -2
  69. data/lib/bundler/man/bundle-check.1 +1 -1
  70. data/lib/bundler/man/bundle-clean.1 +2 -2
  71. data/lib/bundler/man/bundle-clean.1.ronn +1 -1
  72. data/lib/bundler/man/bundle-config.1 +32 -16
  73. data/lib/bundler/man/bundle-config.1.ronn +29 -20
  74. data/lib/bundler/man/bundle-console.1 +53 -0
  75. data/lib/bundler/man/bundle-console.1.ronn +44 -0
  76. data/lib/bundler/man/bundle-doctor.1 +1 -1
  77. data/lib/bundler/man/bundle-exec.1 +6 -6
  78. data/lib/bundler/man/bundle-exec.1.ronn +6 -6
  79. data/lib/bundler/man/bundle-gem.1 +27 -37
  80. data/lib/bundler/man/bundle-gem.1.ronn +5 -5
  81. data/lib/bundler/man/bundle-help.1 +13 -0
  82. data/lib/bundler/man/bundle-help.1.ronn +12 -0
  83. data/lib/bundler/man/bundle-info.1 +1 -1
  84. data/lib/bundler/man/bundle-init.1 +5 -1
  85. data/lib/bundler/man/bundle-init.1.ronn +2 -0
  86. data/lib/bundler/man/bundle-inject.1 +5 -2
  87. data/lib/bundler/man/bundle-inject.1.ronn +3 -1
  88. data/lib/bundler/man/bundle-install.1 +6 -31
  89. data/lib/bundler/man/bundle-install.1.ronn +8 -31
  90. data/lib/bundler/man/bundle-list.1 +1 -1
  91. data/lib/bundler/man/bundle-lock.1 +1 -1
  92. data/lib/bundler/man/bundle-open.1 +22 -2
  93. data/lib/bundler/man/bundle-open.1.ronn +9 -1
  94. data/lib/bundler/man/bundle-outdated.1 +15 -18
  95. data/lib/bundler/man/bundle-outdated.1.ronn +13 -19
  96. data/lib/bundler/man/bundle-platform.1 +16 -6
  97. data/lib/bundler/man/bundle-platform.1.ronn +14 -7
  98. data/lib/bundler/man/bundle-plugin.1 +81 -0
  99. data/lib/bundler/man/bundle-plugin.1.ronn +59 -0
  100. data/lib/bundler/man/bundle-pristine.1 +1 -1
  101. data/lib/bundler/man/bundle-remove.1 +1 -1
  102. data/lib/bundler/man/bundle-show.1 +1 -1
  103. data/lib/bundler/man/bundle-update.1 +2 -2
  104. data/lib/bundler/man/bundle-update.1.ronn +2 -1
  105. data/lib/bundler/man/bundle-version.1 +35 -0
  106. data/lib/bundler/man/bundle-version.1.ronn +24 -0
  107. data/lib/bundler/man/bundle-viz.1 +4 -1
  108. data/lib/bundler/man/bundle-viz.1.ronn +2 -0
  109. data/lib/bundler/man/bundle.1 +15 -10
  110. data/lib/bundler/man/bundle.1.ronn +12 -7
  111. data/lib/bundler/man/gemfile.5 +94 -83
  112. data/lib/bundler/man/gemfile.5.ronn +100 -87
  113. data/lib/bundler/man/index.txt +4 -0
  114. data/lib/bundler/match_metadata.rb +13 -0
  115. data/lib/bundler/match_platform.rb +0 -1
  116. data/lib/bundler/match_remote_metadata.rb +29 -0
  117. data/lib/bundler/mirror.rb +5 -7
  118. data/lib/bundler/plugin/api/source.rb +3 -9
  119. data/lib/bundler/plugin/index.rb +4 -4
  120. data/lib/bundler/plugin/installer/git.rb +0 -4
  121. data/lib/bundler/plugin/installer/rubygems.rb +0 -8
  122. data/lib/bundler/plugin/installer.rb +6 -3
  123. data/lib/bundler/plugin.rb +3 -1
  124. data/lib/bundler/process_lock.rb +1 -1
  125. data/lib/bundler/remote_specification.rb +7 -5
  126. data/lib/bundler/resolver/base.rb +107 -0
  127. data/lib/bundler/resolver/candidate.rb +94 -0
  128. data/lib/bundler/resolver/incompatibility.rb +15 -0
  129. data/lib/bundler/resolver/package.rb +72 -0
  130. data/lib/bundler/resolver/root.rb +25 -0
  131. data/lib/bundler/resolver/spec_group.rb +43 -71
  132. data/lib/bundler/resolver.rb +342 -302
  133. data/lib/bundler/ruby_dsl.rb +1 -1
  134. data/lib/bundler/ruby_version.rb +6 -19
  135. data/lib/bundler/rubygems_ext.rb +149 -28
  136. data/lib/bundler/rubygems_gem_installer.rb +32 -20
  137. data/lib/bundler/rubygems_integration.rb +24 -95
  138. data/lib/bundler/runtime.rb +2 -7
  139. data/lib/bundler/safe_marshal.rb +31 -0
  140. data/lib/bundler/self_manager.rb +168 -0
  141. data/lib/bundler/settings.rb +7 -12
  142. data/lib/bundler/setup.rb +4 -1
  143. data/lib/bundler/shared_helpers.rb +15 -22
  144. data/lib/bundler/source/git/git_proxy.rb +237 -74
  145. data/lib/bundler/source/git.rb +54 -38
  146. data/lib/bundler/source/metadata.rb +3 -4
  147. data/lib/bundler/source/path/installer.rb +1 -22
  148. data/lib/bundler/source/path.rb +7 -7
  149. data/lib/bundler/source/rubygems.rb +85 -128
  150. data/lib/bundler/source.rb +4 -5
  151. data/lib/bundler/source_list.rb +12 -2
  152. data/lib/bundler/source_map.rb +15 -2
  153. data/lib/bundler/spec_set.rb +62 -34
  154. data/lib/bundler/stub_specification.rb +5 -3
  155. data/lib/bundler/templates/Executable +3 -5
  156. data/lib/bundler/templates/Executable.bundler +6 -11
  157. data/lib/bundler/templates/Executable.standalone +4 -4
  158. data/lib/bundler/templates/Gemfile +0 -2
  159. data/lib/bundler/templates/newgem/Cargo.toml.tt +7 -0
  160. data/lib/bundler/templates/newgem/Gemfile.tt +3 -0
  161. data/lib/bundler/templates/newgem/README.md.tt +7 -11
  162. data/lib/bundler/templates/newgem/Rakefile.tt +22 -2
  163. data/lib/bundler/templates/newgem/bin/console.tt +0 -4
  164. data/lib/bundler/templates/newgem/circleci/config.yml.tt +12 -0
  165. data/lib/bundler/templates/newgem/ext/newgem/Cargo.toml.tt +15 -0
  166. data/lib/bundler/templates/newgem/ext/newgem/extconf-c.rb.tt +10 -0
  167. data/lib/bundler/templates/newgem/ext/newgem/extconf-rust.rb.tt +6 -0
  168. data/lib/bundler/templates/newgem/ext/newgem/newgem.c.tt +1 -1
  169. data/lib/bundler/templates/newgem/ext/newgem/src/lib.rs.tt +12 -0
  170. data/lib/bundler/templates/newgem/github/workflows/main.yml.tt +11 -1
  171. data/lib/bundler/templates/newgem/gitignore.tt +3 -0
  172. data/lib/bundler/templates/newgem/gitlab-ci.yml.tt +13 -4
  173. data/lib/bundler/templates/newgem/newgem.gemspec.tt +11 -4
  174. data/lib/bundler/templates/newgem/standard.yml.tt +1 -0
  175. data/lib/bundler/templates/newgem/test/minitest/{newgem_test.rb.tt → test_newgem.rb.tt} +1 -1
  176. data/lib/bundler/ui/shell.rb +36 -13
  177. data/lib/bundler/ui/silent.rb +21 -5
  178. data/lib/bundler/uri_normalizer.rb +23 -0
  179. data/lib/bundler/vendor/connection_pool/lib/connection_pool/timed_stack.rb +3 -3
  180. data/lib/bundler/vendor/connection_pool/lib/connection_pool/wrapper.rb +0 -1
  181. data/lib/bundler/vendor/connection_pool/lib/connection_pool.rb +3 -1
  182. data/lib/bundler/vendor/fileutils/lib/fileutils.rb +1351 -409
  183. data/lib/bundler/vendor/net-http-persistent/README.rdoc +1 -1
  184. data/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent.rb +1 -1
  185. data/lib/bundler/vendor/pub_grub/LICENSE.txt +21 -0
  186. data/lib/bundler/vendor/pub_grub/lib/pub_grub/assignment.rb +20 -0
  187. data/lib/bundler/vendor/pub_grub/lib/pub_grub/basic_package_source.rb +189 -0
  188. data/lib/bundler/vendor/pub_grub/lib/pub_grub/failure_writer.rb +182 -0
  189. data/lib/bundler/vendor/pub_grub/lib/pub_grub/incompatibility.rb +150 -0
  190. data/lib/bundler/vendor/pub_grub/lib/pub_grub/package.rb +43 -0
  191. data/lib/bundler/vendor/pub_grub/lib/pub_grub/partial_solution.rb +121 -0
  192. data/lib/bundler/vendor/pub_grub/lib/pub_grub/rubygems.rb +45 -0
  193. data/lib/bundler/vendor/pub_grub/lib/pub_grub/solve_failure.rb +19 -0
  194. data/lib/bundler/vendor/pub_grub/lib/pub_grub/static_package_source.rb +60 -0
  195. data/lib/bundler/vendor/pub_grub/lib/pub_grub/term.rb +105 -0
  196. data/lib/bundler/vendor/pub_grub/lib/pub_grub/version.rb +3 -0
  197. data/lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb +129 -0
  198. data/lib/bundler/vendor/pub_grub/lib/pub_grub/version_range.rb +411 -0
  199. data/lib/bundler/vendor/pub_grub/lib/pub_grub/version_solver.rb +248 -0
  200. data/lib/bundler/vendor/pub_grub/lib/pub_grub/version_union.rb +178 -0
  201. data/lib/bundler/vendor/pub_grub/lib/pub_grub.rb +31 -0
  202. data/lib/bundler/vendor/thor/lib/thor/actions/file_manipulation.rb +6 -6
  203. data/lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb +1 -2
  204. data/lib/bundler/vendor/thor/lib/thor/actions.rb +6 -2
  205. data/lib/bundler/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb +6 -0
  206. data/lib/bundler/vendor/thor/lib/thor/error.rb +9 -4
  207. data/lib/bundler/vendor/thor/lib/thor/parser/options.rb +19 -1
  208. data/lib/bundler/vendor/thor/lib/thor/shell/basic.rb +23 -5
  209. data/lib/bundler/vendor/thor/lib/thor/shell.rb +1 -1
  210. data/lib/bundler/vendor/thor/lib/thor/util.rb +1 -1
  211. data/lib/bundler/vendor/thor/lib/thor/version.rb +1 -1
  212. data/lib/bundler/vendor/tsort/lib/tsort.rb +318 -319
  213. data/lib/bundler/vendor/uri/lib/uri/common.rb +76 -91
  214. data/lib/bundler/vendor/uri/lib/uri/file.rb +7 -1
  215. data/lib/bundler/vendor/uri/lib/uri/ftp.rb +2 -2
  216. data/lib/bundler/vendor/uri/lib/uri/generic.rb +32 -13
  217. data/lib/bundler/vendor/uri/lib/uri/http.rb +40 -3
  218. data/lib/bundler/vendor/uri/lib/uri/https.rb +2 -2
  219. data/lib/bundler/vendor/uri/lib/uri/ldap.rb +2 -2
  220. data/lib/bundler/vendor/uri/lib/uri/ldaps.rb +2 -1
  221. data/lib/bundler/vendor/uri/lib/uri/mailto.rb +2 -3
  222. data/lib/bundler/vendor/uri/lib/uri/rfc2396_parser.rb +16 -23
  223. data/lib/bundler/vendor/uri/lib/uri/rfc3986_parser.rb +12 -18
  224. data/lib/bundler/vendor/uri/lib/uri/version.rb +1 -1
  225. data/lib/bundler/vendor/uri/lib/uri/ws.rb +83 -0
  226. data/lib/bundler/vendor/uri/lib/uri/wss.rb +23 -0
  227. data/lib/bundler/vendor/uri/lib/uri.rb +3 -3
  228. data/lib/bundler/vendored_persistent.rb +1 -33
  229. data/lib/bundler/{vendored_tmpdir.rb → vendored_pub_grub.rb} +1 -1
  230. data/lib/bundler/version.rb +5 -1
  231. data/lib/bundler/worker.rb +5 -7
  232. data/lib/bundler.rb +47 -82
  233. metadata +52 -38
  234. data/lib/bundler/dep_proxy.rb +0 -55
  235. data/lib/bundler/gemdeps.rb +0 -29
  236. data/lib/bundler/psyched_yaml.rb +0 -22
  237. data/lib/bundler/templates/gems.rb +0 -8
  238. data/lib/bundler/templates/newgem/ext/newgem/extconf.rb.tt +0 -5
  239. data/lib/bundler/templates/newgem/travis.yml.tt +0 -6
  240. data/lib/bundler/vendor/molinillo/LICENSE +0 -9
  241. data/lib/bundler/vendor/molinillo/lib/molinillo/delegates/resolution_state.rb +0 -57
  242. data/lib/bundler/vendor/molinillo/lib/molinillo/delegates/specification_provider.rb +0 -88
  243. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/action.rb +0 -36
  244. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/add_edge_no_circular.rb +0 -66
  245. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/add_vertex.rb +0 -62
  246. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/delete_edge.rb +0 -63
  247. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/detach_vertex_named.rb +0 -61
  248. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/log.rb +0 -126
  249. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/set_payload.rb +0 -46
  250. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/tag.rb +0 -36
  251. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb +0 -164
  252. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb +0 -255
  253. data/lib/bundler/vendor/molinillo/lib/molinillo/errors.rb +0 -143
  254. data/lib/bundler/vendor/molinillo/lib/molinillo/gem_metadata.rb +0 -6
  255. data/lib/bundler/vendor/molinillo/lib/molinillo/modules/specification_provider.rb +0 -112
  256. data/lib/bundler/vendor/molinillo/lib/molinillo/modules/ui.rb +0 -67
  257. data/lib/bundler/vendor/molinillo/lib/molinillo/resolution.rb +0 -839
  258. data/lib/bundler/vendor/molinillo/lib/molinillo/resolver.rb +0 -46
  259. data/lib/bundler/vendor/molinillo/lib/molinillo/state.rb +0 -58
  260. data/lib/bundler/vendor/molinillo/lib/molinillo.rb +0 -11
  261. data/lib/bundler/vendor/tmpdir/lib/tmpdir.rb +0 -154
  262. data/lib/bundler/vendored_molinillo.rb +0 -4
  263. data/lib/bundler/version_ranges.rb +0 -122
@@ -9,7 +9,7 @@ module Bundler
9
9
  raise GemfileError, "Please define :engine" if options[:engine_version] && options[:engine].nil?
10
10
 
11
11
  if options[:engine] == "ruby" && options[:engine_version] &&
12
- ruby_version != Array(options[:engine_version])
12
+ ruby_version != Array(options[:engine_version])
13
13
  raise GemfileEvalError, "ruby_version must match the :engine_version for MRI"
14
14
  end
15
15
  @ruby_version = RubyVersion.new(ruby_version, options[:patchlevel], options[:engine], options[:engine_version])
@@ -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,24 +103,11 @@ 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
- @ruby_version ||= RubyVersion.new(ruby_version, patchlevel, ruby_engine, ruby_engine_version)
111
- end
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? }
110
+ @system ||= RubyVersion.new(ruby_version, patchlevel, ruby_engine, ruby_engine_version)
124
111
  end
125
112
 
126
113
  private
@@ -4,14 +4,35 @@ 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"
19
+ require_relative "force_platform"
11
20
  require_relative "match_platform"
12
21
 
22
+ # Cherry-pick fixes to `Gem.ruby_version` to be useful for modern Bundler
23
+ # versions and ignore patchlevels
24
+ # (https://github.com/rubygems/rubygems/pull/5472,
25
+ # https://github.com/rubygems/rubygems/pull/5486). May be removed once RubyGems
26
+ # 3.3.12 support is dropped.
27
+ unless Gem.ruby_version.to_s == RUBY_VERSION || RUBY_PATCHLEVEL == -1
28
+ Gem.instance_variable_set(:@ruby_version, Gem::Version.new(RUBY_VERSION))
29
+ end
30
+
13
31
  module Gem
14
32
  class Specification
33
+ include ::Bundler::MatchMetadata
34
+ include ::Bundler::MatchPlatform
35
+
15
36
  attr_accessor :remote, :location, :relative_loaded_from
16
37
 
17
38
  remove_method :source
@@ -24,12 +45,8 @@ module Gem
24
45
  alias_method :rg_loaded_from, :loaded_from
25
46
 
26
47
  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" }
48
+ if source.respond_to?(:root)
49
+ Pathname.new(loaded_from).dirname.expand_path(source.root).to_s.tap {|x| x.untaint if RUBY_VERSION < "2.7" }
33
50
  else
34
51
  rg_full_gem_path
35
52
  end
@@ -49,7 +66,9 @@ module Gem
49
66
 
50
67
  alias_method :rg_extension_dir, :extension_dir
51
68
  def extension_dir
52
- @bundler_extension_dir ||= if source.respond_to?(:extension_dir_name)
69
+ # following instance variable is already used in original method
70
+ # and that is the reason to prefix it with bundler_ and add rubocop exception
71
+ @bundler_extension_dir ||= if source.respond_to?(:extension_dir_name) # rubocop:disable Naming/MemoizedInstanceVariableName
53
72
  unique_extension_dir = [source.extension_dir_name, File.basename(full_gem_path)].uniq.join("-")
54
73
  File.expand_path(File.join(extensions_dir, unique_extension_dir))
55
74
  else
@@ -62,6 +81,23 @@ module Gem
62
81
  full_gem_path
63
82
  end
64
83
 
84
+ unless const_defined?(:LATEST_RUBY_WITHOUT_PATCH_VERSIONS)
85
+ LATEST_RUBY_WITHOUT_PATCH_VERSIONS = Gem::Version.new("2.1")
86
+
87
+ alias_method :rg_required_ruby_version=, :required_ruby_version=
88
+ def required_ruby_version=(req)
89
+ self.rg_required_ruby_version = req
90
+
91
+ @required_ruby_version.requirements.map! do |op, v|
92
+ if v >= LATEST_RUBY_WITHOUT_PATCH_VERSIONS && v.release.segments.size == 4
93
+ [op == "~>" ? "=" : op, Gem::Version.new(v.segments.tap {|s| s.delete_at(3) }.join("."))]
94
+ else
95
+ [op, v]
96
+ end
97
+ end
98
+ end
99
+ end
100
+
65
101
  def groups
66
102
  @groups ||= []
67
103
  end
@@ -81,6 +117,17 @@ module Gem
81
117
  gemfile
82
118
  end
83
119
 
120
+ # Backfill missing YAML require when not defined. Fixed since 3.1.0.pre1.
121
+ module YamlBackfiller
122
+ def to_yaml(opts = {})
123
+ Gem.load_yaml unless defined?(::YAML)
124
+
125
+ super(opts)
126
+ end
127
+ end
128
+
129
+ prepend YamlBackfiller
130
+
84
131
  def nondevelopment_dependencies
85
132
  dependencies - development_dependencies
86
133
  end
@@ -109,10 +156,18 @@ module Gem
109
156
  end
110
157
 
111
158
  class Dependency
159
+ include ::Bundler::ForcePlatform
160
+
112
161
  attr_accessor :source, :groups
113
162
 
114
163
  alias_method :eql?, :==
115
164
 
165
+ def force_ruby_platform
166
+ return @force_ruby_platform if defined?(@force_ruby_platform) && !@force_ruby_platform.nil?
167
+
168
+ @force_ruby_platform = default_force_ruby_platform
169
+ end
170
+
116
171
  def encode_with(coder)
117
172
  to_yaml_properties.each do |ivar|
118
173
  coder[ivar.to_s.sub(/^@/, "")] = instance_variable_get(ivar)
@@ -138,6 +193,8 @@ module Gem
138
193
  class Requirement
139
194
  module OrderIndependentComparison
140
195
  def ==(other)
196
+ return unless Gem::Requirement === other
197
+
141
198
  if _requirements_sorted? && other._requirements_sorted?
142
199
  super
143
200
  else
@@ -148,9 +205,9 @@ module Gem
148
205
  protected
149
206
 
150
207
  def _requirements_sorted?
151
- return @_are_requirements_sorted if defined?(@_are_requirements_sorted)
208
+ return @_requirements_sorted if defined?(@_requirements_sorted)
152
209
  strings = as_list
153
- @_are_requirements_sorted = strings == strings.sort
210
+ @_requirements_sorted = strings == strings.sort
154
211
  end
155
212
 
156
213
  def _with_sorted_requirements
@@ -181,11 +238,56 @@ module Gem
181
238
  require "rubygems/platform"
182
239
 
183
240
  class Platform
184
- JAVA = Gem::Platform.new("java") unless defined?(JAVA)
185
- MSWIN = Gem::Platform.new("mswin32") unless defined?(MSWIN)
186
- MSWIN64 = Gem::Platform.new("mswin64") unless defined?(MSWIN64)
187
- MINGW = Gem::Platform.new("x86-mingw32") unless defined?(MINGW)
188
- X64_MINGW = Gem::Platform.new("x64-mingw32") unless defined?(X64_MINGW)
241
+ JAVA = Gem::Platform.new("java")
242
+ MSWIN = Gem::Platform.new("mswin32")
243
+ MSWIN64 = Gem::Platform.new("mswin64")
244
+ MINGW = Gem::Platform.new("x86-mingw32")
245
+ X64_MINGW = [Gem::Platform.new("x64-mingw32"),
246
+ Gem::Platform.new("x64-mingw-ucrt")].freeze
247
+ WINDOWS = [MSWIN, MSWIN64, MINGW, X64_MINGW].flatten.freeze
248
+ X64_LINUX = Gem::Platform.new("x86_64-linux")
249
+ X64_LINUX_MUSL = Gem::Platform.new("x86_64-linux-musl")
250
+
251
+ if X64_LINUX === X64_LINUX_MUSL
252
+ remove_method :===
253
+
254
+ def ===(other)
255
+ return nil unless Gem::Platform === other
256
+
257
+ # universal-mingw32 matches x64-mingw-ucrt
258
+ return true if (@cpu == "universal" || other.cpu == "universal") &&
259
+ @os.start_with?("mingw") && other.os.start_with?("mingw")
260
+
261
+ # cpu
262
+ ([nil,"universal"].include?(@cpu) || [nil, "universal"].include?(other.cpu) || @cpu == other.cpu ||
263
+ (@cpu == "arm" && other.cpu.start_with?("arm"))) &&
264
+
265
+ # os
266
+ @os == other.os &&
267
+
268
+ # version
269
+ (
270
+ (@os != "linux" && (@version.nil? || other.version.nil?)) ||
271
+ (@os == "linux" && (normalized_linux_version_ext == other.normalized_linux_version_ext || ["musl#{@version}", "musleabi#{@version}", "musleabihf#{@version}"].include?(other.version))) ||
272
+ @version == other.version
273
+ )
274
+ end
275
+
276
+ # This is a copy of RubyGems 3.3.23 or higher `normalized_linux_method`.
277
+ # Once only 3.3.23 is supported, we can use the method in RubyGems.
278
+ def normalized_linux_version_ext
279
+ return nil unless @version
280
+
281
+ without_gnu_nor_abi_modifiers = @version.sub(/\Agnu/, "").sub(/eabi(hf)?\Z/, "")
282
+ return nil if without_gnu_nor_abi_modifiers.empty?
283
+
284
+ without_gnu_nor_abi_modifiers
285
+ end
286
+ end
287
+
288
+ if RUBY_ENGINE == "truffleruby" && !defined?(REUSE_AS_BINARY_ON_TRUFFLERUBY)
289
+ REUSE_AS_BINARY_ON_TRUFFLERUBY = %w[libv8 libv8-node sorbet-static].freeze
290
+ end
189
291
  end
190
292
 
191
293
  Platform.singleton_class.module_eval do
@@ -197,14 +299,43 @@ module Gem
197
299
  def match_gem?(platform, gem_name)
198
300
  match_platforms?(platform, Gem.platforms)
199
301
  end
302
+ end
303
+
304
+ match_platforms_defined = Gem::Platform.respond_to?(:match_platforms?, true)
305
+
306
+ if !match_platforms_defined || Gem::Platform.send(:match_platforms?, Gem::Platform::X64_LINUX_MUSL, [Gem::Platform::X64_LINUX])
200
307
 
201
308
  private
202
309
 
310
+ remove_method :match_platforms? if match_platforms_defined
311
+
203
312
  def match_platforms?(platform, platforms)
204
313
  platforms.any? do |local_platform|
205
314
  platform.nil? ||
206
315
  local_platform == platform ||
207
- (local_platform != Gem::Platform::RUBY && local_platform =~ platform)
316
+ (local_platform != Gem::Platform::RUBY && platform =~ local_platform)
317
+ end
318
+ end
319
+ end
320
+ end
321
+
322
+ # On universal Rubies, resolve the "universal" arch to the real CPU arch, without changing the extension directory.
323
+ class Specification
324
+ if /^universal\.(?<arch>.*?)-/ =~ (CROSS_COMPILING || RUBY_PLATFORM)
325
+ local_platform = Platform.local
326
+ if local_platform.cpu == "universal"
327
+ ORIGINAL_LOCAL_PLATFORM = local_platform.to_s.freeze
328
+
329
+ local_platform.cpu = if arch == "arm64e" # arm64e is only permitted for Apple system binaries
330
+ "arm64"
331
+ else
332
+ arch
333
+ end
334
+
335
+ def extensions_dir
336
+ Gem.default_ext_dir_for(base_dir) ||
337
+ File.join(base_dir, "extensions", ORIGINAL_LOCAL_PLATFORM,
338
+ Gem.extension_api_version)
208
339
  end
209
340
  end
210
341
  end
@@ -218,17 +349,7 @@ module Gem
218
349
  end
219
350
 
220
351
  def glob_files_in_dir(glob, base_path)
221
- if RUBY_VERSION >= "2.5"
222
- Dir.glob(glob, :base => base_path).map! {|f| File.expand_path(f, base_path) }
223
- else
224
- Dir.glob(File.join(base_path.to_s.gsub(/[\[\]]/, '\\\\\\&'), glob)).map! {|f| File.expand_path(f) }
225
- end
352
+ Dir.glob(glob, :base => base_path).map! {|f| File.expand_path(f, base_path) }
226
353
  end
227
354
  end
228
355
  end
229
-
230
- module Gem
231
- class Specification
232
- include ::Bundler::MatchPlatform
233
- end
234
- end
@@ -25,7 +25,7 @@ module Bundler
25
25
 
26
26
  extract_files
27
27
 
28
- build_extensions
28
+ build_extensions if spec.extensions.any?
29
29
  write_build_info_file
30
30
  run_post_build_hooks
31
31
 
@@ -66,41 +66,53 @@ module Bundler
66
66
 
67
67
  def build_extensions
68
68
  extension_cache_path = options[:bundler_extension_cache_path]
69
- unless extension_cache_path && extension_dir = spec.extension_dir
70
- 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)
71
72
  return super
72
73
  end
73
74
 
74
- extension_dir = Pathname.new(extension_dir)
75
75
  build_complete = SharedHelpers.filesystem_access(extension_cache_path.join("gem.build_complete"), :read, &:file?)
76
76
  if build_complete && !options[:force]
77
- SharedHelpers.filesystem_access(extension_dir.parent, &:mkpath)
77
+ SharedHelpers.filesystem_access(File.dirname(extension_dir)) do |p|
78
+ FileUtils.mkpath p
79
+ end
78
80
  SharedHelpers.filesystem_access(extension_cache_path) do
79
- FileUtils.cp_r extension_cache_path, spec.extension_dir
81
+ FileUtils.cp_r extension_cache_path, extension_dir
80
82
  end
81
83
  else
82
- require "shellwords" # compensate missing require in rubygems before version 3.2.25
84
+ prepare_extension_build(extension_dir)
83
85
  super
84
- if extension_dir.directory? # not made for gems without extensions
85
- SharedHelpers.filesystem_access(extension_cache_path.parent, &:mkpath)
86
- SharedHelpers.filesystem_access(extension_cache_path) do
87
- FileUtils.cp_r extension_dir, extension_cache_path
88
- 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
89
89
  end
90
90
  end
91
91
  end
92
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
+
93
101
  private
94
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
+
95
110
  def strict_rm_rf(dir)
96
- # FileUtils.rm_rf should probably rise in case of permission issues like
97
- # `rm -rf` does. However, it fails to delete the folder silently due to
98
- # https://github.com/ruby/fileutils/issues/57. It should probably be fixed
99
- # inside `fileutils` but for now I`m checking whether the folder was
100
- # removed after it completes, and raising otherwise.
101
- FileUtils.rm_rf dir
102
-
103
- raise PermissionError.new(dir, :delete) if File.directory?(dir)
111
+ Bundler.rm_rf dir
112
+ rescue StandardError => e
113
+ raise unless File.exist?(dir)
114
+
115
+ raise DirectoryRemovalError.new(e, "Could not delete previous installation of `#{dir}`")
104
116
  end
105
117
 
106
118
  def validate_bundler_checksum(checksum)
@@ -12,25 +12,21 @@ 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
@@ -108,18 +104,6 @@ module Bundler
108
104
  obj.to_s
109
105
  end
110
106
 
111
- def configuration
112
- require_relative "psyched_yaml"
113
- Gem.configuration
114
- rescue Gem::SystemExitException, LoadError => e
115
- Bundler.ui.error "#{e.class}: #{e.message}"
116
- Bundler.ui.trace e
117
- raise
118
- rescue YamlLibrarySyntaxError => e
119
- raise YamlSyntaxError.new(e, "Your RubyGems configuration, which is " \
120
- "usually located in ~/.gemrc, contains invalid YAML syntax.")
121
- end
122
-
123
107
  def ruby_engine
124
108
  Gem.ruby_engine
125
109
  end
@@ -142,19 +126,6 @@ module Bundler
142
126
  end
143
127
  end
144
128
 
145
- def sources=(val)
146
- # Gem.configuration creates a new Gem::ConfigFile, which by default will read ~/.gemrc
147
- # If that file exists, its settings (including sources) will overwrite the values we
148
- # are about to set here. In order to avoid that, we force memoizing the config file now.
149
- configuration
150
-
151
- Gem.sources = val
152
- end
153
-
154
- def sources
155
- Gem.sources
156
- end
157
-
158
129
  def gem_dir
159
130
  Gem.dir
160
131
  end
@@ -232,32 +203,9 @@ module Bundler
232
203
  EXT_LOCK
233
204
  end
234
205
 
235
- def with_build_args(args)
236
- ext_lock.synchronize do
237
- old_args = build_args
238
- begin
239
- self.build_args = args
240
- yield
241
- ensure
242
- self.build_args = old_args
243
- end
244
- end
245
- end
246
-
247
- def spec_from_gem(path, policy = nil)
248
- require "rubygems/security"
249
- require_relative "psyched_yaml"
250
- gem_from_path(path, security_policies[policy]).spec
251
- rescue Exception, Gem::Exception, Gem::Security::Exception => e # rubocop:disable Lint/RescueException
252
- if e.is_a?(Gem::Security::Exception) ||
253
- e.message =~ /unknown trust policy|unsigned gem/i ||
254
- e.message =~ /couldn't verify (meta)?data signature/i
255
- raise SecurityError,
256
- "The gem #{File.basename(path, ".gem")} can't be installed because " \
257
- "the security policy didn't allow it, with the message: #{e.message}"
258
- else
259
- raise e
260
- end
206
+ def spec_from_gem(path)
207
+ require "rubygems/package"
208
+ Gem::Package.new(path).spec
261
209
  end
262
210
 
263
211
  def build_gem(gem_dir, spec)
@@ -279,10 +227,14 @@ module Bundler
279
227
 
280
228
  def reverse_rubygems_kernel_mixin
281
229
  # Disable rubygems' gem activation system
282
- kernel = (class << ::Kernel; self; end)
283
- [kernel, ::Kernel].each do |k|
284
- if k.private_method_defined?(:gem_original_require)
285
- redefine_method(k, :require, k.instance_method(:gem_original_require))
230
+ if Gem.respond_to?(:discover_gems_on_require=)
231
+ Gem.discover_gems_on_require = false
232
+ else
233
+ kernel = (class << ::Kernel; self; end)
234
+ [kernel, ::Kernel].each do |k|
235
+ if k.private_method_defined?(:gem_original_require)
236
+ redefine_method(k, :require, k.instance_method(:gem_original_require))
237
+ end
286
238
  end
287
239
  end
288
240
  end
@@ -324,11 +276,7 @@ module Bundler
324
276
 
325
277
  e = Gem::LoadError.new(message)
326
278
  e.name = dep.name
327
- if e.respond_to?(:requirement=)
328
- e.requirement = dep.requirement
329
- elsif e.respond_to?(:version_requirement=)
330
- e.version_requirement = dep.requirement
331
- end
279
+ e.requirement = dep.requirement
332
280
  raise e
333
281
  end
334
282
 
@@ -505,7 +453,7 @@ module Bundler
505
453
  fetcher = gem_remote_fetcher
506
454
  fetcher.headers = { "X-Gemfile-Source" => remote.original_uri.to_s } if remote.original_uri
507
455
  string = fetcher.fetch_path(path)
508
- Bundler.load_marshal(string)
456
+ Bundler.safe_load_marshal(string)
509
457
  rescue Gem::RemoteFetcher::FetchError
510
458
  # it's okay for prerelease to fail
511
459
  raise unless name == "prerelease_specs"
@@ -551,30 +499,15 @@ module Bundler
551
499
 
552
500
  def gem_remote_fetcher
553
501
  require "rubygems/remote_fetcher"
554
- proxy = configuration[:http_proxy]
502
+ proxy = Gem.configuration[:http_proxy]
555
503
  Gem::RemoteFetcher.new(proxy)
556
504
  end
557
505
 
558
- def gem_from_path(path, policy = nil)
559
- require "rubygems/package"
560
- p = Gem::Package.new(path)
561
- p.security_policy = policy if policy
562
- p
563
- end
564
-
565
506
  def build(spec, skip_validation = false)
566
507
  require "rubygems/package"
567
508
  Gem::Package.build(spec, skip_validation)
568
509
  end
569
510
 
570
- def repository_subdirectories
571
- Gem::REPOSITORY_SUBDIRECTORIES
572
- end
573
-
574
- def install_with_build_args(args)
575
- yield
576
- end
577
-
578
511
  def path_separator
579
512
  Gem.path_separator
580
513
  end
@@ -604,6 +537,10 @@ module Bundler
604
537
  end
605
538
  end
606
539
 
540
+ def find_bundler(version)
541
+ find_name("bundler").find {|s| s.version.to_s == version }
542
+ end
543
+
607
544
  def find_name(name)
608
545
  Gem::Specification.stubs_for(name).map(&:to_spec)
609
546
  end
@@ -617,14 +554,6 @@ module Bundler
617
554
  Gem::Specification.send(:default_stubs, "*.gemspec")
618
555
  end
619
556
  end
620
-
621
- def use_gemdeps(gemfile)
622
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path(gemfile)
623
- require_relative "gemdeps"
624
- runtime = Bundler.setup
625
- activated_spec_names = runtime.requested_specs.map(&:to_spec).sort_by(&:name)
626
- [Gemdeps.new(runtime), activated_spec_names]
627
- end
628
557
  end
629
558
 
630
559
  def self.rubygems
@@ -94,7 +94,7 @@ module Bundler
94
94
  definition_method :requires
95
95
 
96
96
  def lock(opts = {})
97
- return if @definition.nothing_changed? && !@definition.unlocking?
97
+ return if @definition.no_resolve_needed?
98
98
  @definition.lock(Bundler.default_lockfile, opts[:preserve_unknown_sections])
99
99
  end
100
100
 
@@ -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
 
@@ -301,11 +300,7 @@ module Bundler
301
300
  e = Gem::LoadError.new "You have already activated #{activated_spec.name} #{activated_spec.version}, " \
302
301
  "but your Gemfile requires #{spec.name} #{spec.version}. #{suggestion}"
303
302
  e.name = spec.name
304
- if e.respond_to?(:requirement=)
305
- e.requirement = Gem::Requirement.new(spec.version.to_s)
306
- else
307
- e.version_requirement = Gem::Requirement.new(spec.version.to_s)
308
- end
303
+ e.requirement = Gem::Requirement.new(spec.version.to_s)
309
304
  raise e
310
305
  end
311
306
  end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bundler
4
+ module SafeMarshal
5
+ ALLOWED_CLASSES = [
6
+ Array,
7
+ FalseClass,
8
+ Gem::Specification,
9
+ Gem::Version,
10
+ Hash,
11
+ String,
12
+ Symbol,
13
+ Time,
14
+ TrueClass,
15
+ ].freeze
16
+
17
+ ERROR = "Unexpected class %s present in marshaled data. Only %s are allowed."
18
+
19
+ PROC = proc do |object|
20
+ object.tap do
21
+ unless ALLOWED_CLASSES.include?(object.class)
22
+ raise TypeError, format(ERROR, object.class, ALLOWED_CLASSES.join(", "))
23
+ end
24
+ end
25
+ end
26
+
27
+ def self.proc
28
+ PROC
29
+ end
30
+ end
31
+ end