bundler 2.1.4 → 2.2.18

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of bundler might be problematic. Click here for more details.

Files changed (227) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1790 -1430
  3. data/README.md +6 -8
  4. data/bundler.gemspec +5 -6
  5. data/exe/bundle +3 -0
  6. data/lib/bundler/build_metadata.rb +3 -11
  7. data/lib/bundler/cli/add.rb +1 -1
  8. data/lib/bundler/cli/binstubs.rb +6 -2
  9. data/lib/bundler/cli/cache.rb +2 -7
  10. data/lib/bundler/cli/clean.rb +1 -1
  11. data/lib/bundler/cli/common.rb +29 -2
  12. data/lib/bundler/cli/console.rb +1 -1
  13. data/lib/bundler/cli/doctor.rb +1 -1
  14. data/lib/bundler/cli/exec.rb +4 -4
  15. data/lib/bundler/cli/fund.rb +36 -0
  16. data/lib/bundler/cli/gem.rb +129 -28
  17. data/lib/bundler/cli/info.rb +15 -4
  18. data/lib/bundler/cli/init.rb +2 -2
  19. data/lib/bundler/cli/inject.rb +1 -1
  20. data/lib/bundler/cli/install.rb +13 -11
  21. data/lib/bundler/cli/issue.rb +2 -2
  22. data/lib/bundler/cli/list.rb +12 -10
  23. data/lib/bundler/cli/outdated.rb +94 -76
  24. data/lib/bundler/cli/plugin.rb +10 -0
  25. data/lib/bundler/cli/pristine.rb +5 -0
  26. data/lib/bundler/cli/show.rb +1 -1
  27. data/lib/bundler/cli/update.rb +3 -1
  28. data/lib/bundler/cli.rb +72 -56
  29. data/lib/bundler/compact_index_client/cache.rb +6 -14
  30. data/lib/bundler/compact_index_client/gem_parser.rb +28 -0
  31. data/lib/bundler/compact_index_client/updater.rb +13 -17
  32. data/lib/bundler/compact_index_client.rb +1 -1
  33. data/lib/bundler/current_ruby.rb +1 -0
  34. data/lib/bundler/definition.rb +117 -188
  35. data/lib/bundler/dep_proxy.rb +16 -9
  36. data/lib/bundler/dependency.rb +3 -10
  37. data/lib/bundler/dsl.rb +40 -33
  38. data/lib/bundler/endpoint_specification.rb +1 -1
  39. data/lib/bundler/env.rb +1 -1
  40. data/lib/bundler/environment_preserver.rb +26 -2
  41. data/lib/bundler/errors.rb +1 -0
  42. data/lib/bundler/feature_flag.rb +0 -6
  43. data/lib/bundler/fetcher/base.rb +1 -1
  44. data/lib/bundler/fetcher/compact_index.rb +1 -1
  45. data/lib/bundler/fetcher/downloader.rb +9 -5
  46. data/lib/bundler/fetcher/index.rb +3 -4
  47. data/lib/bundler/fetcher.rb +5 -4
  48. data/lib/bundler/friendly_errors.rb +22 -13
  49. data/lib/bundler/gem_helper.rb +51 -18
  50. data/lib/bundler/gem_helpers.rb +36 -25
  51. data/lib/bundler/gem_version_promoter.rb +4 -4
  52. data/lib/bundler/graph.rb +1 -1
  53. data/lib/bundler/index.rb +13 -9
  54. data/lib/bundler/injector.rb +23 -5
  55. data/lib/bundler/inline.rb +3 -2
  56. data/lib/bundler/installer/gem_installer.rb +3 -3
  57. data/lib/bundler/installer/parallel_installer.rb +46 -25
  58. data/lib/bundler/installer/standalone.rb +17 -2
  59. data/lib/bundler/installer.rb +37 -49
  60. data/lib/bundler/lazy_specification.rb +45 -25
  61. data/lib/bundler/lockfile_generator.rb +1 -1
  62. data/lib/bundler/lockfile_parser.rb +4 -14
  63. data/lib/bundler/man/.document +1 -0
  64. data/{man → lib/bundler/man}/bundle-add.1 +1 -1
  65. data/{man/bundle-add.ronn → lib/bundler/man/bundle-add.1.ronn} +0 -0
  66. data/{man → lib/bundler/man}/bundle-binstubs.1 +5 -3
  67. data/{man/bundle-binstubs.ronn → lib/bundler/man/bundle-binstubs.1.ronn} +2 -4
  68. data/{man → lib/bundler/man}/bundle-cache.1 +1 -1
  69. data/{man/bundle-cache.ronn → lib/bundler/man/bundle-cache.1.ronn} +0 -0
  70. data/{man → lib/bundler/man}/bundle-check.1 +1 -1
  71. data/{man/bundle-check.ronn → lib/bundler/man/bundle-check.1.ronn} +0 -0
  72. data/{man → lib/bundler/man}/bundle-clean.1 +1 -1
  73. data/{man/bundle-clean.ronn → lib/bundler/man/bundle-clean.1.ronn} +0 -0
  74. data/{man → lib/bundler/man}/bundle-config.1 +40 -38
  75. data/{man/bundle-config.ronn → lib/bundler/man/bundle-config.1.ronn} +50 -50
  76. data/{man → lib/bundler/man}/bundle-doctor.1 +1 -1
  77. data/{man/bundle-doctor.ronn → lib/bundler/man/bundle-doctor.1.ronn} +0 -0
  78. data/{man → lib/bundler/man}/bundle-exec.1 +1 -1
  79. data/{man/bundle-exec.ronn → lib/bundler/man/bundle-exec.1.ronn} +0 -0
  80. data/{man → lib/bundler/man}/bundle-gem.1 +25 -3
  81. data/{man/bundle-gem.ronn → lib/bundler/man/bundle-gem.1.ronn} +30 -7
  82. data/{man → lib/bundler/man}/bundle-info.1 +1 -1
  83. data/{man/bundle-info.ronn → lib/bundler/man/bundle-info.1.ronn} +0 -0
  84. data/{man → lib/bundler/man}/bundle-init.1 +1 -1
  85. data/{man/bundle-init.ronn → lib/bundler/man/bundle-init.1.ronn} +0 -0
  86. data/{man → lib/bundler/man}/bundle-inject.1 +1 -1
  87. data/{man/bundle-inject.ronn → lib/bundler/man/bundle-inject.1.ronn} +0 -0
  88. data/{man → lib/bundler/man}/bundle-install.1 +30 -3
  89. data/{man/bundle-install.ronn → lib/bundler/man/bundle-install.1.ronn} +25 -3
  90. data/{man → lib/bundler/man}/bundle-list.1 +7 -7
  91. data/{man/bundle-list.ronn → lib/bundler/man/bundle-list.1.ronn} +6 -6
  92. data/{man → lib/bundler/man}/bundle-lock.1 +1 -1
  93. data/{man/bundle-lock.ronn → lib/bundler/man/bundle-lock.1.ronn} +0 -0
  94. data/{man → lib/bundler/man}/bundle-open.1 +1 -1
  95. data/{man/bundle-open.ronn → lib/bundler/man/bundle-open.1.ronn} +0 -0
  96. data/{man → lib/bundler/man}/bundle-outdated.1 +1 -1
  97. data/{man/bundle-outdated.ronn → lib/bundler/man/bundle-outdated.1.ronn} +0 -0
  98. data/{man → lib/bundler/man}/bundle-platform.1 +1 -1
  99. data/{man/bundle-platform.ronn → lib/bundler/man/bundle-platform.1.ronn} +0 -0
  100. data/{man → lib/bundler/man}/bundle-pristine.1 +1 -1
  101. data/{man/bundle-pristine.ronn → lib/bundler/man/bundle-pristine.1.ronn} +0 -0
  102. data/{man → lib/bundler/man}/bundle-remove.1 +1 -1
  103. data/{man/bundle-remove.ronn → lib/bundler/man/bundle-remove.1.ronn} +0 -0
  104. data/{man → lib/bundler/man}/bundle-show.1 +1 -1
  105. data/{man/bundle-show.ronn → lib/bundler/man/bundle-show.1.ronn} +0 -0
  106. data/{man → lib/bundler/man}/bundle-update.1 +1 -1
  107. data/{man/bundle-update.ronn → lib/bundler/man/bundle-update.1.ronn} +0 -0
  108. data/{man → lib/bundler/man}/bundle-viz.1 +1 -1
  109. data/{man/bundle-viz.ronn → lib/bundler/man/bundle-viz.1.ronn} +0 -0
  110. data/{man → lib/bundler/man}/bundle.1 +1 -1
  111. data/{man/bundle.ronn → lib/bundler/man/bundle.1.ronn} +0 -0
  112. data/{man → lib/bundler/man}/gemfile.5 +4 -4
  113. data/{man → lib/bundler/man}/gemfile.5.ronn +4 -4
  114. data/{man → lib/bundler/man}/index.txt +0 -0
  115. data/lib/bundler/mirror.rb +2 -2
  116. data/lib/bundler/plugin/api/source.rb +22 -1
  117. data/lib/bundler/plugin/dsl.rb +1 -1
  118. data/lib/bundler/plugin/index.rb +10 -1
  119. data/lib/bundler/plugin/installer/rubygems.rb +1 -1
  120. data/lib/bundler/plugin/installer.rb +9 -11
  121. data/lib/bundler/plugin/source_list.rb +5 -1
  122. data/lib/bundler/plugin.rb +33 -7
  123. data/lib/bundler/psyched_yaml.rb +0 -15
  124. data/lib/bundler/remote_specification.rb +5 -2
  125. data/lib/bundler/resolver/spec_group.rb +56 -53
  126. data/lib/bundler/resolver.rb +88 -115
  127. data/lib/bundler/retry.rb +2 -2
  128. data/lib/bundler/ruby_version.rb +1 -1
  129. data/lib/bundler/rubygems_ext.rb +71 -11
  130. data/lib/bundler/rubygems_gem_installer.rb +50 -9
  131. data/lib/bundler/rubygems_integration.rb +25 -60
  132. data/lib/bundler/runtime.rb +4 -14
  133. data/lib/bundler/settings.rb +107 -55
  134. data/lib/bundler/shared_helpers.rb +3 -3
  135. data/lib/bundler/similarity_detector.rb +1 -1
  136. data/lib/bundler/source/git/git_proxy.rb +82 -80
  137. data/lib/bundler/source/git.rb +24 -22
  138. data/lib/bundler/source/metadata.rb +0 -4
  139. data/lib/bundler/source/path/installer.rb +10 -10
  140. data/lib/bundler/source/path.rb +10 -4
  141. data/lib/bundler/source/rubygems/remote.rb +1 -1
  142. data/lib/bundler/source/rubygems.rb +60 -28
  143. data/lib/bundler/source/rubygems_aggregate.rb +64 -0
  144. data/lib/bundler/source.rb +16 -1
  145. data/lib/bundler/source_list.rb +52 -28
  146. data/lib/bundler/source_map.rb +58 -0
  147. data/lib/bundler/spec_set.rb +29 -17
  148. data/lib/bundler/stub_specification.rb +25 -7
  149. data/lib/bundler/templates/Gemfile +1 -1
  150. data/lib/bundler/templates/gems.rb +1 -1
  151. data/lib/bundler/templates/newgem/CHANGELOG.md.tt +5 -0
  152. data/lib/bundler/templates/newgem/CODE_OF_CONDUCT.md.tt +57 -47
  153. data/lib/bundler/templates/newgem/Gemfile.tt +9 -1
  154. data/lib/bundler/templates/newgem/README.md.tt +6 -5
  155. data/lib/bundler/templates/newgem/Rakefile.tt +19 -5
  156. data/lib/bundler/templates/newgem/bin/console.tt +1 -0
  157. data/lib/bundler/templates/newgem/circleci/config.yml.tt +13 -0
  158. data/lib/bundler/templates/newgem/ext/newgem/extconf.rb.tt +2 -0
  159. data/lib/bundler/templates/newgem/github/workflows/main.yml.tt +16 -0
  160. data/lib/bundler/templates/newgem/gitlab-ci.yml.tt +9 -0
  161. data/lib/bundler/templates/newgem/lib/newgem/version.rb.tt +2 -0
  162. data/lib/bundler/templates/newgem/lib/newgem.rb.tt +4 -2
  163. data/lib/bundler/templates/newgem/newgem.gemspec.tt +15 -7
  164. data/lib/bundler/templates/newgem/rubocop.yml.tt +13 -0
  165. data/lib/bundler/templates/newgem/spec/newgem_spec.rb.tt +2 -0
  166. data/lib/bundler/templates/newgem/spec/spec_helper.rb.tt +2 -1
  167. data/lib/bundler/templates/newgem/test/{newgem_test.rb.tt → minitest/newgem_test.rb.tt} +2 -0
  168. data/lib/bundler/templates/newgem/test/{test_helper.rb.tt → minitest/test_helper.rb.tt} +2 -0
  169. data/lib/bundler/templates/newgem/test/test-unit/newgem_test.rb.tt +15 -0
  170. data/lib/bundler/templates/newgem/test/test-unit/test_helper.rb.tt +6 -0
  171. data/lib/bundler/ui/shell.rb +5 -5
  172. data/lib/bundler/uri_credentials_filter.rb +3 -1
  173. data/lib/bundler/vendor/molinillo/lib/molinillo/delegates/specification_provider.rb +7 -0
  174. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/tag.rb +2 -2
  175. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb +11 -5
  176. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb +34 -2
  177. data/lib/bundler/vendor/molinillo/lib/molinillo/errors.rb +3 -3
  178. data/lib/bundler/vendor/molinillo/lib/molinillo/gem_metadata.rb +1 -1
  179. data/lib/bundler/vendor/molinillo/lib/molinillo/modules/specification_provider.rb +12 -1
  180. data/lib/bundler/vendor/molinillo/lib/molinillo/resolution.rb +49 -47
  181. data/lib/bundler/vendor/molinillo/lib/molinillo.rb +0 -1
  182. data/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent.rb +82 -189
  183. data/lib/bundler/vendor/thor/lib/thor/actions/create_link.rb +2 -1
  184. data/lib/bundler/vendor/thor/lib/thor/actions/file_manipulation.rb +4 -2
  185. data/lib/bundler/vendor/thor/lib/thor/actions.rb +1 -1
  186. data/lib/bundler/vendor/thor/lib/thor/base.rb +9 -0
  187. data/lib/bundler/vendor/thor/lib/thor/error.rb +1 -1
  188. data/lib/bundler/vendor/thor/lib/thor/parser/arguments.rb +5 -1
  189. data/lib/bundler/vendor/thor/lib/thor/parser/options.rb +9 -8
  190. data/lib/bundler/vendor/thor/lib/thor/shell/basic.rb +5 -2
  191. data/lib/bundler/vendor/thor/lib/thor/shell/color.rb +5 -1
  192. data/lib/bundler/vendor/thor/lib/thor/version.rb +1 -1
  193. data/lib/bundler/vendor/thor/lib/thor.rb +5 -13
  194. data/lib/bundler/vendor/tmpdir/lib/tmpdir.rb +154 -0
  195. data/lib/bundler/vendored_persistent.rb +0 -7
  196. data/lib/bundler/vendored_tmpdir.rb +4 -0
  197. data/lib/bundler/version.rb +1 -1
  198. data/lib/bundler/worker.rb +1 -1
  199. data/lib/bundler/yaml_serializer.rb +1 -1
  200. data/lib/bundler.rb +34 -9
  201. metadata +77 -86
  202. data/lib/bundler/vendor/molinillo/lib/molinillo/compatibility.rb +0 -26
  203. data/man/bundle-add.1.txt +0 -58
  204. data/man/bundle-binstubs.1.txt +0 -48
  205. data/man/bundle-cache.1.txt +0 -78
  206. data/man/bundle-check.1.txt +0 -33
  207. data/man/bundle-clean.1.txt +0 -26
  208. data/man/bundle-config.1.txt +0 -528
  209. data/man/bundle-doctor.1.txt +0 -44
  210. data/man/bundle-exec.1.txt +0 -178
  211. data/man/bundle-gem.1.txt +0 -91
  212. data/man/bundle-info.1.txt +0 -21
  213. data/man/bundle-init.1.txt +0 -34
  214. data/man/bundle-inject.1.txt +0 -32
  215. data/man/bundle-install.1.txt +0 -401
  216. data/man/bundle-list.1.txt +0 -43
  217. data/man/bundle-lock.1.txt +0 -93
  218. data/man/bundle-open.1.txt +0 -29
  219. data/man/bundle-outdated.1.txt +0 -131
  220. data/man/bundle-platform.1.txt +0 -57
  221. data/man/bundle-pristine.1.txt +0 -44
  222. data/man/bundle-remove.1.txt +0 -34
  223. data/man/bundle-show.1.txt +0 -27
  224. data/man/bundle-update.1.txt +0 -390
  225. data/man/bundle-viz.1.txt +0 -39
  226. data/man/bundle.1.txt +0 -116
  227. data/man/gemfile.5.txt +0 -649
@@ -4,23 +4,64 @@ require "rubygems/installer"
4
4
 
5
5
  module Bundler
6
6
  class RubyGemsGemInstaller < Gem::Installer
7
- unless respond_to?(:at)
8
- def self.at(*args)
9
- new(*args)
10
- end
11
- end
12
-
13
7
  def check_executable_overwrite(filename)
14
8
  # Bundler needs to install gems regardless of binstub overwriting
15
9
  end
16
10
 
11
+ def install
12
+ pre_install_checks
13
+
14
+ run_pre_install_hooks
15
+
16
+ spec.loaded_from = spec_file
17
+
18
+ # Completely remove any previous gem files
19
+ FileUtils.rm_rf gem_dir
20
+ FileUtils.rm_rf spec.extension_dir
21
+
22
+ FileUtils.mkdir_p gem_dir, :mode => 0o755
23
+
24
+ extract_files
25
+
26
+ build_extensions
27
+ write_build_info_file
28
+ run_post_build_hooks
29
+
30
+ generate_bin
31
+ generate_plugins
32
+
33
+ write_spec
34
+ write_cache_file
35
+
36
+ say spec.post_install_message unless spec.post_install_message.nil?
37
+
38
+ run_post_install_hooks
39
+
40
+ spec
41
+ end
42
+
43
+ def generate_plugins
44
+ return unless Gem::Installer.instance_methods(false).include?(:generate_plugins)
45
+
46
+ latest = Gem::Specification.stubs_for(spec.name).first
47
+ return if latest && latest.version > spec.version
48
+
49
+ ensure_writable_dir @plugins_dir
50
+
51
+ if spec.plugins.empty?
52
+ remove_plugins_for(spec, @plugins_dir)
53
+ else
54
+ regenerate_plugins_for(spec, @plugins_dir)
55
+ end
56
+ end
57
+
17
58
  def pre_install_checks
18
59
  super && validate_bundler_checksum(options[:bundler_expected_checksum])
19
60
  end
20
61
 
21
62
  def build_extensions
22
63
  extension_cache_path = options[:bundler_extension_cache_path]
23
- return super unless extension_cache_path && extension_dir = Bundler.rubygems.spec_extension_dir(spec)
64
+ return super unless extension_cache_path && extension_dir = spec.extension_dir
24
65
 
25
66
  extension_dir = Pathname.new(extension_dir)
26
67
  build_complete = SharedHelpers.filesystem_access(extension_cache_path.join("gem.build_complete"), :read, &:file?)
@@ -40,7 +81,7 @@ module Bundler
40
81
  end
41
82
  end
42
83
 
43
- private
84
+ private
44
85
 
45
86
  def validate_bundler_checksum(checksum)
46
87
  return true if Bundler.settings[:disable_checksum_validation]
@@ -66,7 +107,7 @@ module Bundler
66
107
 
67
108
  If you wish to continue installing the downloaded gem, and are certain it does not pose a \
68
109
  security issue despite the mismatching checksum, do the following:
69
- 1. run `bundle config set disable_checksum_validation true` to turn off checksum verification
110
+ 1. run `bundle config set --local disable_checksum_validation true` to turn off checksum verification
70
111
  2. run `bundle install`
71
112
 
72
113
  (More info: The expected SHA256 checksum was #{checksum.inspect}, but the \
@@ -102,11 +102,6 @@ module Bundler
102
102
  end.flatten(1)
103
103
  end
104
104
 
105
- def spec_extension_dir(spec)
106
- return unless spec.respond_to?(:extension_dir)
107
- spec.extension_dir
108
- end
109
-
110
105
  def stub_set_spec(stub, spec)
111
106
  stub.instance_variable_set(:@spec, spec)
112
107
  end
@@ -115,11 +110,6 @@ module Bundler
115
110
  obj.to_s
116
111
  end
117
112
 
118
- def platforms
119
- return [Gem::Platform::RUBY] if Bundler.settings[:force_ruby_platform]
120
- Gem.platforms
121
- end
122
-
123
113
  def configuration
124
114
  require_relative "psyched_yaml"
125
115
  Gem.configuration
@@ -141,14 +131,10 @@ module Bundler
141
131
  end
142
132
 
143
133
  def inflate(obj)
144
- require "rubygems/util"
145
-
146
134
  Gem::Util.inflate(obj)
147
135
  end
148
136
 
149
137
  def correct_for_windows_path(path)
150
- require "rubygems/util"
151
-
152
138
  if Gem::Util.respond_to?(:correct_for_windows_path)
153
139
  Gem::Util.correct_for_windows_path(path)
154
140
  elsif path[0].chr == "/" && path[1].chr =~ /[a-z]/i && path[2].chr == ":"
@@ -223,11 +209,6 @@ module Bundler
223
209
  Gem.bin_path(gem, bin, ver)
224
210
  end
225
211
 
226
- def preserve_paths
227
- # this is a no-op outside of RubyGems 1.8
228
- yield
229
- end
230
-
231
212
  def loaded_gem_paths
232
213
  loaded_gem_paths = Gem.loaded_specs.map {|_, s| s.full_require_paths }
233
214
  loaded_gem_paths.flatten
@@ -241,6 +222,10 @@ module Bundler
241
222
  Gem.load_plugin_files(files) if Gem.respond_to?(:load_plugin_files)
242
223
  end
243
224
 
225
+ def load_env_plugins
226
+ Gem.load_env_plugins if Gem.respond_to?(:load_env_plugins)
227
+ end
228
+
244
229
  def ui=(obj)
245
230
  Gem::DefaultUserInteraction.ui = obj
246
231
  end
@@ -265,8 +250,6 @@ module Bundler
265
250
  require "rubygems/security"
266
251
  require_relative "psyched_yaml"
267
252
  gem_from_path(path, security_policies[policy]).spec
268
- rescue Gem::Package::FormatError
269
- raise GemspecError, "Could not read gem at #{path}. It may be corrupted."
270
253
  rescue Exception, Gem::Exception, Gem::Security::Exception => e # rubocop:disable Lint/RescueException
271
254
  if e.is_a?(Gem::Security::Exception) ||
272
255
  e.message =~ /unknown trust policy|unsigned gem/i ||
@@ -329,8 +312,13 @@ module Bundler
329
312
  end
330
313
 
331
314
  message = if spec.nil?
315
+ target_file = begin
316
+ Bundler.default_gemfile.basename
317
+ rescue GemfileNotFound
318
+ "inline Gemfile"
319
+ end
332
320
  "#{dep.name} is not part of the bundle." \
333
- " Add it to your #{Bundler.default_gemfile.basename}."
321
+ " Add it to your #{target_file}."
334
322
  else
335
323
  "can't activate #{dep}, already activated #{spec.full_name}. " \
336
324
  "Make sure all dependencies are added to Gemfile."
@@ -346,7 +334,7 @@ module Bundler
346
334
  raise e
347
335
  end
348
336
 
349
- # backwards compatibility shim, see https://github.com/bundler/bundler/issues/5102
337
+ # backwards compatibility shim, see https://github.com/rubygems/bundler/issues/5102
350
338
  kernel_class.send(:public, :gem) if Bundler.feature_flag.setup_makes_kernel_gem_public?
351
339
  end
352
340
  end
@@ -422,6 +410,17 @@ module Bundler
422
410
  # Replace or hook into RubyGems to provide a bundlerized view
423
411
  # of the world.
424
412
  def replace_entrypoints(specs)
413
+ specs_by_name = add_default_gems_to(specs)
414
+
415
+ replace_gem(specs, specs_by_name)
416
+ stub_rubygems(specs)
417
+ replace_bin_path(specs_by_name)
418
+
419
+ Gem.clear_paths
420
+ end
421
+
422
+ # Add default gems not already present in specs, and return them as a hash.
423
+ def add_default_gems_to(specs)
425
424
  specs_by_name = specs.reduce({}) do |h, s|
426
425
  h[s.name] = s
427
426
  h
@@ -436,40 +435,7 @@ module Bundler
436
435
  specs_by_name[default_spec_name] = default_spec
437
436
  end
438
437
 
439
- replace_gem(specs, specs_by_name)
440
- stub_rubygems(specs)
441
- replace_bin_path(specs_by_name)
442
-
443
- Gem.clear_paths
444
- end
445
-
446
- # This backports base_dir which replaces installation path
447
- # RubyGems 1.8+
448
- def backport_base_dir
449
- redefine_method(Gem::Specification, :base_dir) do
450
- return Gem.dir unless loaded_from
451
- File.dirname File.dirname loaded_from
452
- end
453
- end
454
-
455
- def backport_cache_file
456
- redefine_method(Gem::Specification, :cache_dir) do
457
- @cache_dir ||= File.join base_dir, "cache"
458
- end
459
-
460
- redefine_method(Gem::Specification, :cache_file) do
461
- @cache_file ||= File.join cache_dir, "#{full_name}.gem"
462
- end
463
- end
464
-
465
- def backport_spec_file
466
- redefine_method(Gem::Specification, :spec_dir) do
467
- @spec_dir ||= File.join base_dir, "specifications"
468
- end
469
-
470
- redefine_method(Gem::Specification, :spec_file) do
471
- @spec_file ||= File.join spec_dir, "#{full_name}.gemspec"
472
- end
438
+ specs_by_name
473
439
  end
474
440
 
475
441
  def undo_replacements
@@ -594,7 +560,6 @@ module Bundler
594
560
  end
595
561
 
596
562
  def all_specs
597
- require_relative "remote_specification"
598
563
  Gem::Specification.stubs.map do |stub|
599
564
  StubSpecification.from_stub(stub)
600
565
  end
@@ -602,10 +567,10 @@ module Bundler
602
567
 
603
568
  def backport_ext_builder_monitor
604
569
  # So we can avoid requiring "rubygems/ext" in its entirety
605
- Gem.module_eval <<-RB, __FILE__, __LINE__ + 1
570
+ Gem.module_eval <<-RUBY, __FILE__, __LINE__ + 1
606
571
  module Ext
607
572
  end
608
- RB
573
+ RUBY
609
574
 
610
575
  require "rubygems/ext/builder"
611
576
 
@@ -43,14 +43,6 @@ module Bundler
43
43
  self
44
44
  end
45
45
 
46
- REQUIRE_ERRORS = [
47
- /^no such file to load -- (.+)$/i,
48
- /^Missing \w+ (?:file\s*)?([^\s]+.rb)$/i,
49
- /^Missing API definition file in (.+)$/i,
50
- /^cannot load such file -- (.+)$/i,
51
- /^dlopen\([^)]*\): Library not loaded: (.+)$/i,
52
- ].freeze
53
-
54
46
  def require(*groups)
55
47
  groups.map!(&:to_sym)
56
48
  groups = [:default] if groups.empty?
@@ -79,16 +71,14 @@ module Bundler
79
71
  end
80
72
  end
81
73
  rescue LoadError => e
82
- REQUIRE_ERRORS.find {|r| r =~ e.message }
83
- raise if dep.autorequire || $1 != required_file
74
+ raise if dep.autorequire || e.path != required_file
84
75
 
85
76
  if dep.autorequire.nil? && dep.name.include?("-")
86
77
  begin
87
78
  namespaced_file = dep.name.tr("-", "/")
88
79
  Kernel.require namespaced_file
89
80
  rescue LoadError => e
90
- REQUIRE_ERRORS.find {|r| r =~ e.message }
91
- raise if $1 != namespaced_file
81
+ raise if e.path != namespaced_file
92
82
  end
93
83
  end
94
84
  end
@@ -165,7 +155,7 @@ module Bundler
165
155
  spec_cache_paths = []
166
156
  spec_gemspec_paths = []
167
157
  spec_extension_paths = []
168
- specs.each do |spec|
158
+ Bundler.rubygems.add_default_gems_to(specs).values.each do |spec|
169
159
  spec_gem_paths << spec.full_gem_path
170
160
  # need to check here in case gems are nested like for the rails git repo
171
161
  md = %r{(.+bundler/gems/.+-[a-f0-9]{7,12})}.match(spec.full_gem_path)
@@ -213,7 +203,7 @@ module Bundler
213
203
  output
214
204
  end
215
205
 
216
- private
206
+ private
217
207
 
218
208
  def prune_gem_cache(resolve, cache_path)
219
209
  cached = Dir["#{cache_path}/*.gem"]
@@ -7,35 +7,35 @@ module Bundler
7
7
  autoload :Validator, File.expand_path("settings/validator", __dir__)
8
8
 
9
9
  BOOL_KEYS = %w[
10
- allow_bundler_dependency_conflicts
11
10
  allow_deployment_source_credential_changes
12
11
  allow_offline_install
13
12
  auto_clean_without_path
14
13
  auto_install
15
- auto_config_jobs
16
14
  cache_all
17
15
  cache_all_platforms
16
+ clean
18
17
  default_install_uses_path
19
18
  deployment
20
19
  deployment_means_frozen
21
20
  disable_checksum_validation
22
21
  disable_exec_load
23
22
  disable_local_branch_check
24
- disable_multisource
25
- disable_platform_warnings
23
+ disable_local_revision_check
26
24
  disable_shared_gems
27
25
  disable_version_check
28
26
  force_ruby_platform
29
27
  forget_cli_options
30
28
  frozen
29
+ gem.changelog
31
30
  gem.coc
32
31
  gem.mit
32
+ git.allow_insecure
33
33
  global_gem_cache
34
34
  ignore_messages
35
35
  init_gems_rb
36
+ inline
36
37
  no_install
37
38
  no_prune
38
- only_update_to_newer_versions
39
39
  path_relative_to_cwd
40
40
  path.system
41
41
  plugins
@@ -44,8 +44,6 @@ module Bundler
44
44
  setup_makes_kernel_gem_public
45
45
  silence_deprecations
46
46
  silence_root_warning
47
- skip_default_git_sources
48
- specific_platform
49
47
  suppress_install_using_messages
50
48
  unlock_source_unlocks_spec
51
49
  update_requires_all_flag
@@ -65,31 +63,42 @@ module Bundler
65
63
  without
66
64
  ].freeze
67
65
 
66
+ STRING_KEYS = %w[
67
+ bin
68
+ cache_path
69
+ console
70
+ gem.ci
71
+ gem.github_username
72
+ gem.linter
73
+ gem.rubocop
74
+ gem.test
75
+ gemfile
76
+ path
77
+ shebang
78
+ system_bindir
79
+ trust-policy
80
+ ].freeze
81
+
68
82
  DEFAULT_CONFIG = {
69
- :silence_deprecations => false,
70
- :disable_version_check => true,
71
- :prefer_patch => false,
72
- :redirect => 5,
73
- :retry => 3,
74
- :timeout => 10,
83
+ "BUNDLE_SILENCE_DEPRECATIONS" => false,
84
+ "BUNDLE_DISABLE_VERSION_CHECK" => true,
85
+ "BUNDLE_PREFER_PATCH" => false,
86
+ "BUNDLE_REDIRECT" => 5,
87
+ "BUNDLE_RETRY" => 3,
88
+ "BUNDLE_TIMEOUT" => 10,
75
89
  }.freeze
76
90
 
77
91
  def initialize(root = nil)
78
92
  @root = root
79
93
  @local_config = load_config(local_config_file)
94
+ @env_config = ENV.to_h.select {|key, _value| key =~ /\ABUNDLE_.+/ }
80
95
  @global_config = load_config(global_config_file)
81
96
  @temporary = {}
82
97
  end
83
98
 
84
99
  def [](name)
85
100
  key = key_for(name)
86
- value = @temporary.fetch(key) do
87
- @local_config.fetch(key) do
88
- ENV.fetch(key) do
89
- @global_config.fetch(key) do
90
- DEFAULT_CONFIG.fetch(name) do
91
- nil
92
- end end end end end
101
+ value = configs.values.map {|config| config[key] }.compact.first
93
102
 
94
103
  converted_value(value, name)
95
104
  end
@@ -132,13 +141,11 @@ module Bundler
132
141
  end
133
142
 
134
143
  def all
135
- env_keys = ENV.keys.grep(/\ABUNDLE_.+/)
136
-
137
- keys = @temporary.keys | @global_config.keys | @local_config.keys | env_keys
144
+ keys = @temporary.keys | @global_config.keys | @local_config.keys | @env_config.keys
138
145
 
139
146
  keys.map do |key|
140
- key.sub(/^BUNDLE_/, "").gsub(/__/, ".").downcase
141
- end
147
+ key.sub(/^BUNDLE_/, "").gsub(/___/, "-").gsub(/__/, ".").downcase
148
+ end.sort
142
149
  end
143
150
 
144
151
  def local_overrides
@@ -171,13 +178,11 @@ module Bundler
171
178
 
172
179
  def locations(key)
173
180
  key = key_for(key)
174
- locations = {}
175
- locations[:temporary] = @temporary[key] if @temporary.key?(key)
176
- locations[:local] = @local_config[key] if @local_config.key?(key)
177
- locations[:env] = ENV[key] if ENV[key]
178
- locations[:global] = @global_config[key] if @global_config.key?(key)
179
- locations[:default] = DEFAULT_CONFIG[key] if DEFAULT_CONFIG.key?(key)
180
- locations
181
+ configs.keys.inject({}) do |partial_locations, level|
182
+ value_on_level = configs[level][key]
183
+ partial_locations[level] = value_on_level unless value_on_level.nil?
184
+ partial_locations
185
+ end
181
186
  end
182
187
 
183
188
  def pretty_values_for(exposed_key)
@@ -185,20 +190,20 @@ module Bundler
185
190
 
186
191
  locations = []
187
192
 
188
- if @temporary.key?(key)
189
- locations << "Set for the current command: #{converted_value(@temporary[key], exposed_key).inspect}"
193
+ if value = @temporary[key]
194
+ locations << "Set for the current command: #{printable_value(value, exposed_key).inspect}"
190
195
  end
191
196
 
192
- if @local_config.key?(key)
193
- locations << "Set for your local app (#{local_config_file}): #{converted_value(@local_config[key], exposed_key).inspect}"
197
+ if value = @local_config[key]
198
+ locations << "Set for your local app (#{local_config_file}): #{printable_value(value, exposed_key).inspect}"
194
199
  end
195
200
 
196
- if value = ENV[key]
197
- locations << "Set via #{key}: #{converted_value(value, exposed_key).inspect}"
201
+ if value = @env_config[key]
202
+ locations << "Set via #{key}: #{printable_value(value, exposed_key).inspect}"
198
203
  end
199
204
 
200
- if @global_config.key?(key)
201
- locations << "Set for the current user (#{global_config_file}): #{converted_value(@global_config[key], exposed_key).inspect}"
205
+ if value = @global_config[key]
206
+ locations << "Set for the current user (#{global_config_file}): #{printable_value(value, exposed_key).inspect}"
202
207
  end
203
208
 
204
209
  return ["You have not configured a value for `#{exposed_key}`"] if locations.empty?
@@ -207,17 +212,19 @@ module Bundler
207
212
 
208
213
  # for legacy reasons, in Bundler 2, we do not respect :disable_shared_gems
209
214
  def path
210
- key = key_for(:path)
211
- path = ENV[key] || @global_config[key]
212
- if path && !@temporary.key?(key) && !@local_config.key?(key)
213
- return Path.new(path, false, false)
215
+ configs.each do |_level, settings|
216
+ path = value_for("path", settings)
217
+ path_system = value_for("path.system", settings)
218
+ disabled_shared_gems = value_for("disable_shared_gems", settings)
219
+ next if path.nil? && path_system.nil? && disabled_shared_gems.nil?
220
+ system_path = path_system || (disabled_shared_gems == false)
221
+ return Path.new(path, system_path)
214
222
  end
215
223
 
216
- system_path = self["path.system"] || (self[:disable_shared_gems] == false)
217
- Path.new(self[:path], system_path, Bundler.feature_flag.default_install_uses_path?)
224
+ Path.new(nil, false)
218
225
  end
219
226
 
220
- Path = Struct.new(:explicit_path, :system_path, :default_install_uses_path) do
227
+ Path = Struct.new(:explicit_path, :system_path) do
221
228
  def path
222
229
  path = base_path
223
230
  path = File.join(path, Bundler.ruby_scope) unless use_system_gems?
@@ -227,7 +234,7 @@ module Bundler
227
234
  def use_system_gems?
228
235
  return true if system_path
229
236
  return false if explicit_path
230
- !default_install_uses_path
237
+ !Bundler.feature_flag.default_install_uses_path?
231
238
  end
232
239
 
233
240
  def base_path
@@ -280,20 +287,32 @@ module Bundler
280
287
 
281
288
  def validate!
282
289
  all.each do |raw_key|
283
- [@local_config, ENV, @global_config].each do |settings|
284
- value = converted_value(settings[key_for(raw_key)], raw_key)
285
- Validator.validate!(raw_key, value, settings.to_hash.dup)
290
+ [@local_config, @env_config, @global_config].each do |settings|
291
+ value = value_for(raw_key, settings)
292
+ Validator.validate!(raw_key, value, settings.dup)
286
293
  end
287
294
  end
288
295
  end
289
296
 
290
297
  def key_for(key)
291
- key = Settings.normalize_uri(key).to_s if key.is_a?(String) && /https?:/ =~ key
292
- key = key.to_s.gsub(".", "__").upcase
293
- "BUNDLE_#{key}"
298
+ self.class.key_for(key)
294
299
  end
295
300
 
296
- private
301
+ private
302
+
303
+ def configs
304
+ {
305
+ :temporary => @temporary,
306
+ :local => @local_config,
307
+ :env => @env_config,
308
+ :global => @global_config,
309
+ :default => DEFAULT_CONFIG,
310
+ }
311
+ end
312
+
313
+ def value_for(name, config)
314
+ converted_value(config[key_for(name)], name)
315
+ end
297
316
 
298
317
  def parent_setting_for(name)
299
318
  split_specific_setting_for(name)[0]
@@ -311,6 +330,10 @@ module Bundler
311
330
  BOOL_KEYS.include?(name.to_s) || BOOL_KEYS.include?(parent_setting_for(name.to_s))
312
331
  end
313
332
 
333
+ def is_string(name)
334
+ STRING_KEYS.include?(name.to_s) || name.to_s.start_with?("local.") || name.to_s.start_with?("mirror.") || name.to_s.start_with?("build.")
335
+ end
336
+
314
337
  def to_bool(value)
315
338
  case value
316
339
  when nil, /\A(false|f|no|n|0|)\z/i, false
@@ -328,6 +351,14 @@ module Bundler
328
351
  ARRAY_KEYS.include?(key.to_s)
329
352
  end
330
353
 
354
+ def is_credential(key)
355
+ key == "gem.push_key"
356
+ end
357
+
358
+ def is_userinfo(value)
359
+ value.include?(":")
360
+ end
361
+
331
362
  def to_array(value)
332
363
  return [] unless value
333
364
  value.split(":").map(&:to_sym)
@@ -374,6 +405,21 @@ module Bundler
374
405
  end
375
406
  end
376
407
 
408
+ def printable_value(value, key)
409
+ converted = converted_value(value, key)
410
+ return converted unless converted.is_a?(String)
411
+
412
+ if is_string(key)
413
+ converted
414
+ elsif is_credential(key)
415
+ "[REDACTED]"
416
+ elsif is_userinfo(converted)
417
+ converted.gsub(/:.*$/, ":[REDACTED]")
418
+ else
419
+ converted
420
+ end
421
+ end
422
+
377
423
  def global_config_file
378
424
  if ENV["BUNDLE_CONFIG"] && !ENV["BUNDLE_CONFIG"].empty?
379
425
  Pathname.new(ENV["BUNDLE_CONFIG"])
@@ -413,6 +459,12 @@ module Bundler
413
459
  \z
414
460
  /ix.freeze
415
461
 
462
+ def self.key_for(key)
463
+ key = normalize_uri(key).to_s if key.is_a?(String) && /https?:/ =~ key
464
+ key = key.to_s.gsub(".", "__").gsub("-", "___").upcase
465
+ "BUNDLE_#{key}"
466
+ end
467
+
416
468
  # TODO: duplicates Rubygems#normalize_uri
417
469
  # TODO: is this the correct place to validate mirror URIs?
418
470
  def self.normalize_uri(uri)
@@ -194,11 +194,11 @@ module Bundler
194
194
  return @md5_available if defined?(@md5_available)
195
195
  @md5_available = begin
196
196
  require "openssl"
197
- OpenSSL::Digest::MD5.digest("")
197
+ ::OpenSSL::Digest.digest("MD5", "")
198
198
  true
199
199
  rescue LoadError
200
200
  true
201
- rescue OpenSSL::Digest::DigestError
201
+ rescue ::OpenSSL::Digest::DigestError
202
202
  false
203
203
  end
204
204
  end
@@ -212,7 +212,7 @@ module Bundler
212
212
  filesystem_access(gemfile_path) {|g| File.open(g, "w") {|file| file.puts contents } }
213
213
  end
214
214
 
215
- private
215
+ private
216
216
 
217
217
  def validate_bundle_path
218
218
  path_separator = Bundler.rubygems.path_separator
@@ -26,7 +26,7 @@ module Bundler
26
26
  end
27
27
  end
28
28
 
29
- protected
29
+ protected
30
30
 
31
31
  # https://www.informit.com/articles/article.aspx?p=683059&seqNum=36
32
32
  def levenshtein_distance(this, that, ins = 2, del = 2, sub = 1)