diff options
author | Hiroshi SHIBATA <[email protected]> | 2023-12-22 07:01:12 +0900 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2023-12-22 07:24:04 +0900 |
commit | 82496f2b389278a569fa7680ee6faa55a97410d7 (patch) | |
tree | acce0c98431a9f617be3d5c971b4c684155c5b94 /lib | |
parent | fc549b2b3a65a95a734ee8679293a30284f84622 (diff) |
Merge RubyGems-3.5.2 and Bundler-2.5.2
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bundler/definition.rb | 30 | ||||
-rw-r--r-- | lib/bundler/lazy_specification.rb | 2 | ||||
-rw-r--r-- | lib/bundler/remote_specification.rb | 4 | ||||
-rw-r--r-- | lib/bundler/self_manager.rb | 2 | ||||
-rw-r--r-- | lib/bundler/spec_set.rb | 42 | ||||
-rw-r--r-- | lib/bundler/vendor/thor/lib/thor/shell/color.rb | 3 | ||||
-rw-r--r-- | lib/bundler/vendor/thor/lib/thor/shell/html.rb | 3 | ||||
-rw-r--r-- | lib/bundler/vendor/thor/lib/thor/shell/lcs_diff.rb | 49 | ||||
-rw-r--r-- | lib/bundler/version.rb | 2 | ||||
-rw-r--r-- | lib/rubygems.rb | 9 | ||||
-rw-r--r-- | lib/rubygems/basic_specification.rb | 8 | ||||
-rw-r--r-- | lib/rubygems/package.rb | 14 | ||||
-rw-r--r-- | lib/rubygems/request.rb | 8 |
13 files changed, 93 insertions, 83 deletions
diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index 5dc711ffde..9b905db1f9 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -496,7 +496,15 @@ module Bundler private :sources def nothing_changed? - !@source_changes && !@dependency_changes && !@new_platform && !@path_changes && !@local_changes && !@missing_lockfile_dep && !@unlocking_bundler && !@invalid_lockfile_dep + !@source_changes && + !@dependency_changes && + !@new_platform && + !@path_changes && + !@local_changes && + !@missing_lockfile_dep && + !@unlocking_bundler && + !@locked_spec_with_missing_deps && + !@locked_spec_with_invalid_deps end def no_resolve_needed? @@ -653,7 +661,8 @@ module Bundler [@local_changes, "the gemspecs for git local gems changed"], [@missing_lockfile_dep, "your lock file is missing \"#{@missing_lockfile_dep}\""], [@unlocking_bundler, "an update to the version of Bundler itself was requested"], - [@invalid_lockfile_dep, "your lock file has an invalid dependency \"#{@invalid_lockfile_dep}\""], + [@locked_spec_with_missing_deps, "your lock file includes \"#{@locked_spec_with_missing_deps}\" but not some of its dependencies"], + [@locked_spec_with_invalid_deps, "your lockfile does not satisfy dependencies of \"#{@locked_spec_with_invalid_deps}\""], ].select(&:first).map(&:last).join(", ") end @@ -708,26 +717,25 @@ module Bundler end def check_lockfile - @invalid_lockfile_dep = nil @missing_lockfile_dep = nil - locked_names = @locked_specs.map(&:name) + @locked_spec_with_invalid_deps = nil + @locked_spec_with_missing_deps = nil + missing = [] invalid = [] @locked_specs.each do |s| - s.dependencies.each do |dep| - next if dep.name == "bundler" + validation = @locked_specs.validate_deps(s) - missing << s unless locked_names.include?(dep.name) - invalid << s if @locked_specs.none? {|spec| dep.matches_spec?(spec) } - end + missing << s if validation == :missing + invalid << s if validation == :invalid end if missing.any? @locked_specs.delete(missing) - @missing_lockfile_dep = missing.first.name + @locked_spec_with_missing_deps = missing.first.name elsif !@dependency_changes @missing_lockfile_dep = current_dependencies.find do |d| @locked_specs[d.name].empty? && d.name != "bundler" @@ -737,7 +745,7 @@ module Bundler if invalid.any? @locked_specs.delete(invalid) - @invalid_lockfile_dep = invalid.first.name + @locked_spec_with_invalid_deps = invalid.first.name end end diff --git a/lib/bundler/lazy_specification.rb b/lib/bundler/lazy_specification.rb index f2d1016732..38aea2a4aa 100644 --- a/lib/bundler/lazy_specification.rb +++ b/lib/bundler/lazy_specification.rb @@ -10,6 +10,8 @@ module Bundler attr_reader :name, :version, :platform attr_accessor :source, :remote, :force_ruby_platform, :dependencies, :required_ruby_version, :required_rubygems_version + alias_method :runtime_dependencies, :dependencies + def self.from_spec(s) lazy_spec = new(s.name, s.version, s.platform, s.source) lazy_spec.dependencies = s.dependencies diff --git a/lib/bundler/remote_specification.rb b/lib/bundler/remote_specification.rb index f626a3218e..9d237f3fa0 100644 --- a/lib/bundler/remote_specification.rb +++ b/lib/bundler/remote_specification.rb @@ -88,6 +88,10 @@ module Bundler end end + def runtime_dependencies + dependencies.select(&:runtime?) + end + def git_version return unless loaded_from && source.is_a?(Bundler::Source::Git) " #{source.revision[0..6]}" diff --git a/lib/bundler/self_manager.rb b/lib/bundler/self_manager.rb index 1925a266d9..5accda4bcb 100644 --- a/lib/bundler/self_manager.rb +++ b/lib/bundler/self_manager.rb @@ -121,7 +121,7 @@ module Bundler source = Bundler::Source::Rubygems.new("remotes" => "https://rubygems.org") source.remote! source.add_dependency_names("bundler") - source.specs + source.specs.select(&:matches_current_metadata?) end end diff --git a/lib/bundler/spec_set.rb b/lib/bundler/spec_set.rb index a0ef3c2cb5..ceaac2cec5 100644 --- a/lib/bundler/spec_set.rb +++ b/lib/bundler/spec_set.rb @@ -37,7 +37,7 @@ module Bundler specs_for_dep.first.dependencies.each do |d| next if d.type == :development - incomplete = true if d.name != "bundler" && lookup[d.name].empty? + incomplete = true if d.name != "bundler" && lookup[d.name].nil? deps << [d, dep[1]] end else @@ -45,7 +45,7 @@ module Bundler end if incomplete && check - @incomplete_specs += lookup[name].any? ? lookup[name] : [LazySpecification.new(name, nil, nil)] + @incomplete_specs += lookup[name] || [LazySpecification.new(name, nil, nil)] end end @@ -64,7 +64,9 @@ module Bundler valid_platform = lookup.all? do |_, specs| spec = specs.first matching_specs = spec.source.specs.search([spec.name, spec.version]) - platform_spec = GemHelpers.select_best_platform_match(matching_specs, platform).find(&:matches_current_metadata?) + platform_spec = GemHelpers.select_best_platform_match(matching_specs, platform).find do |s| + s.matches_current_metadata? && valid_dependencies?(s) + end if platform_spec new_specs << LazySpecification.from_spec(platform_spec) @@ -90,9 +92,20 @@ module Bundler platforms end + def validate_deps(s) + s.runtime_dependencies.each do |dep| + next if dep.name == "bundler" + + return :missing unless names.include?(dep.name) + return :invalid if none? {|spec| dep.matches_spec?(spec) } + end + + :valid + end + def [](key) key = key.name if key.respond_to?(:name) - lookup[key].reverse + lookup[key]&.reverse || [] end def []=(key, value) @@ -167,7 +180,7 @@ module Bundler end def what_required(spec) - unless req = find {|s| s.dependencies.any? {|d| d.type == :runtime && d.name == spec.name } } + unless req = find {|s| s.runtime_dependencies.any? {|d| d.name == spec.name } } return [spec] end what_required(req) << spec @@ -193,8 +206,16 @@ module Bundler sorted.each(&b) end + def names + lookup.keys + end + private + def valid_dependencies?(s) + validate_deps(s) == :valid + end + def sorted rake = @specs.find {|s| s.name == "rake" } begin @@ -213,8 +234,9 @@ module Bundler def lookup @lookup ||= begin - lookup = Hash.new {|h, k| h[k] = [] } + lookup = {} @specs.each do |s| + lookup[s.name] ||= [] lookup[s.name] << s end lookup @@ -228,6 +250,8 @@ module Bundler def specs_for_dependency(dep, platform) specs_for_name = lookup[dep.name] + return [] unless specs_for_name + matching_specs = if dep.force_ruby_platform GemHelpers.force_ruby_platform(specs_for_name) else @@ -240,7 +264,11 @@ module Bundler def tsort_each_child(s) s.dependencies.sort_by(&:name).each do |d| next if d.type == :development - lookup[d.name].each {|s2| yield s2 } + + specs_for_name = lookup[d.name] + next unless specs_for_name + + specs_for_name.each {|s2| yield s2 } end end end diff --git a/lib/bundler/vendor/thor/lib/thor/shell/color.rb b/lib/bundler/vendor/thor/lib/thor/shell/color.rb index 6a9176331c..5d708fadca 100644 --- a/lib/bundler/vendor/thor/lib/thor/shell/color.rb +++ b/lib/bundler/vendor/thor/lib/thor/shell/color.rb @@ -1,5 +1,4 @@ require_relative "basic" -require_relative "lcs_diff" class Bundler::Thor module Shell @@ -7,8 +6,6 @@ class Bundler::Thor # Bundler::Thor::Shell::Basic to see all available methods. # class Color < Basic - include LCSDiff - # Embed in a String to clear all previous ANSI sequences. CLEAR = "\e[0m" # The start of an ANSI bold sequence. diff --git a/lib/bundler/vendor/thor/lib/thor/shell/html.rb b/lib/bundler/vendor/thor/lib/thor/shell/html.rb index 6091485acb..0277b882b7 100644 --- a/lib/bundler/vendor/thor/lib/thor/shell/html.rb +++ b/lib/bundler/vendor/thor/lib/thor/shell/html.rb @@ -1,5 +1,4 @@ require_relative "basic" -require_relative "lcs_diff" class Bundler::Thor module Shell @@ -7,8 +6,6 @@ class Bundler::Thor # Bundler::Thor::Shell::Basic to see all available methods. # class HTML < Basic - include LCSDiff - # The start of an HTML bold sequence. BOLD = "font-weight: bold" diff --git a/lib/bundler/vendor/thor/lib/thor/shell/lcs_diff.rb b/lib/bundler/vendor/thor/lib/thor/shell/lcs_diff.rb deleted file mode 100644 index 81268a9f02..0000000000 --- a/lib/bundler/vendor/thor/lib/thor/shell/lcs_diff.rb +++ /dev/null @@ -1,49 +0,0 @@ -module LCSDiff -protected - - # Overwrite show_diff to show diff with colors if Diff::LCS is - # available. - def show_diff(destination, content) #:nodoc: - if diff_lcs_loaded? && ENV["THOR_DIFF"].nil? && ENV["RAILS_DIFF"].nil? - actual = File.binread(destination).to_s.split("\n") - content = content.to_s.split("\n") - - Diff::LCS.sdiff(actual, content).each do |diff| - output_diff_line(diff) - end - else - super - end - end - -private - - def output_diff_line(diff) #:nodoc: - case diff.action - when "-" - say "- #{diff.old_element.chomp}", :red, true - when "+" - say "+ #{diff.new_element.chomp}", :green, true - when "!" - say "- #{diff.old_element.chomp}", :red, true - say "+ #{diff.new_element.chomp}", :green, true - else - say " #{diff.old_element.chomp}", nil, true - end - end - - # Check if Diff::LCS is loaded. If it is, use it to create pretty output - # for diff. - def diff_lcs_loaded? #:nodoc: - return true if defined?(Diff::LCS) - return @diff_lcs_loaded unless @diff_lcs_loaded.nil? - - @diff_lcs_loaded = begin - require "diff/lcs" - true - rescue LoadError - false - end - end - -end diff --git a/lib/bundler/version.rb b/lib/bundler/version.rb index 46a984283d..a98d7fab30 100644 --- a/lib/bundler/version.rb +++ b/lib/bundler/version.rb @@ -1,7 +1,7 @@ # frozen_string_literal: false module Bundler - VERSION = "2.5.1".freeze + VERSION = "2.5.2".freeze def self.bundler_major_version @bundler_major_version ||= VERSION.split(".").first.to_i diff --git a/lib/rubygems.rb b/lib/rubygems.rb index a5091b07b8..fd5683f1be 100644 --- a/lib/rubygems.rb +++ b/lib/rubygems.rb @@ -9,7 +9,7 @@ require "rbconfig" module Gem - VERSION = "3.5.1" + VERSION = "3.5.2" end # Must be first since it unloads the prelude from 1.9.2 @@ -943,6 +943,13 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} end ## + # Suffixes for dynamic library require-able paths. + + def self.dynamic_library_suffixes + @dynamic_library_suffixes ||= suffixes - [".rb"] + end + + ## # Prints the amount of time the supplied block takes to run using the debug # UI output. diff --git a/lib/rubygems/basic_specification.rb b/lib/rubygems/basic_specification.rb index cb6931b974..0380fceece 100644 --- a/lib/rubygems/basic_specification.rb +++ b/lib/rubygems/basic_specification.rb @@ -84,7 +84,13 @@ class Gem::BasicSpecification return false end - have_file? file, Gem.suffixes + is_soext = file.end_with?(".so", ".o") + + if is_soext + have_file? file.delete_suffix(File.extname(file)), Gem.dynamic_library_suffixes + else + have_file? file, Gem.suffixes + end end def default_gem? diff --git a/lib/rubygems/package.rb b/lib/rubygems/package.rb index f3c1cb2895..387e40ffd7 100644 --- a/lib/rubygems/package.rb +++ b/lib/rubygems/package.rb @@ -268,7 +268,7 @@ class Gem::Package tar.add_file_simple file, stat.mode, stat.size do |dst_io| File.open file, "rb" do |src_io| - dst_io.write src_io.read 16_384 until src_io.eof? + copy_stream(src_io, dst_io) end end end @@ -453,7 +453,7 @@ EOM end if entry.file? - File.open(destination, "wb") {|out| out.write entry.read } + File.open(destination, "wb") {|out| copy_stream(entry, out) } FileUtils.chmod file_mode(entry.header.mode), destination end @@ -714,6 +714,16 @@ EOM rescue Zlib::GzipFile::Error => e raise Gem::Package::FormatError.new(e.message, entry.full_name) end + + if RUBY_ENGINE == "truffleruby" + def copy_stream(src, dst) # :nodoc: + dst.write src.read + end + else + def copy_stream(src, dst) # :nodoc: + IO.copy_stream(src, dst) + end + end end require_relative "package/digest_io" diff --git a/lib/rubygems/request.rb b/lib/rubygems/request.rb index dec0c35c63..8702e223d6 100644 --- a/lib/rubygems/request.rb +++ b/lib/rubygems/request.rb @@ -30,7 +30,7 @@ class Gem::Request @uri = uri @request_class = request_class @last_modified = last_modified - @requests = Hash.new 0 + @requests = Hash.new(0).compare_by_identity @user_agent = user_agent @connection_pool = pool @@ -196,7 +196,7 @@ class Gem::Request bad_response = false begin - @requests[connection.object_id] += 1 + @requests[connection] += 1 verbose "#{request.method} #{Gem::Uri.redact(@uri)}" @@ -247,7 +247,7 @@ class Gem::Request rescue EOFError, Gem::Timeout::Error, Errno::ECONNABORTED, Errno::ECONNRESET, Errno::EPIPE - requests = @requests[connection.object_id] + requests = @requests[connection] verbose "connection reset after #{requests} requests, retrying" raise Gem::RemoteFetcher::FetchError.new("too many connection resets", @uri) if retried @@ -267,7 +267,7 @@ class Gem::Request # Resets HTTP connection +connection+. def reset(connection) - @requests.delete connection.object_id + @requests.delete connection connection.finish connection.start |