bundler 2.5.9 → 2.5.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +136 -0
  3. data/lib/bundler/build_metadata.rb +2 -2
  4. data/lib/bundler/cli/check.rb +1 -1
  5. data/lib/bundler/cli/fund.rb +1 -1
  6. data/lib/bundler/cli/gem.rb +8 -15
  7. data/lib/bundler/cli/install.rb +1 -1
  8. data/lib/bundler/cli.rb +31 -48
  9. data/lib/bundler/compact_index_client/cache.rb +47 -72
  10. data/lib/bundler/compact_index_client/parser.rb +84 -0
  11. data/lib/bundler/compact_index_client.rb +51 -80
  12. data/lib/bundler/constants.rb +8 -1
  13. data/lib/bundler/definition.rb +120 -74
  14. data/lib/bundler/dependency.rb +2 -1
  15. data/lib/bundler/endpoint_specification.rb +11 -0
  16. data/lib/bundler/env.rb +1 -1
  17. data/lib/bundler/environment_preserver.rb +2 -20
  18. data/lib/bundler/errors.rb +14 -0
  19. data/lib/bundler/fetcher/compact_index.rb +15 -24
  20. data/lib/bundler/force_platform.rb +0 -2
  21. data/lib/bundler/gem_helper.rb +1 -1
  22. data/lib/bundler/gem_helpers.rb +14 -7
  23. data/lib/bundler/injector.rb +3 -5
  24. data/lib/bundler/installer/gem_installer.rb +0 -1
  25. data/lib/bundler/installer/standalone.rb +0 -3
  26. data/lib/bundler/installer.rb +9 -11
  27. data/lib/bundler/lazy_specification.rb +1 -0
  28. data/lib/bundler/man/bundle-add.1 +1 -1
  29. data/lib/bundler/man/bundle-binstubs.1 +1 -1
  30. data/lib/bundler/man/bundle-cache.1 +1 -1
  31. data/lib/bundler/man/bundle-check.1 +3 -1
  32. data/lib/bundler/man/bundle-check.1.ronn +3 -0
  33. data/lib/bundler/man/bundle-clean.1 +1 -1
  34. data/lib/bundler/man/bundle-config.1 +2 -4
  35. data/lib/bundler/man/bundle-config.1.ronn +1 -4
  36. data/lib/bundler/man/bundle-console.1 +1 -1
  37. data/lib/bundler/man/bundle-doctor.1 +1 -1
  38. data/lib/bundler/man/bundle-exec.1 +1 -1
  39. data/lib/bundler/man/bundle-gem.1 +7 -1
  40. data/lib/bundler/man/bundle-gem.1.ronn +11 -0
  41. data/lib/bundler/man/bundle-help.1 +1 -1
  42. data/lib/bundler/man/bundle-info.1 +1 -1
  43. data/lib/bundler/man/bundle-init.1 +1 -1
  44. data/lib/bundler/man/bundle-inject.1 +1 -1
  45. data/lib/bundler/man/bundle-install.1 +1 -1
  46. data/lib/bundler/man/bundle-list.1 +1 -1
  47. data/lib/bundler/man/bundle-lock.1 +1 -1
  48. data/lib/bundler/man/bundle-open.1 +1 -1
  49. data/lib/bundler/man/bundle-outdated.1 +1 -1
  50. data/lib/bundler/man/bundle-platform.1 +1 -1
  51. data/lib/bundler/man/bundle-plugin.1 +1 -1
  52. data/lib/bundler/man/bundle-pristine.1 +1 -1
  53. data/lib/bundler/man/bundle-remove.1 +1 -1
  54. data/lib/bundler/man/bundle-show.1 +1 -1
  55. data/lib/bundler/man/bundle-update.1 +1 -1
  56. data/lib/bundler/man/bundle-version.1 +1 -1
  57. data/lib/bundler/man/bundle-viz.1 +1 -1
  58. data/lib/bundler/man/bundle.1 +1 -1
  59. data/lib/bundler/man/gemfile.5 +1 -1
  60. data/lib/bundler/plugin/api/source.rb +1 -0
  61. data/lib/bundler/resolver/base.rb +4 -0
  62. data/lib/bundler/resolver/candidate.rb +4 -16
  63. data/lib/bundler/resolver/package.rb +4 -0
  64. data/lib/bundler/resolver/spec_group.rb +20 -2
  65. data/lib/bundler/resolver.rb +18 -9
  66. data/lib/bundler/rubygems_ext.rb +105 -23
  67. data/lib/bundler/rubygems_gem_installer.rb +35 -2
  68. data/lib/bundler/rubygems_integration.rb +16 -2
  69. data/lib/bundler/runtime.rb +1 -6
  70. data/lib/bundler/self_manager.rb +23 -3
  71. data/lib/bundler/settings.rb +12 -9
  72. data/lib/bundler/setup.rb +6 -0
  73. data/lib/bundler/shared_helpers.rb +6 -4
  74. data/lib/bundler/source/git/git_proxy.rb +8 -0
  75. data/lib/bundler/source/git.rb +43 -16
  76. data/lib/bundler/source/metadata.rb +2 -0
  77. data/lib/bundler/source/path.rb +0 -13
  78. data/lib/bundler/source/rubygems.rb +31 -30
  79. data/lib/bundler/source_list.rb +28 -4
  80. data/lib/bundler/spec_set.rb +16 -14
  81. data/lib/bundler/stub_specification.rb +8 -0
  82. data/lib/bundler/templates/newgem/CODE_OF_CONDUCT.md.tt +77 -29
  83. data/lib/bundler/vendored_net_http.rb +17 -6
  84. data/lib/bundler/version.rb +1 -1
  85. data/lib/bundler/yaml_serializer.rb +2 -9
  86. data/lib/bundler.rb +26 -1
  87. metadata +4 -3
@@ -79,7 +79,8 @@ module Bundler
79
79
  def solve_versions(root:, logger:)
80
80
  solver = PubGrub::VersionSolver.new(source: self, root: root, logger: logger)
81
81
  result = solver.solve
82
- result.map {|package, version| version.to_specs(package) }.flatten.uniq
82
+ resolved_specs = result.map {|package, version| version.to_specs(package) }.flatten
83
+ resolved_specs |= @base.specs_compatible_with(SpecSet.new(resolved_specs))
83
84
  rescue PubGrub::SolveFailure => e
84
85
  incompatibility = e.incompatibility
85
86
 
@@ -254,7 +255,7 @@ module Bundler
254
255
  results = filter_matching_specs(results, locked_requirement) if locked_requirement
255
256
 
256
257
  results.group_by(&:version).reduce([]) do |groups, (version, specs)|
257
- platform_specs = package.platforms.map {|platform| select_best_platform_match(specs, platform) }
258
+ platform_specs = package.platform_specs(specs)
258
259
 
259
260
  # If package is a top-level dependency,
260
261
  # candidate is only valid if there are matching versions for all resolution platforms.
@@ -269,14 +270,22 @@ module Bundler
269
270
  next groups if platform_specs.all?(&:empty?)
270
271
  end
271
272
 
272
- platform_specs.flatten!
273
-
274
273
  ruby_specs = select_best_platform_match(specs, Gem::Platform::RUBY)
275
- groups << Resolver::Candidate.new(version, specs: ruby_specs) if ruby_specs.any?
274
+ ruby_group = Resolver::SpecGroup.new(ruby_specs)
275
+
276
+ unless ruby_group.empty?
277
+ platform_specs.each do |specs|
278
+ ruby_group.merge(Resolver::SpecGroup.new(specs))
279
+ end
280
+
281
+ groups << Resolver::Candidate.new(version, group: ruby_group, priority: -1)
282
+ next groups if package.force_ruby_platform?
283
+ end
276
284
 
277
- next groups if platform_specs == ruby_specs || package.force_ruby_platform?
285
+ platform_group = Resolver::SpecGroup.new(platform_specs.flatten.uniq)
286
+ next groups if platform_group == ruby_group
278
287
 
279
- groups << Resolver::Candidate.new(version, specs: platform_specs)
288
+ groups << Resolver::Candidate.new(version, group: platform_group, priority: 1)
280
289
 
281
290
  groups
282
291
  end
@@ -431,8 +440,8 @@ module Bundler
431
440
 
432
441
  def requirement_to_range(requirement)
433
442
  ranges = requirement.requirements.map do |(op, version)|
434
- ver = Resolver::Candidate.new(version).generic!
435
- platform_ver = Resolver::Candidate.new(version).platform_specific!
443
+ ver = Resolver::Candidate.new(version, priority: -1)
444
+ platform_ver = Resolver::Candidate.new(version, priority: 1)
436
445
 
437
446
  case op
438
447
  when "~>"
@@ -1,11 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "pathname"
4
-
5
3
  require "rubygems" unless defined?(Gem)
6
4
 
7
- require "rubygems/specification"
8
-
9
5
  # We can't let `Gem::Source` be autoloaded in the `Gem::Specification#source`
10
6
  # redefinition below, so we need to load it upfront. The reason is that if
11
7
  # Bundler monkeypatches are loaded before RubyGems activates an executable (for
@@ -17,10 +13,6 @@ require "rubygems/specification"
17
13
  # `Gem::Source` from the redefined `Gem::Specification#source`.
18
14
  require "rubygems/source"
19
15
 
20
- require_relative "match_metadata"
21
- require_relative "force_platform"
22
- require_relative "match_platform"
23
-
24
16
  # Cherry-pick fixes to `Gem.ruby_version` to be useful for modern Bundler
25
17
  # versions and ignore patchlevels
26
18
  # (https://github.com/rubygems/rubygems/pull/5472,
@@ -31,7 +23,52 @@ unless Gem.ruby_version.to_s == RUBY_VERSION || RUBY_PATCHLEVEL == -1
31
23
  end
32
24
 
33
25
  module Gem
26
+ # Can be removed once RubyGems 3.5.11 support is dropped
27
+ unless Gem.respond_to?(:freebsd_platform?)
28
+ def self.freebsd_platform?
29
+ RbConfig::CONFIG["host_os"].to_s.include?("bsd")
30
+ end
31
+ end
32
+
33
+ # Can be removed once RubyGems 3.5.14 support is dropped
34
+ unless Gem.respond_to?(:open_file_with_flock)
35
+ def self.open_file_with_flock(path, &block)
36
+ flags = File.exist?(path) ? "r+" : "a+"
37
+
38
+ File.open(path, flags) do |io|
39
+ begin
40
+ io.flock(File::LOCK_EX)
41
+ rescue Errno::ENOSYS, Errno::ENOTSUP
42
+ end
43
+ yield io
44
+ rescue Errno::ENOLCK # NFS
45
+ if Thread.main != Thread.current
46
+ raise
47
+ else
48
+ File.open(path, flags, &block)
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ require "rubygems/specification"
55
+
56
+ # Can be removed once RubyGems 3.5.14 support is dropped
57
+ VALIDATES_FOR_RESOLUTION = Specification.new.respond_to?(:validate_for_resolution).freeze
58
+
59
+ # Can be removed once RubyGems 3.3.15 support is dropped
60
+ FLATTENS_REQUIRED_PATHS = Specification.new.respond_to?(:flatten_require_paths).freeze
61
+
34
62
  class Specification
63
+ # Can be removed once RubyGems 3.5.15 support is dropped
64
+ correct_array_attributes = @@default_value.select {|_k,v| v.is_a?(Array) }.keys
65
+ unless @@array_attributes == correct_array_attributes
66
+ @@array_attributes = correct_array_attributes # rubocop:disable Style/ClassVars
67
+ end
68
+
69
+ require_relative "match_metadata"
70
+ require_relative "match_platform"
71
+
35
72
  include ::Bundler::MatchMetadata
36
73
  include ::Bundler::MatchPlatform
37
74
 
@@ -48,7 +85,7 @@ module Gem
48
85
 
49
86
  def full_gem_path
50
87
  if source.respond_to?(:root)
51
- Pathname.new(loaded_from).dirname.expand_path(source.root).to_s
88
+ File.expand_path(File.dirname(loaded_from), source.root)
52
89
  else
53
90
  rg_full_gem_path
54
91
  end
@@ -127,6 +164,33 @@ module Gem
127
164
  !default_gem? && !File.directory?(full_gem_path)
128
165
  end
129
166
 
167
+ unless VALIDATES_FOR_RESOLUTION
168
+ def validate_for_resolution
169
+ SpecificationPolicy.new(self).validate_for_resolution
170
+ end
171
+ end
172
+
173
+ unless FLATTENS_REQUIRED_PATHS
174
+ def flatten_require_paths
175
+ return unless raw_require_paths.first.is_a?(Array)
176
+
177
+ warn "#{name} #{version} includes a gemspec with `require_paths` set to an array of arrays. Newer versions of this gem might've already fixed this"
178
+ raw_require_paths.flatten!
179
+ end
180
+
181
+ class << self
182
+ module RequirePathFlattener
183
+ def from_yaml(input)
184
+ spec = super(input)
185
+ spec.flatten_require_paths
186
+ spec
187
+ end
188
+ end
189
+
190
+ prepend RequirePathFlattener
191
+ end
192
+ end
193
+
130
194
  private
131
195
 
132
196
  def dependencies_to_gemfile(dependencies, group = nil)
@@ -146,29 +210,47 @@ module Gem
146
210
  end
147
211
  end
148
212
 
213
+ unless VALIDATES_FOR_RESOLUTION
214
+ class SpecificationPolicy
215
+ def validate_for_resolution
216
+ validate_required!
217
+ end
218
+ end
219
+ end
220
+
221
+ module BetterPermissionError
222
+ def data
223
+ super
224
+ rescue Errno::EACCES
225
+ raise Bundler::PermissionError.new(loaded_from, :read)
226
+ end
227
+ end
228
+
229
+ require "rubygems/stub_specification"
230
+
231
+ class StubSpecification
232
+ prepend BetterPermissionError
233
+ end
234
+
149
235
  class Dependency
236
+ require_relative "force_platform"
237
+
150
238
  include ::Bundler::ForcePlatform
151
239
 
240
+ attr_reader :force_ruby_platform
241
+
152
242
  attr_accessor :source, :groups
153
243
 
154
244
  alias_method :eql?, :==
155
245
 
156
- def force_ruby_platform
157
- return @force_ruby_platform if defined?(@force_ruby_platform) && !@force_ruby_platform.nil?
158
-
159
- @force_ruby_platform = default_force_ruby_platform
160
- end
161
-
162
- def encode_with(coder)
163
- to_yaml_properties.each do |ivar|
164
- coder[ivar.to_s.sub(/^@/, "")] = instance_variable_get(ivar)
246
+ unless method_defined?(:encode_with, false)
247
+ def encode_with(coder)
248
+ [:@name, :@requirement, :@type, :@prerelease, :@version_requirements].each do |ivar|
249
+ coder[ivar.to_s.sub(/^@/, "")] = instance_variable_get(ivar)
250
+ end
165
251
  end
166
252
  end
167
253
 
168
- def to_yaml_properties
169
- instance_variables.reject {|p| ["@source", "@groups"].include?(p.to_s) }
170
- end
171
-
172
254
  def to_lock
173
255
  out = String.new(" #{name}")
174
256
  unless requirement.none?
@@ -221,7 +303,7 @@ module Gem
221
303
 
222
304
  # cpu
223
305
  ([nil,"universal"].include?(@cpu) || [nil, "universal"].include?(other.cpu) || @cpu == other.cpu ||
224
- (@cpu == "arm" && other.cpu.start_with?("arm"))) &&
306
+ (@cpu == "arm" && other.cpu.start_with?("armv"))) &&
225
307
 
226
308
  # os
227
309
  @os == other.os &&
@@ -29,7 +29,10 @@ module Bundler
29
29
  write_build_info_file
30
30
  run_post_build_hooks
31
31
 
32
- generate_bin
32
+ SharedHelpers.filesystem_access(bin_dir, :write) do
33
+ generate_bin
34
+ end
35
+
33
36
  generate_plugins
34
37
 
35
38
  write_spec
@@ -45,7 +48,17 @@ module Bundler
45
48
  spec
46
49
  end
47
50
 
48
- def pre_install_checks
51
+ if Bundler.rubygems.provides?("< 3.5")
52
+ def pre_install_checks
53
+ super
54
+ rescue Gem::FilePermissionError
55
+ # Ignore permission checks in RubyGems. Instead, go on, and try to write
56
+ # for real. We properly handle permission errors when they happen.
57
+ nil
58
+ end
59
+ end
60
+
61
+ def ensure_writable_dir(dir)
49
62
  super
50
63
  rescue Gem::FilePermissionError
51
64
  # Ignore permission checks in RubyGems. Instead, go on, and try to write
@@ -68,6 +81,26 @@ module Bundler
68
81
  end
69
82
  end
70
83
 
84
+ if Bundler.rubygems.provides?("< 3.5.15")
85
+ def generate_bin_script(filename, bindir)
86
+ bin_script_path = File.join bindir, formatted_program_filename(filename)
87
+
88
+ Gem.open_file_with_flock("#{bin_script_path}.lock") do
89
+ require "fileutils"
90
+ FileUtils.rm_f bin_script_path # prior install may have been --no-wrappers
91
+
92
+ File.open(bin_script_path, "wb", 0o755) do |file|
93
+ file.write app_script_text(filename)
94
+ file.chmod(options[:prog_mode] || 0o755)
95
+ end
96
+ end
97
+
98
+ verbose bin_script_path
99
+
100
+ generate_windows_script filename, bindir
101
+ end
102
+ end
103
+
71
104
  def build_extensions
72
105
  extension_cache_path = options[:bundler_extension_cache_path]
73
106
  extension_dir = spec.extension_dir
@@ -48,7 +48,7 @@ module Bundler
48
48
  end
49
49
 
50
50
  def validate(spec)
51
- Bundler.ui.silence { spec.validate(false) }
51
+ Bundler.ui.silence { spec.validate_for_resolution }
52
52
  rescue Gem::InvalidSpecificationException => e
53
53
  error_message = "The gemspec at #{spec.loaded_from} is not valid. Please fix this gemspec.\n" \
54
54
  "The validation error was '#{e.message}'\n"
@@ -204,7 +204,7 @@ module Bundler
204
204
 
205
205
  [::Kernel.singleton_class, ::Kernel].each do |kernel_class|
206
206
  redefine_method(kernel_class, :gem) do |dep, *reqs|
207
- if executables&.include?(File.basename(caller.first.split(":").first))
207
+ if executables&.include?(File.basename(caller_locations(1, 1).first.path))
208
208
  break
209
209
  end
210
210
 
@@ -469,11 +469,25 @@ module Bundler
469
469
  end
470
470
 
471
471
  def all_specs
472
+ SharedHelpers.major_deprecation 2, "Bundler.rubygems.all_specs has been removed in favor of Bundler.rubygems.installed_specs"
473
+
472
474
  Gem::Specification.stubs.map do |stub|
473
475
  StubSpecification.from_stub(stub)
474
476
  end
475
477
  end
476
478
 
479
+ def installed_specs
480
+ Gem::Specification.stubs.reject(&:default_gem?).map do |stub|
481
+ StubSpecification.from_stub(stub)
482
+ end
483
+ end
484
+
485
+ def default_specs
486
+ Gem::Specification.default_stubs.map do |stub|
487
+ StubSpecification.from_stub(stub)
488
+ end
489
+ end
490
+
477
491
  def find_bundler(version)
478
492
  find_name("bundler").find {|s| s.version.to_s == version }
479
493
  end
@@ -10,7 +10,7 @@ module Bundler
10
10
  end
11
11
 
12
12
  def setup(*groups)
13
- @definition.ensure_equivalent_gemfile_and_lockfile if Bundler.frozen_bundle?
13
+ @definition.ensure_equivalent_gemfile_and_lockfile
14
14
 
15
15
  # Has to happen first
16
16
  clean_load_path
@@ -128,11 +128,6 @@ module Bundler
128
128
  spec.source.cache(spec, custom_path) if spec.source.respond_to?(:cache)
129
129
  end
130
130
 
131
- Dir[cache_path.join("*/.git")].each do |git_dir|
132
- FileUtils.rm_rf(git_dir)
133
- FileUtils.touch(File.expand_path("../.bundlecache", git_dir))
134
- end
135
-
136
131
  prune_cache(cache_path) unless Bundler.settings[:no_prune]
137
132
  end
138
133
 
@@ -70,8 +70,23 @@ module Bundler
70
70
  configured_gem_home = ENV["GEM_HOME"]
71
71
  configured_gem_path = ENV["GEM_PATH"]
72
72
 
73
- cmd = [$PROGRAM_NAME, *ARGV]
74
- cmd.unshift(Gem.ruby) unless File.executable?($PROGRAM_NAME)
73
+ # Bundler specs need some stuff to be required before Bundler starts
74
+ # running, for example, for faking the compact index API. However, these
75
+ # flags are lost when we reexec to a different version of Bundler. In the
76
+ # future, we may be able to properly reconstruct the original Ruby
77
+ # invocation (see https://bugs.ruby-lang.org/issues/6648), but for now
78
+ # there's no way to do it, so we need to be explicit about how to re-exec.
79
+ # This may be a feature end users request at some point, but maybe by that
80
+ # time, we have builtin tools to do. So for now, we use an undocumented
81
+ # ENV variable only for our specs.
82
+ bundler_spec_original_cmd = ENV["BUNDLER_SPEC_ORIGINAL_CMD"]
83
+ if bundler_spec_original_cmd
84
+ require "shellwords"
85
+ cmd = [*Shellwords.shellsplit(bundler_spec_original_cmd), *ARGV]
86
+ else
87
+ cmd = [$PROGRAM_NAME, *ARGV]
88
+ cmd.unshift(Gem.ruby) unless File.executable?($PROGRAM_NAME)
89
+ end
75
90
 
76
91
  Bundler.with_original_env do
77
92
  Kernel.exec(
@@ -92,6 +107,7 @@ module Bundler
92
107
  def autoswitching_applies?
93
108
  ENV["BUNDLER_VERSION"].nil? &&
94
109
  Bundler.rubygems.supports_bundler_trampolining? &&
110
+ ruby_can_restart_with_same_arguments? &&
95
111
  SharedHelpers.in_bundle? &&
96
112
  lockfile_version
97
113
  end
@@ -113,7 +129,7 @@ module Bundler
113
129
  end
114
130
 
115
131
  def local_specs
116
- @local_specs ||= Bundler::Source::Rubygems.new("allow_local" => true, "allow_cached" => true).specs.select {|spec| spec.name == "bundler" }
132
+ @local_specs ||= Bundler::Source::Rubygems.new("allow_local" => true).specs.select {|spec| spec.name == "bundler" }
117
133
  end
118
134
 
119
135
  def remote_specs
@@ -151,6 +167,10 @@ module Bundler
151
167
  !version.to_s.end_with?(".dev")
152
168
  end
153
169
 
170
+ def ruby_can_restart_with_same_arguments?
171
+ $PROGRAM_NAME != "-e"
172
+ end
173
+
154
174
  def updating?
155
175
  "update".start_with?(ARGV.first || " ") && ARGV[1..-1].any? {|a| a.start_with?("--bundler") }
156
176
  end
@@ -7,7 +7,6 @@ module Bundler
7
7
  autoload :Validator, File.expand_path("settings/validator", __dir__)
8
8
 
9
9
  BOOL_KEYS = %w[
10
- allow_deployment_source_credential_changes
11
10
  allow_offline_install
12
11
  auto_clean_without_path
13
12
  auto_install
@@ -104,6 +103,7 @@ module Bundler
104
103
  def initialize(root = nil)
105
104
  @root = root
106
105
  @local_config = load_config(local_config_file)
106
+ @local_root = root || Pathname.new(".bundle").expand_path
107
107
 
108
108
  @env_config = ENV.to_h
109
109
  @env_config.select! {|key, _value| key.start_with?("BUNDLE_") }
@@ -143,7 +143,7 @@ module Bundler
143
143
  end
144
144
 
145
145
  def set_local(key, value)
146
- local_config_file || raise(GemfileNotFound, "Could not locate Gemfile")
146
+ local_config_file = @local_root.join("config")
147
147
 
148
148
  set_key(key, value, @local_config, local_config_file)
149
149
  end
@@ -492,6 +492,10 @@ module Bundler
492
492
  valid_file = file.exist? && !file.size.zero?
493
493
  return {} unless valid_file
494
494
  serializer_class.load(file.read).inject({}) do |config, (k, v)|
495
+ k = k.dup
496
+ k << "/" if /https?:/i.match?(k) && !k.end_with?("/", "__#{FALLBACK_TIMEOUT_URI_OPTION.upcase}")
497
+ k.gsub!(".", "__")
498
+
495
499
  unless k.start_with?("#")
496
500
  if k.include?("-")
497
501
  Bundler.ui.warn "Your #{file} config includes `#{k}`, which contains the dash character (`-`).\n" \
@@ -519,26 +523,25 @@ module Bundler
519
523
  YAMLSerializer
520
524
  end
521
525
 
522
- PER_URI_OPTIONS = %w[
523
- fallback_timeout
524
- ].freeze
526
+ FALLBACK_TIMEOUT_URI_OPTION = "fallback_timeout"
525
527
 
526
528
  NORMALIZE_URI_OPTIONS_PATTERN =
527
529
  /
528
530
  \A
529
531
  (\w+\.)? # optional prefix key
530
532
  (https?.*?) # URI
531
- (\.#{Regexp.union(PER_URI_OPTIONS)})? # optional suffix key
533
+ (\.#{FALLBACK_TIMEOUT_URI_OPTION})? # optional suffix key
532
534
  \z
533
535
  /ix
534
536
 
535
537
  def self.key_for(key)
536
- key = normalize_uri(key).to_s if key.is_a?(String) && key.start_with?("http", "mirror.http")
537
- key = key_to_s(key).gsub(".", "__")
538
+ key = key_to_s(key)
539
+ key = normalize_uri(key) if key.start_with?("http", "mirror.http")
540
+ key = key.gsub(".", "__")
538
541
  key.gsub!("-", "___")
539
542
  key.upcase!
540
543
 
541
- key.prepend("BUNDLE_")
544
+ key.gsub(/\A([ #]*)/, '\1BUNDLE_')
542
545
  end
543
546
 
544
547
  # TODO: duplicates Rubygems#normalize_uri
data/lib/bundler/setup.rb CHANGED
@@ -5,6 +5,12 @@ require_relative "shared_helpers"
5
5
  if Bundler::SharedHelpers.in_bundle?
6
6
  require_relative "../bundler"
7
7
 
8
+ # autoswitch to locked Bundler version if available
9
+ Bundler.auto_switch
10
+
11
+ # try to auto_install first before we get to the `Bundler.ui.silence`, so user knows what is happening
12
+ Bundler.auto_install
13
+
8
14
  if STDOUT.tty? || ENV["BUNDLER_FORCE_TTY"]
9
15
  begin
10
16
  Bundler.ui.silence { Bundler.setup }
@@ -1,14 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "pathname"
4
- require "rbconfig"
5
-
6
3
  require_relative "version"
7
- require_relative "constants"
8
4
  require_relative "rubygems_integration"
9
5
  require_relative "current_ruby"
10
6
 
7
+ autoload :Pathname, "pathname"
8
+
11
9
  module Bundler
10
+ autoload :WINDOWS, File.expand_path("constants", __dir__)
11
+ autoload :FREEBSD, File.expand_path("constants", __dir__)
12
+ autoload :NULL, File.expand_path("constants", __dir__)
13
+
12
14
  module SharedHelpers
13
15
  def root
14
16
  gemfile = find_gemfile
@@ -182,6 +182,14 @@ module Bundler
182
182
  if err.include?("Could not find remote branch")
183
183
  raise MissingGitRevisionError.new(command_with_no_credentials, nil, explicit_ref, credential_filtered_uri)
184
184
  else
185
+ idx = command.index("--depth")
186
+ if idx
187
+ command.delete_at(idx)
188
+ command.delete_at(idx)
189
+ command_with_no_credentials = check_allowed(command)
190
+
191
+ err += "Retrying without --depth argument."
192
+ end
185
193
  raise GitCommandError.new(command_with_no_credentials, path, err)
186
194
  end
187
195
  end
@@ -32,6 +32,20 @@ module Bundler
32
32
  @local = false
33
33
  end
34
34
 
35
+ def remote!
36
+ return if @allow_remote
37
+
38
+ @local_specs = nil
39
+ @allow_remote = true
40
+ end
41
+
42
+ def cached!
43
+ return if @allow_cached
44
+
45
+ @local_specs = nil
46
+ @allow_cached = true
47
+ end
48
+
35
49
  def self.from_lock(options)
36
50
  new(options.merge("uri" => options.delete("remote")))
37
51
  end
@@ -150,7 +164,8 @@ module Bundler
150
164
  "does not exist. Run `bundle config unset local.#{override_for(original_path)}` to remove the local override"
151
165
  end
152
166
 
153
- set_local!(path)
167
+ @local = true
168
+ set_paths!(path)
154
169
 
155
170
  # Create a new git proxy without the cached revision
156
171
  # so the Gemfile.lock always picks up the new revision.
@@ -173,13 +188,11 @@ module Bundler
173
188
  end
174
189
 
175
190
  def specs(*)
176
- set_local!(app_cache_path) if has_app_cache? && !local?
191
+ set_cache_path!(app_cache_path) if has_app_cache? && !local?
177
192
 
178
193
  if requires_checkout? && !@copied
179
194
  fetch
180
- git_proxy.copy_to(install_path, submodules)
181
- serialize_gemspecs_in(install_path)
182
- @copied = true
195
+ checkout
183
196
  end
184
197
 
185
198
  local_specs
@@ -192,10 +205,7 @@ module Bundler
192
205
  print_using_message "Using #{version_message(spec, options[:previous_spec])} from #{self}"
193
206
 
194
207
  if (requires_checkout? && !@copied) || force
195
- Bundler.ui.debug " * Checking out revision: #{ref}"
196
- git_proxy.copy_to(install_path, submodules)
197
- serialize_gemspecs_in(install_path)
198
- @copied = true
208
+ checkout
199
209
  end
200
210
 
201
211
  generate_bin_options = { disable_extensions: !Bundler.rubygems.spec_missing_extensions?(spec), build_args: options[:build_args] }
@@ -207,12 +217,13 @@ module Bundler
207
217
  def cache(spec, custom_path = nil)
208
218
  app_cache_path = app_cache_path(custom_path)
209
219
  return unless Bundler.feature_flag.cache_all?
210
- return if path == app_cache_path
220
+ return if install_path == app_cache_path
221
+ return if cache_path == app_cache_path
211
222
  cached!
212
223
  FileUtils.rm_rf(app_cache_path)
213
224
  git_proxy.checkout if requires_checkout?
214
- git_proxy.copy_to(app_cache_path, @submodules)
215
- serialize_gemspecs_in(app_cache_path)
225
+ FileUtils.cp_r("#{cache_path}/.", app_cache_path)
226
+ FileUtils.touch(app_cache_path.join(".bundlecache"))
216
227
  end
217
228
 
218
229
  def load_spec_files
@@ -256,6 +267,13 @@ module Bundler
256
267
 
257
268
  private
258
269
 
270
+ def checkout
271
+ Bundler.ui.debug " * Checking out revision: #{ref}"
272
+ git_proxy.copy_to(install_path, submodules)
273
+ serialize_gemspecs_in(install_path)
274
+ @copied = true
275
+ end
276
+
259
277
  def humanized_ref
260
278
  if local?
261
279
  path
@@ -284,10 +302,19 @@ module Bundler
284
302
  end
285
303
  end
286
304
 
287
- def set_local!(path)
288
- @local = true
289
- @local_specs = @git_proxy = nil
290
- @cache_path = @install_path = path
305
+ def set_paths!(path)
306
+ set_cache_path!(path)
307
+ set_install_path!(path)
308
+ end
309
+
310
+ def set_cache_path!(path)
311
+ @git_proxy = nil
312
+ @cache_path = path
313
+ end
314
+
315
+ def set_install_path!(path)
316
+ @local_specs = nil
317
+ @install_path = path
291
318
  end
292
319
 
293
320
  def has_app_cache?
@@ -11,6 +11,8 @@ module Bundler
11
11
  end
12
12
 
13
13
  if local_spec = Gem.loaded_specs["bundler"]
14
+ raise CorruptBundlerInstallError.new(local_spec) if local_spec.version.to_s != Bundler::VERSION
15
+
14
16
  idx << local_spec
15
17
  else
16
18
  idx << Gem::Specification.new do |s|
@@ -18,9 +18,6 @@ module Bundler
18
18
  @options = options.dup
19
19
  @glob = options["glob"] || DEFAULT_GLOB
20
20
 
21
- @allow_cached = false
22
- @allow_remote = false
23
-
24
21
  @root_path = options["root_path"] || root
25
22
 
26
23
  if options["path"]
@@ -41,16 +38,6 @@ module Bundler
41
38
  @original_path = @path
42
39
  end
43
40
 
44
- def remote!
45
- @local_specs = nil
46
- @allow_remote = true
47
- end
48
-
49
- def cached!
50
- @local_specs = nil
51
- @allow_cached = true
52
- end
53
-
54
41
  def self.from_lock(options)
55
42
  new(options.merge("path" => options.delete("remote")))
56
43
  end