bundler 4.1.0.beta3 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/lib/bundler/build_metadata.rb +2 -2
  3. data/lib/bundler/checksum.rb +8 -2
  4. data/lib/bundler/cli/clean.rb +19 -3
  5. data/lib/bundler/cli/exec.rb +1 -1
  6. data/lib/bundler/cli/install.rb +1 -1
  7. data/lib/bundler/cli/lock.rb +12 -0
  8. data/lib/bundler/cli/update.rb +1 -1
  9. data/lib/bundler/cli.rb +2 -0
  10. data/lib/bundler/definition.rb +125 -3
  11. data/lib/bundler/dsl.rb +6 -2
  12. data/lib/bundler/errors.rb +8 -0
  13. data/lib/bundler/fetcher/downloader.rb +7 -3
  14. data/lib/bundler/index.rb +7 -2
  15. data/lib/bundler/inline.rb +16 -8
  16. data/lib/bundler/installer.rb +19 -0
  17. data/lib/bundler/lazy_specification.rb +42 -25
  18. data/lib/bundler/lockfile_generator.rb +21 -9
  19. data/lib/bundler/lockfile_parser.rb +21 -5
  20. data/lib/bundler/man/bundle-lock.1 +7 -1
  21. data/lib/bundler/man/bundle-lock.1.ronn +10 -0
  22. data/lib/bundler/man/bundle-plugin.1 +61 -0
  23. data/lib/bundler/man/bundle-plugin.1.ronn +84 -0
  24. data/lib/bundler/man/gemfile.5 +3 -1
  25. data/lib/bundler/man/gemfile.5.ronn +11 -3
  26. data/lib/bundler/match_platform.rb +3 -3
  27. data/lib/bundler/mirror.rb +7 -5
  28. data/lib/bundler/resolver.rb +2 -0
  29. data/lib/bundler/ruby_dsl.rb +2 -1
  30. data/lib/bundler/rubygems_ext.rb +41 -9
  31. data/lib/bundler/rubygems_integration.rb +2 -4
  32. data/lib/bundler/runtime.rb +24 -10
  33. data/lib/bundler/source/git/git_proxy.rb +18 -6
  34. data/lib/bundler/source/git.rb +0 -2
  35. data/lib/bundler/spec_set.rb +26 -7
  36. data/lib/bundler/stub_specification.rb +4 -0
  37. data/lib/bundler/version.rb +1 -1
  38. data/lib/bundler/worker.rb +4 -0
  39. data/lib/bundler.rb +1 -1
  40. data/lib/rubygems/compact_index_client/http_fetcher.rb +3 -1
  41. data/lib/rubygems/yaml_serializer.rb +128 -46
  42. metadata +2 -2
@@ -42,11 +42,12 @@ module Bundler
42
42
  # Loads the file relative to the dirname of the Gemfile itself.
43
43
  def normalize_ruby_file(filename)
44
44
  file_content = Bundler.read_file(gemfile.dirname.join(filename))
45
- # match "ruby-3.2.2", ruby = "3.2.2", ruby = '3.2.2' or "ruby 3.2.2" capturing version string up to the first space or comment
45
+ # match "ruby-3.2.2", ruby = "3.2.2", ruby = '3.2.2', ruby = { version = "3.2.2" } or "ruby 3.2.2" capturing version string up to the first space or comment
46
46
  version_match = /^ # Start of line
47
47
  ruby # Literal "ruby"
48
48
  [\s-]* # Optional whitespace or hyphens (for "ruby-3.2.2" format)
49
49
  (?:=\s*)? # Optional equals sign with whitespace (for ruby = "3.2.2" format)
50
+ (?:\{[^}]*?\bversion\s*=\s*)? # Optional inline table up to its version key (for ruby = { version = "3.2.2" } format)
50
51
  (?:
51
52
  "([^"]+)" # Double quoted version
52
53
  |
@@ -42,6 +42,29 @@ module Gem
42
42
  def self.content_addressed_row?(suffix, platform, required_ruby_version = nil, validate_ruby_abi: true)
43
43
  false
44
44
  end
45
+
46
+ def self.platform_eligible?(platform)
47
+ false
48
+ end
49
+
50
+ def self.ruby_abi_for(required_ruby_version)
51
+ nil
52
+ end
53
+
54
+ def self.valid_ruby_abi?(value)
55
+ value.is_a?(String) && /\A\d+\.\d+\z/.match?(value)
56
+ end
57
+
58
+ def self.ruby_abi_requirement(ruby_abi)
59
+ Gem::Requirement.new("~> #{ruby_abi}.0")
60
+ end
61
+ end
62
+ end
63
+
64
+ # Can be removed once RubyGems 4.0.0 support is dropped
65
+ unless respond_to?(:ruby_abi)
66
+ def self.ruby_abi
67
+ ruby_version.segments.first(2).join(".")
45
68
  end
46
69
  end
47
70
 
@@ -498,15 +521,6 @@ module Gem
498
521
  end
499
522
  end
500
523
 
501
- unless instance_method(:initialize).parameters.any? {|kind, name| kind == :key && name == :content_address }
502
- alias_method :initialize_without_content_address, :initialize
503
-
504
- def initialize(name, version, platform = Gem::Platform::RUBY, content_address: nil)
505
- initialize_without_content_address(name, version, platform)
506
- @content_address = content_address
507
- end
508
- end
509
-
510
524
  def lock_name
511
525
  if platform == Gem::Platform::RUBY
512
526
  "#{name} (#{version})"
@@ -516,6 +530,24 @@ module Gem
516
530
  end
517
531
  end
518
532
 
533
+ # Defined unconditionally for testability, see SplitCompactIndexEntryOnFirstColon.
534
+ module NameTupleContentAddress
535
+ def initialize(name, version, platform = Gem::Platform::RUBY, content_address: nil)
536
+ super(name, version, platform)
537
+ @content_address = content_address
538
+ end
539
+
540
+ def full_name
541
+ return super unless @content_address
542
+
543
+ "#{@name}-#{@version}-#{@content_address}"
544
+ end
545
+ end
546
+
547
+ unless NameTuple.instance_method(:initialize).parameters.any? {|kind, name| kind == :key && name == :content_address }
548
+ NameTuple.prepend(NameTupleContentAddress)
549
+ end
550
+
519
551
  unless Gem.rubygems_version >= Gem::Version.new("3.5.19")
520
552
  class Resolver::ActivationRequest
521
553
  remove_method :installed?
@@ -289,11 +289,9 @@ module Bundler
289
289
  end
290
290
 
291
291
  Bundler.rubygems.default_stubs.each do |stub|
292
- default_spec = stub.to_spec
293
- default_spec_name = default_spec.name
294
- next if specs_by_name.key?(default_spec_name)
292
+ next if specs_by_name.key?(stub.name)
295
293
 
296
- specs_by_name[default_spec_name] = default_spec
294
+ specs_by_name[stub.name] = stub.to_spec
297
295
  end
298
296
 
299
297
  specs_by_name
@@ -210,26 +210,25 @@ module Bundler
210
210
  stale_gemspec_files = gemspec_files - spec_gemspec_paths
211
211
  stale_extension_dirs = extension_dirs - spec_extension_paths
212
212
 
213
- removed_stale_gem_dirs = stale_gem_dirs.collect {|dir| remove_dir(dir, dry_run) }
214
- removed_stale_git_dirs = stale_git_dirs.collect {|dir| remove_dir(dir, dry_run) }
213
+ failures = []
214
+ removed_stale_gem_dirs = stale_gem_dirs.filter_map {|dir| remove_dir(dir, dry_run, failures) }
215
+ removed_stale_git_dirs = stale_git_dirs.filter_map {|dir| remove_dir(dir, dry_run, failures) }
215
216
  output = removed_stale_gem_dirs + removed_stale_git_dirs
216
217
 
217
218
  unless dry_run
218
219
  stale_files = stale_gem_bins + stale_gem_files + stale_gemspec_files
219
220
  stale_files.each do |file|
220
- SharedHelpers.filesystem_access(File.dirname(file)) do |_p|
221
- FileUtils.rm(file) if File.exist?(file)
222
- end
221
+ remove_path(file, failures, File.dirname(file))
223
222
  end
224
223
 
225
224
  stale_dirs = stale_git_cache_dirs + stale_extension_dirs
226
225
  stale_dirs.each do |stale_dir|
227
- SharedHelpers.filesystem_access(stale_dir) do |dir|
228
- FileUtils.rm_rf(dir) if File.exist?(dir)
229
- end
226
+ remove_path(stale_dir, failures)
230
227
  end
231
228
  end
232
229
 
230
+ raise CleanError.new(failures) unless failures.empty?
231
+
233
232
  output
234
233
  end
235
234
 
@@ -359,7 +358,7 @@ module Bundler
359
358
  ).uniq.join(File::PATH_SEPARATOR)
360
359
  end
361
360
 
362
- def remove_dir(dir, dry_run)
361
+ def remove_dir(dir, dry_run, failures)
363
362
  full_name = Pathname.new(dir).basename.to_s
364
363
 
365
364
  parts = full_name.split("-")
@@ -370,13 +369,28 @@ module Bundler
370
369
  if dry_run
371
370
  Bundler.ui.info "Would have removed #{output}"
372
371
  else
372
+ return unless remove_path(dir, failures)
373
373
  Bundler.ui.info "Removing #{output}"
374
- FileUtils.rm_rf(dir)
375
374
  end
376
375
 
377
376
  output
378
377
  end
379
378
 
379
+ # Collects the error instead of raising it, so that one path that cannot be
380
+ # removed does not stop the rest of the bundle from being cleaned.
381
+ def remove_path(path, failures, access_path = path)
382
+ SharedHelpers.filesystem_access(access_path) do
383
+ FileUtils.rm_r(path)
384
+ end
385
+ true
386
+ rescue Errno::ENOENT
387
+ # Removed by something else since the bundle was scanned
388
+ true
389
+ rescue BundlerError => e
390
+ failures << e
391
+ false
392
+ end
393
+
380
394
  def check_for_activated_spec!(spec)
381
395
  return unless activated_spec = Bundler.rubygems.loaded_specs(spec.name)
382
396
  return if activated_spec.version == spec.version
@@ -169,13 +169,25 @@ module Bundler
169
169
  git "fetch", "--force", "--quiet", *extra_fetch_args(ref), dir: destination
170
170
  end
171
171
 
172
- git "reset", "--hard", revision, dir: destination
172
+ # A checkout that already had a working tree may be a local override, which
173
+ # is the user's own working copy, so a failure only discards one that had none.
174
+ checked_out = installed_to?(destination)
175
+ begin
176
+ git "reset", "--hard", revision, dir: destination
173
177
 
174
- if submodules
175
- git_retry "submodule", "update", "--init", "--recursive", dir: destination
176
- elsif Gem::Version.create(version) >= Gem::Version.create("2.9.0")
177
- inner_command = "git -C $toplevel submodule deinit --force $sm_path"
178
- git_retry "submodule", "foreach", "--quiet", inner_command, dir: destination
178
+ if submodules
179
+ git_retry "submodule", "update", "--init", "--recursive", dir: destination
180
+ elsif Gem::Version.create(version) >= Gem::Version.create("2.9.0")
181
+ inner_command = "git -C $toplevel submodule deinit --force $sm_path"
182
+ git_retry "submodule", "foreach", "--quiet", inner_command, dir: destination
183
+ end
184
+ rescue GitCommandError
185
+ unless checked_out
186
+ SharedHelpers.filesystem_access(destination) do |p|
187
+ FileUtils.rm_rf(p)
188
+ end
189
+ end
190
+ raise
179
191
  end
180
192
  end
181
193
 
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../vendored_fileutils"
4
-
5
3
  module Bundler
6
4
  class Source
7
5
  class Git < Path
@@ -84,15 +84,36 @@ module Bundler
84
84
  platforms.delete(Bundler.local_platform) if less_specific_platform
85
85
  end
86
86
 
87
+ def assign_content_addresses!(ruby_abis, normalize: false, local: false)
88
+ @specs.each do |spec|
89
+ next unless spec.source.is_a?(Source::Rubygems)
90
+ next unless Gem::ContentAddress.platform_eligible?(spec.platform)
91
+
92
+ offered = spec.source.specs.search([spec.name, spec.version]).filter_map do |gem|
93
+ next unless gem.platform.to_s == spec.platform.to_s && Gem::ContentAddress.content_addressed?(gem)
94
+
95
+ [gem.content_address, Gem::ContentAddress.ruby_abi_for(gem.required_ruby_version)]
96
+ end.to_h
97
+
98
+ locked = normalize ? {} : spec.content_addresses
99
+ locked = locked.reject {|_, ruby_abi| ruby_abi.nil? } unless local
100
+ spec.content_addresses = locked.merge(offered).select {|_, ruby_abi| ruby_abi.nil? || ruby_abis.include?(ruby_abi) }
101
+ end
102
+ end
103
+
104
+ def content_addresses_cover?(ruby_abi)
105
+ @specs.all? {|spec| !spec.is_a?(LazySpecification) || spec.content_addresses.empty? || spec.content_addresses.value?(ruby_abi) }
106
+ end
107
+
87
108
  def validate_deps(s, overrides = s.is_a?(LazySpecification) ? Array(s.overrides) : [])
88
109
  Override.rewrite_dependencies(overrides, s.name, s.runtime_dependencies).each do |dep|
89
110
  next if dep.name == "bundler"
90
111
 
91
- return :missing unless names.include?(dep.name)
112
+ return :missing unless lookup.key?(dep.name)
92
113
 
93
114
  override = Override.find_for(overrides, dep.name, :version)
94
115
  dep = Gem::Dependency.new(dep.name, override.apply_to(dep.requirement)) if override
95
- return :invalid if none? {|spec| dep.matches_spec?(spec) }
116
+ return :invalid if Array(lookup[dep.name]).none? {|spec| dep.matches_spec?(spec) }
96
117
  end
97
118
 
98
119
  :valid
@@ -134,11 +155,9 @@ module Bundler
134
155
  # Materialize for all the specs in the spec set, regardless of what platform they're for
135
156
  # @return [Array<Gem::Specification>]
136
157
  def materialized_for_all_platforms
137
- @specs.map do |s|
138
- next s unless s.is_a?(LazySpecification)
139
- spec = s.materialize_for_cache
140
- raise GemNotFound, "Could not find #{s.full_name} in any of the sources" unless spec
141
- spec
158
+ @specs.flat_map do |s|
159
+ next [s] unless s.is_a?(LazySpecification)
160
+ s.materialize_for_cache
142
161
  end
143
162
  end
144
163
 
@@ -114,6 +114,10 @@ module Bundler
114
114
  stub.matches_for_glob(glob)
115
115
  end
116
116
 
117
+ def contains_requirable_file?(file)
118
+ stub.contains_requirable_file?(file)
119
+ end
120
+
117
121
  def raw_require_paths
118
122
  stub.raw_require_paths
119
123
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: false
2
2
 
3
3
  module Bundler
4
- VERSION = "4.1.0.beta3".freeze
4
+ VERSION = "4.1.0".freeze
5
5
 
6
6
  def self.bundler_major_version
7
7
  @bundler_major_version ||= gem_version.segments.first
@@ -93,6 +93,10 @@ module Bundler
93
93
  end
94
94
 
95
95
  def create_threads
96
+ # Jobs use FileUtils, and TruffleRuby shows other threads an autoloaded
97
+ # constant while its file is still loading.
98
+ require_relative "vendored_fileutils"
99
+
96
100
  creation_errors = []
97
101
 
98
102
  @threads = Array.new(@size) do |i|
data/lib/bundler.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "bundler/rubygems_ext"
4
- require_relative "bundler/vendored_fileutils"
5
4
  autoload :Pathname, "pathname" unless defined?(Pathname)
6
5
  require "rbconfig"
7
6
 
@@ -43,6 +42,7 @@ module Bundler
43
42
  autoload :CIDetector, File.expand_path("bundler/ci_detector", __dir__)
44
43
  autoload :Definition, File.expand_path("bundler/definition", __dir__)
45
44
  autoload :Dependency, File.expand_path("bundler/dependency", __dir__)
45
+ autoload :FileUtils, File.expand_path("bundler/vendored_fileutils", __dir__)
46
46
  autoload :Deprecate, File.expand_path("bundler/deprecate", __dir__)
47
47
  autoload :Digest, File.expand_path("bundler/digest", __dir__)
48
48
  autoload :Dsl, File.expand_path("bundler/dsl", __dir__)
@@ -9,6 +9,8 @@ class Gem::CompactIndexClient
9
9
  # Gem::CompactIndexClient: #call(path, headers) returning a
10
10
  # Gem::Net::HTTP response.
11
11
  class HTTPFetcher
12
+ include Gem::Text
13
+
12
14
  REDIRECT_LIMIT = 10
13
15
  private_constant :REDIRECT_LIMIT
14
16
 
@@ -79,7 +81,7 @@ class Gem::CompactIndexClient
79
81
  end
80
82
 
81
83
  def bad_response(response, uri)
82
- detail = response["X-Error-Message"] || response.message
84
+ detail = clean_text(response["X-Error-Message"] || response.message)
83
85
  Gem::RemoteFetcher::FetchError.new("bad response #{detail} #{response.code}", uri)
84
86
  end
85
87