bundler 2.2.16 → 2.4.19

Sign up to get free protection for your applications and to get access to all the features.
Files changed (280) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +971 -7
  3. data/README.md +4 -7
  4. data/bundler.gemspec +10 -13
  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 +6 -2
  11. data/lib/bundler/cli/cache.rb +1 -1
  12. data/lib/bundler/cli/check.rb +5 -3
  13. data/lib/bundler/cli/common.rb +6 -2
  14. data/lib/bundler/cli/config.rb +10 -1
  15. data/lib/bundler/cli/console.rb +2 -2
  16. data/lib/bundler/cli/doctor.rb +22 -5
  17. data/lib/bundler/cli/exec.rb +1 -6
  18. data/lib/bundler/cli/gem.rb +147 -35
  19. data/lib/bundler/cli/info.rb +28 -7
  20. data/lib/bundler/cli/init.rb +6 -2
  21. data/lib/bundler/cli/install.rb +26 -58
  22. data/lib/bundler/cli/issue.rb +4 -3
  23. data/lib/bundler/cli/list.rb +7 -1
  24. data/lib/bundler/cli/lock.rb +11 -4
  25. data/lib/bundler/cli/open.rb +7 -6
  26. data/lib/bundler/cli/outdated.rb +23 -17
  27. data/lib/bundler/cli/platform.rb +8 -6
  28. data/lib/bundler/cli/remove.rb +1 -2
  29. data/lib/bundler/cli/show.rb +1 -1
  30. data/lib/bundler/cli/update.rb +17 -8
  31. data/lib/bundler/cli/viz.rb +1 -1
  32. data/lib/bundler/cli.rb +95 -65
  33. data/lib/bundler/compact_index_client/cache.rb +1 -10
  34. data/lib/bundler/compact_index_client/updater.rb +56 -43
  35. data/lib/bundler/compact_index_client.rb +2 -8
  36. data/lib/bundler/constants.rb +1 -1
  37. data/lib/bundler/current_ruby.rb +19 -6
  38. data/lib/bundler/definition.rb +386 -419
  39. data/lib/bundler/dependency.rb +24 -71
  40. data/lib/bundler/digest.rb +71 -0
  41. data/lib/bundler/dsl.rb +48 -63
  42. data/lib/bundler/endpoint_specification.rb +15 -13
  43. data/lib/bundler/env.rb +3 -3
  44. data/lib/bundler/environment_preserver.rb +7 -3
  45. data/lib/bundler/errors.rb +30 -14
  46. data/lib/bundler/feature_flag.rb +0 -5
  47. data/lib/bundler/fetcher/base.rb +6 -8
  48. data/lib/bundler/fetcher/compact_index.rb +21 -28
  49. data/lib/bundler/fetcher/dependency.rb +2 -6
  50. data/lib/bundler/fetcher/downloader.rb +12 -10
  51. data/lib/bundler/fetcher/index.rb +1 -29
  52. data/lib/bundler/fetcher.rb +35 -30
  53. data/lib/bundler/force_platform.rb +18 -0
  54. data/lib/bundler/friendly_errors.rb +26 -39
  55. data/lib/bundler/gem_helper.rb +10 -22
  56. data/lib/bundler/gem_helpers.rb +9 -2
  57. data/lib/bundler/gem_version_promoter.rb +53 -98
  58. data/lib/bundler/graph.rb +3 -3
  59. data/lib/bundler/index.rb +14 -57
  60. data/lib/bundler/injector.rb +20 -6
  61. data/lib/bundler/inline.rb +10 -22
  62. data/lib/bundler/installer/gem_installer.rb +16 -21
  63. data/lib/bundler/installer/parallel_installer.rb +4 -34
  64. data/lib/bundler/installer/standalone.rb +53 -17
  65. data/lib/bundler/installer.rb +26 -58
  66. data/lib/bundler/lazy_specification.rb +72 -55
  67. data/lib/bundler/lockfile_generator.rb +3 -3
  68. data/lib/bundler/lockfile_parser.rb +31 -45
  69. data/lib/bundler/man/bundle-add.1 +21 -5
  70. data/lib/bundler/man/bundle-add.1.ronn +16 -4
  71. data/lib/bundler/man/bundle-binstubs.1 +1 -1
  72. data/lib/bundler/man/bundle-cache.1 +9 -3
  73. data/lib/bundler/man/bundle-cache.1.ronn +9 -2
  74. data/lib/bundler/man/bundle-check.1 +1 -1
  75. data/lib/bundler/man/bundle-clean.1 +2 -2
  76. data/lib/bundler/man/bundle-clean.1.ronn +1 -1
  77. data/lib/bundler/man/bundle-config.1 +50 -26
  78. data/lib/bundler/man/bundle-config.1.ronn +47 -32
  79. data/lib/bundler/man/bundle-console.1 +53 -0
  80. data/lib/bundler/man/bundle-console.1.ronn +44 -0
  81. data/lib/bundler/man/bundle-doctor.1 +1 -1
  82. data/lib/bundler/man/bundle-exec.1 +6 -6
  83. data/lib/bundler/man/bundle-exec.1.ronn +6 -6
  84. data/lib/bundler/man/bundle-gem.1 +37 -34
  85. data/lib/bundler/man/bundle-gem.1.ronn +21 -5
  86. data/lib/bundler/man/bundle-help.1 +13 -0
  87. data/lib/bundler/man/bundle-help.1.ronn +12 -0
  88. data/lib/bundler/man/bundle-info.1 +3 -3
  89. data/lib/bundler/man/bundle-info.1.ronn +3 -3
  90. data/lib/bundler/man/bundle-init.1 +5 -1
  91. data/lib/bundler/man/bundle-init.1.ronn +2 -0
  92. data/lib/bundler/man/bundle-inject.1 +5 -2
  93. data/lib/bundler/man/bundle-inject.1.ronn +3 -1
  94. data/lib/bundler/man/bundle-install.1 +6 -31
  95. data/lib/bundler/man/bundle-install.1.ronn +8 -31
  96. data/lib/bundler/man/bundle-list.1 +1 -1
  97. data/lib/bundler/man/bundle-lock.1 +1 -1
  98. data/lib/bundler/man/bundle-open.1 +22 -2
  99. data/lib/bundler/man/bundle-open.1.ronn +9 -1
  100. data/lib/bundler/man/bundle-outdated.1 +15 -18
  101. data/lib/bundler/man/bundle-outdated.1.ronn +13 -19
  102. data/lib/bundler/man/bundle-platform.1 +16 -6
  103. data/lib/bundler/man/bundle-platform.1.ronn +14 -7
  104. data/lib/bundler/man/bundle-plugin.1 +81 -0
  105. data/lib/bundler/man/bundle-plugin.1.ronn +59 -0
  106. data/lib/bundler/man/bundle-pristine.1 +1 -1
  107. data/lib/bundler/man/bundle-remove.1 +1 -1
  108. data/lib/bundler/man/bundle-show.1 +1 -1
  109. data/lib/bundler/man/bundle-update.1 +5 -5
  110. data/lib/bundler/man/bundle-update.1.ronn +5 -4
  111. data/lib/bundler/man/bundle-version.1 +35 -0
  112. data/lib/bundler/man/bundle-version.1.ronn +24 -0
  113. data/lib/bundler/man/bundle-viz.1 +4 -1
  114. data/lib/bundler/man/bundle-viz.1.ronn +2 -0
  115. data/lib/bundler/man/bundle.1 +15 -10
  116. data/lib/bundler/man/bundle.1.ronn +12 -7
  117. data/lib/bundler/man/gemfile.5 +131 -81
  118. data/lib/bundler/man/gemfile.5.ronn +111 -85
  119. data/lib/bundler/man/index.txt +4 -0
  120. data/lib/bundler/match_metadata.rb +13 -0
  121. data/lib/bundler/match_platform.rb +0 -1
  122. data/lib/bundler/match_remote_metadata.rb +29 -0
  123. data/lib/bundler/mirror.rb +5 -7
  124. data/lib/bundler/plugin/api/source.rb +17 -8
  125. data/lib/bundler/plugin/index.rb +9 -6
  126. data/lib/bundler/plugin/installer/git.rb +0 -4
  127. data/lib/bundler/plugin/installer/rubygems.rb +0 -8
  128. data/lib/bundler/plugin/installer.rb +9 -4
  129. data/lib/bundler/plugin.rb +30 -9
  130. data/lib/bundler/process_lock.rb +1 -1
  131. data/lib/bundler/remote_specification.rb +7 -5
  132. data/lib/bundler/resolver/base.rb +107 -0
  133. data/lib/bundler/resolver/candidate.rb +94 -0
  134. data/lib/bundler/resolver/incompatibility.rb +15 -0
  135. data/lib/bundler/resolver/package.rb +72 -0
  136. data/lib/bundler/resolver/root.rb +25 -0
  137. data/lib/bundler/resolver/spec_group.rb +42 -94
  138. data/lib/bundler/resolver.rb +331 -381
  139. data/lib/bundler/retry.rb +1 -1
  140. data/lib/bundler/ruby_dsl.rb +7 -1
  141. data/lib/bundler/ruby_version.rb +8 -21
  142. data/lib/bundler/rubygems_ext.rb +175 -34
  143. data/lib/bundler/rubygems_gem_installer.rb +46 -14
  144. data/lib/bundler/rubygems_integration.rb +57 -108
  145. data/lib/bundler/runtime.rb +20 -18
  146. data/lib/bundler/safe_marshal.rb +31 -0
  147. data/lib/bundler/self_manager.rb +168 -0
  148. data/lib/bundler/settings.rb +101 -30
  149. data/lib/bundler/setup.rb +5 -2
  150. data/lib/bundler/shared_helpers.rb +17 -32
  151. data/lib/bundler/source/git/git_proxy.rb +242 -77
  152. data/lib/bundler/source/git.rb +82 -41
  153. data/lib/bundler/source/metadata.rb +3 -4
  154. data/lib/bundler/source/path/installer.rb +1 -22
  155. data/lib/bundler/source/path.rb +7 -7
  156. data/lib/bundler/source/rubygems.rb +158 -212
  157. data/lib/bundler/source/rubygems_aggregate.rb +68 -0
  158. data/lib/bundler/source.rb +19 -5
  159. data/lib/bundler/source_list.rb +91 -52
  160. data/lib/bundler/source_map.rb +71 -0
  161. data/lib/bundler/spec_set.rb +69 -57
  162. data/lib/bundler/stub_specification.rb +5 -3
  163. data/lib/bundler/templates/Executable +3 -5
  164. data/lib/bundler/templates/Executable.bundler +11 -16
  165. data/lib/bundler/templates/Executable.standalone +4 -4
  166. data/lib/bundler/templates/Gemfile +0 -2
  167. data/lib/bundler/templates/newgem/Cargo.toml.tt +7 -0
  168. data/lib/bundler/templates/newgem/Gemfile.tt +8 -2
  169. data/lib/bundler/templates/newgem/README.md.tt +7 -11
  170. data/lib/bundler/templates/newgem/Rakefile.tt +27 -3
  171. data/lib/bundler/templates/newgem/bin/console.tt +0 -4
  172. data/lib/bundler/templates/newgem/circleci/config.yml.tt +12 -0
  173. data/lib/bundler/templates/newgem/ext/newgem/Cargo.toml.tt +15 -0
  174. data/lib/bundler/templates/newgem/ext/newgem/extconf-c.rb.tt +10 -0
  175. data/lib/bundler/templates/newgem/ext/newgem/extconf-rust.rb.tt +6 -0
  176. data/lib/bundler/templates/newgem/ext/newgem/newgem.c.tt +1 -1
  177. data/lib/bundler/templates/newgem/ext/newgem/src/lib.rs.tt +12 -0
  178. data/lib/bundler/templates/newgem/github/workflows/main.yml.tt +24 -3
  179. data/lib/bundler/templates/newgem/gitignore.tt +3 -0
  180. data/lib/bundler/templates/newgem/gitlab-ci.yml.tt +13 -4
  181. data/lib/bundler/templates/newgem/newgem.gemspec.tt +27 -18
  182. data/lib/bundler/templates/newgem/sig/newgem.rbs.tt +8 -0
  183. data/lib/bundler/templates/newgem/standard.yml.tt +3 -0
  184. data/lib/bundler/templates/newgem/test/minitest/{newgem_test.rb.tt → test_newgem.rb.tt} +1 -1
  185. data/lib/bundler/ui/rg_proxy.rb +1 -1
  186. data/lib/bundler/ui/shell.rb +36 -13
  187. data/lib/bundler/ui/silent.rb +21 -5
  188. data/lib/bundler/uri_normalizer.rb +23 -0
  189. data/lib/bundler/vendor/.document +1 -0
  190. data/lib/bundler/vendor/connection_pool/LICENSE +20 -0
  191. data/lib/bundler/vendor/connection_pool/lib/connection_pool/timed_stack.rb +19 -21
  192. data/lib/bundler/vendor/connection_pool/lib/connection_pool/version.rb +1 -1
  193. data/lib/bundler/vendor/connection_pool/lib/connection_pool/wrapper.rb +56 -0
  194. data/lib/bundler/vendor/connection_pool/lib/connection_pool.rb +41 -74
  195. data/lib/bundler/vendor/fileutils/LICENSE.txt +22 -0
  196. data/lib/bundler/vendor/fileutils/lib/fileutils.rb +1351 -409
  197. data/lib/bundler/vendor/net-http-persistent/README.rdoc +82 -0
  198. data/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent.rb +1 -1
  199. data/lib/bundler/vendor/pub_grub/LICENSE.txt +21 -0
  200. data/lib/bundler/vendor/pub_grub/lib/pub_grub/assignment.rb +20 -0
  201. data/lib/bundler/vendor/pub_grub/lib/pub_grub/basic_package_source.rb +189 -0
  202. data/lib/bundler/vendor/pub_grub/lib/pub_grub/failure_writer.rb +182 -0
  203. data/lib/bundler/vendor/pub_grub/lib/pub_grub/incompatibility.rb +150 -0
  204. data/lib/bundler/vendor/pub_grub/lib/pub_grub/package.rb +43 -0
  205. data/lib/bundler/vendor/pub_grub/lib/pub_grub/partial_solution.rb +121 -0
  206. data/lib/bundler/vendor/pub_grub/lib/pub_grub/rubygems.rb +45 -0
  207. data/lib/bundler/vendor/pub_grub/lib/pub_grub/solve_failure.rb +19 -0
  208. data/lib/bundler/vendor/pub_grub/lib/pub_grub/static_package_source.rb +60 -0
  209. data/lib/bundler/vendor/pub_grub/lib/pub_grub/term.rb +105 -0
  210. data/lib/bundler/vendor/pub_grub/lib/pub_grub/version.rb +3 -0
  211. data/lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb +129 -0
  212. data/lib/bundler/vendor/pub_grub/lib/pub_grub/version_range.rb +411 -0
  213. data/lib/bundler/vendor/pub_grub/lib/pub_grub/version_solver.rb +248 -0
  214. data/lib/bundler/vendor/pub_grub/lib/pub_grub/version_union.rb +178 -0
  215. data/lib/bundler/vendor/pub_grub/lib/pub_grub.rb +31 -0
  216. data/lib/bundler/vendor/thor/LICENSE.md +20 -0
  217. data/lib/bundler/vendor/thor/lib/thor/actions/file_manipulation.rb +5 -5
  218. data/lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb +1 -2
  219. data/lib/bundler/vendor/thor/lib/thor/actions.rb +6 -2
  220. data/lib/bundler/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb +6 -0
  221. data/lib/bundler/vendor/thor/lib/thor/error.rb +9 -4
  222. data/lib/bundler/vendor/thor/lib/thor/parser/options.rb +19 -1
  223. data/lib/bundler/vendor/thor/lib/thor/shell/basic.rb +23 -5
  224. data/lib/bundler/vendor/thor/lib/thor/shell.rb +1 -1
  225. data/lib/bundler/vendor/thor/lib/thor/util.rb +1 -1
  226. data/lib/bundler/vendor/thor/lib/thor/version.rb +1 -1
  227. data/lib/bundler/vendor/tsort/LICENSE.txt +22 -0
  228. data/lib/bundler/vendor/tsort/lib/tsort.rb +452 -0
  229. data/lib/bundler/vendor/uri/LICENSE.txt +22 -0
  230. data/lib/bundler/vendor/uri/lib/uri/common.rb +76 -91
  231. data/lib/bundler/vendor/uri/lib/uri/file.rb +7 -1
  232. data/lib/bundler/vendor/uri/lib/uri/ftp.rb +2 -2
  233. data/lib/bundler/vendor/uri/lib/uri/generic.rb +32 -13
  234. data/lib/bundler/vendor/uri/lib/uri/http.rb +40 -3
  235. data/lib/bundler/vendor/uri/lib/uri/https.rb +2 -2
  236. data/lib/bundler/vendor/uri/lib/uri/ldap.rb +2 -2
  237. data/lib/bundler/vendor/uri/lib/uri/ldaps.rb +2 -1
  238. data/lib/bundler/vendor/uri/lib/uri/mailto.rb +2 -3
  239. data/lib/bundler/vendor/uri/lib/uri/rfc2396_parser.rb +16 -23
  240. data/lib/bundler/vendor/uri/lib/uri/rfc3986_parser.rb +12 -18
  241. data/lib/bundler/vendor/uri/lib/uri/version.rb +1 -1
  242. data/lib/bundler/vendor/uri/lib/uri/ws.rb +83 -0
  243. data/lib/bundler/vendor/uri/lib/uri/wss.rb +23 -0
  244. data/lib/bundler/vendor/uri/lib/uri.rb +3 -3
  245. data/lib/bundler/vendored_persistent.rb +1 -33
  246. data/lib/bundler/{vendored_molinillo.rb → vendored_pub_grub.rb} +1 -1
  247. data/lib/bundler/{vendored_tmpdir.rb → vendored_tsort.rb} +1 -1
  248. data/lib/bundler/version.rb +5 -1
  249. data/lib/bundler/worker.rb +24 -11
  250. data/lib/bundler.rb +66 -110
  251. metadata +70 -41
  252. data/lib/bundler/dep_proxy.rb +0 -55
  253. data/lib/bundler/gemdeps.rb +0 -29
  254. data/lib/bundler/psyched_yaml.rb +0 -22
  255. data/lib/bundler/templates/gems.rb +0 -8
  256. data/lib/bundler/templates/newgem/ext/newgem/extconf.rb.tt +0 -5
  257. data/lib/bundler/templates/newgem/travis.yml.tt +0 -6
  258. data/lib/bundler/vendor/connection_pool/lib/connection_pool/monotonic_time.rb +0 -66
  259. data/lib/bundler/vendor/molinillo/lib/molinillo/delegates/resolution_state.rb +0 -57
  260. data/lib/bundler/vendor/molinillo/lib/molinillo/delegates/specification_provider.rb +0 -88
  261. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/action.rb +0 -36
  262. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/add_edge_no_circular.rb +0 -66
  263. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/add_vertex.rb +0 -62
  264. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/delete_edge.rb +0 -63
  265. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/detach_vertex_named.rb +0 -61
  266. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/log.rb +0 -126
  267. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/set_payload.rb +0 -46
  268. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/tag.rb +0 -36
  269. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb +0 -164
  270. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb +0 -255
  271. data/lib/bundler/vendor/molinillo/lib/molinillo/errors.rb +0 -143
  272. data/lib/bundler/vendor/molinillo/lib/molinillo/gem_metadata.rb +0 -6
  273. data/lib/bundler/vendor/molinillo/lib/molinillo/modules/specification_provider.rb +0 -112
  274. data/lib/bundler/vendor/molinillo/lib/molinillo/modules/ui.rb +0 -67
  275. data/lib/bundler/vendor/molinillo/lib/molinillo/resolution.rb +0 -839
  276. data/lib/bundler/vendor/molinillo/lib/molinillo/resolver.rb +0 -46
  277. data/lib/bundler/vendor/molinillo/lib/molinillo/state.rb +0 -58
  278. data/lib/bundler/vendor/molinillo/lib/molinillo.rb +0 -11
  279. data/lib/bundler/vendor/tmpdir/lib/tmpdir.rb +0 -154
  280. data/lib/bundler/version_ranges.rb +0 -122
data/lib/bundler/retry.rb CHANGED
@@ -49,7 +49,7 @@ module Bundler
49
49
  raise e
50
50
  end
51
51
  return true unless name
52
- Bundler.ui.info "" unless Bundler.ui.debug? # Add new line incase dots preceded this
52
+ Bundler.ui.info "" unless Bundler.ui.debug? # Add new line in case dots preceded this
53
53
  Bundler.ui.warn "Retrying #{name} due to error (#{current_run.next}/#{total_runs}): #{e.class} #{e.message}", Bundler.ui.debug?
54
54
  end
55
55
 
@@ -5,11 +5,17 @@ module Bundler
5
5
  def ruby(*ruby_version)
6
6
  options = ruby_version.last.is_a?(Hash) ? ruby_version.pop : {}
7
7
  ruby_version.flatten!
8
+
8
9
  raise GemfileError, "Please define :engine_version" if options[:engine] && options[:engine_version].nil?
9
10
  raise GemfileError, "Please define :engine" if options[:engine_version] && options[:engine].nil?
10
11
 
12
+ if options[:file]
13
+ raise GemfileError, "Cannot specify version when using the file option" if ruby_version.any?
14
+ ruby_version << Bundler.read_file(options[:file]).strip
15
+ end
16
+
11
17
  if options[:engine] == "ruby" && options[:engine_version] &&
12
- ruby_version != Array(options[:engine_version])
18
+ ruby_version != Array(options[:engine_version])
13
19
  raise GemfileEvalError, "ruby_version must match the :engine_version for MRI"
14
20
  end
15
21
  @ruby_version = RubyVersion.new(ruby_version, options[:patchlevel], options[:engine], options[:engine_version])
@@ -28,16 +28,16 @@ module Bundler
28
28
  end
29
29
 
30
30
  @gem_version = Gem::Requirement.create(@versions.first).requirements.first.last
31
- @input_engine = engine && engine.to_s
32
- @engine = engine && engine.to_s || "ruby"
31
+ @input_engine = engine&.to_s
32
+ @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,10 +117,25 @@ 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
87
134
 
135
+ def deleted_gem?
136
+ !default_gem? && !File.directory?(full_gem_path)
137
+ end
138
+
88
139
  private
89
140
 
90
141
  def dependencies_to_gemfile(dependencies, group = nil)
@@ -105,10 +156,18 @@ module Gem
105
156
  end
106
157
 
107
158
  class Dependency
108
- attr_accessor :source, :groups, :all_sources
159
+ include ::Bundler::ForcePlatform
160
+
161
+ attr_accessor :source, :groups
109
162
 
110
163
  alias_method :eql?, :==
111
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
+
112
171
  def encode_with(coder)
113
172
  to_yaml_properties.each do |ivar|
114
173
  coder[ivar.to_s.sub(/^@/, "")] = instance_variable_get(ivar)
@@ -116,7 +175,7 @@ module Gem
116
175
  end
117
176
 
118
177
  def to_yaml_properties
119
- instance_variables.reject {|p| ["@source", "@groups", "@all_sources"].include?(p.to_s) }
178
+ instance_variables.reject {|p| ["@source", "@groups"].include?(p.to_s) }
120
179
  end
121
180
 
122
181
  def to_lock
@@ -134,6 +193,8 @@ module Gem
134
193
  class Requirement
135
194
  module OrderIndependentComparison
136
195
  def ==(other)
196
+ return unless Gem::Requirement === other
197
+
137
198
  if _requirements_sorted? && other._requirements_sorted?
138
199
  super
139
200
  else
@@ -144,9 +205,9 @@ module Gem
144
205
  protected
145
206
 
146
207
  def _requirements_sorted?
147
- return @_are_requirements_sorted if defined?(@_are_requirements_sorted)
208
+ return @_requirements_sorted if defined?(@_requirements_sorted)
148
209
  strings = as_list
149
- @_are_requirements_sorted = strings == strings.sort
210
+ @_requirements_sorted = strings == strings.sort
150
211
  end
151
212
 
152
213
  def _with_sorted_requirements
@@ -174,20 +235,110 @@ module Gem
174
235
  end
175
236
  end
176
237
 
238
+ require "rubygems/platform"
239
+
177
240
  class Platform
178
- JAVA = Gem::Platform.new("java") unless defined?(JAVA)
179
- MSWIN = Gem::Platform.new("mswin32") unless defined?(MSWIN)
180
- MSWIN64 = Gem::Platform.new("mswin64") unless defined?(MSWIN64)
181
- MINGW = Gem::Platform.new("x86-mingw32") unless defined?(MINGW)
182
- 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?
183
283
 
184
- undef_method :hash if method_defined? :hash
185
- def hash
186
- @cpu.hash ^ @os.hash ^ @version.hash
284
+ without_gnu_nor_abi_modifiers
285
+ end
187
286
  end
188
287
 
189
- undef_method :eql? if method_defined? :eql?
190
- alias_method :eql?, :==
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
291
+ end
292
+
293
+ Platform.singleton_class.module_eval do
294
+ unless Platform.singleton_methods.include?(:match_spec?)
295
+ def match_spec?(spec)
296
+ match_gem?(spec.platform, spec.name)
297
+ end
298
+
299
+ def match_gem?(platform, gem_name)
300
+ match_platforms?(platform, Gem.platforms)
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])
307
+
308
+ private
309
+
310
+ remove_method :match_platforms? if match_platforms_defined
311
+
312
+ def match_platforms?(platform, platforms)
313
+ platforms.any? do |local_platform|
314
+ platform.nil? ||
315
+ 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)
339
+ end
340
+ end
341
+ end
191
342
  end
192
343
 
193
344
  require "rubygems/util"
@@ -198,17 +349,7 @@ module Gem
198
349
  end
199
350
 
200
351
  def glob_files_in_dir(glob, base_path)
201
- if RUBY_VERSION >= "2.5"
202
- Dir.glob(glob, :base => base_path).map! {|f| File.expand_path(f, base_path) }
203
- else
204
- Dir.glob(File.join(base_path.to_s.gsub(/[\[\]]/, '\\\\\\&'), glob)).map! {|f| File.expand_path(f) }
205
- end
352
+ Dir.glob(glob, :base => base_path).map! {|f| File.expand_path(f, base_path) }
206
353
  end
207
354
  end
208
355
  end
209
-
210
- module Gem
211
- class Specification
212
- include ::Bundler::MatchPlatform
213
- end
214
- 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,28 +66,55 @@ module Bundler
61
66
 
62
67
  def build_extensions
63
68
  extension_cache_path = options[:bundler_extension_cache_path]
64
- return super unless extension_cache_path && extension_dir = spec.extension_dir
69
+ extension_dir = spec.extension_dir
70
+ unless extension_cache_path && extension_dir
71
+ prepare_extension_build(extension_dir)
72
+ return super
73
+ end
65
74
 
66
- extension_dir = Pathname.new(extension_dir)
67
75
  build_complete = SharedHelpers.filesystem_access(extension_cache_path.join("gem.build_complete"), :read, &:file?)
68
76
  if build_complete && !options[:force]
69
- SharedHelpers.filesystem_access(extension_dir.parent, &:mkpath)
77
+ SharedHelpers.filesystem_access(File.dirname(extension_dir)) do |p|
78
+ FileUtils.mkpath p
79
+ end
70
80
  SharedHelpers.filesystem_access(extension_cache_path) do
71
- FileUtils.cp_r extension_cache_path, spec.extension_dir
81
+ FileUtils.cp_r extension_cache_path, extension_dir
72
82
  end
73
83
  else
84
+ prepare_extension_build(extension_dir)
74
85
  super
75
- if extension_dir.directory? # not made for gems without extensions
76
- SharedHelpers.filesystem_access(extension_cache_path.parent, &:mkpath)
77
- SharedHelpers.filesystem_access(extension_cache_path) do
78
- FileUtils.cp_r extension_dir, extension_cache_path
79
- 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
80
89
  end
81
90
  end
82
91
  end
83
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
+
84
101
  private
85
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 StandardError => e
113
+ raise unless File.exist?(dir)
114
+
115
+ raise DirectoryRemovalError.new(e, "Could not delete previous installation of `#{dir}`")
116
+ end
117
+
86
118
  def validate_bundler_checksum(checksum)
87
119
  return true if Bundler.settings[:disable_checksum_validation]
88
120
  return true unless checksum