Skip to content

Commit

Permalink
Merge RubyGems-3.5.2 and Bundler-2.5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
hsbt committed Dec 21, 2023
1 parent fc549b2 commit 82496f2
Show file tree
Hide file tree
Showing 28 changed files with 394 additions and 267 deletions.
30 changes: 19 additions & 11 deletions lib/bundler/definition.rb
Expand Up @@ -496,7 +496,15 @@ def most_specific_locked_platform
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?
Expand Down Expand Up @@ -653,7 +661,8 @@ def change_reason
[@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

Expand Down Expand Up @@ -708,26 +717,25 @@ def converge_locals
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"
Expand All @@ -737,7 +745,7 @@ def check_lockfile
if invalid.any?
@locked_specs.delete(invalid)

@invalid_lockfile_dep = invalid.first.name
@locked_spec_with_invalid_deps = invalid.first.name
end
end

Expand Down
2 changes: 2 additions & 0 deletions lib/bundler/lazy_specification.rb
Expand Up @@ -10,6 +10,8 @@ class LazySpecification
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
Expand Down
4 changes: 4 additions & 0 deletions lib/bundler/remote_specification.rb
Expand Up @@ -88,6 +88,10 @@ def dependencies
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]}"
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/self_manager.rb
Expand Up @@ -121,7 +121,7 @@ def remote_specs
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

Expand Down
42 changes: 35 additions & 7 deletions lib/bundler/spec_set.rb
Expand Up @@ -37,15 +37,15 @@ def for(dependencies, check = false, platforms = [nil])

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
incomplete = true
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

Expand All @@ -64,7 +64,9 @@ def complete_platforms!(platforms)
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)
Expand All @@ -90,9 +92,20 @@ def complete_platforms!(platforms)
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)
Expand Down Expand Up @@ -167,7 +180,7 @@ def delete_by_name(name)
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
Expand All @@ -193,8 +206,16 @@ def each(&b)
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
Expand All @@ -213,8 +234,9 @@ def extract_circular_gems(error)

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
Expand All @@ -228,6 +250,8 @@ def tsort_each_node

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
Expand All @@ -240,7 +264,11 @@ def specs_for_dependency(dep, platform)
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
Expand Down
3 changes: 0 additions & 3 deletions lib/bundler/vendor/thor/lib/thor/shell/color.rb
@@ -1,14 +1,11 @@
require_relative "basic"
require_relative "lcs_diff"

class Bundler::Thor
module Shell
# Inherit from Bundler::Thor::Shell::Basic and add set_color behavior. Check
# 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.
Expand Down
3 changes: 0 additions & 3 deletions lib/bundler/vendor/thor/lib/thor/shell/html.rb
@@ -1,14 +1,11 @@
require_relative "basic"
require_relative "lcs_diff"

class Bundler::Thor
module Shell
# Inherit from Bundler::Thor::Shell::Basic and add set_color behavior. Check
# 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"

Expand Down
49 changes: 0 additions & 49 deletions lib/bundler/vendor/thor/lib/thor/shell/lcs_diff.rb

This file was deleted.

2 changes: 1 addition & 1 deletion 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
Expand Down
9 changes: 8 additions & 1 deletion lib/rubygems.rb
Expand Up @@ -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
Expand Down Expand Up @@ -942,6 +942,13 @@ def self.suffixes
end].compact.uniq
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.
Expand Down
8 changes: 7 additions & 1 deletion lib/rubygems/basic_specification.rb
Expand Up @@ -84,7 +84,13 @@ def contains_requirable_file?(file)
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?
Expand Down
14 changes: 12 additions & 2 deletions lib/rubygems/package.rb
Expand Up @@ -268,7 +268,7 @@ def add_files(tar) # :nodoc:

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
Expand Down Expand Up @@ -453,7 +453,7 @@ def extract_tar_gz(io, destination_dir, pattern = "*") # :nodoc:
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

Expand Down Expand Up @@ -714,6 +714,16 @@ def verify_gz(entry) # :nodoc:
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"
Expand Down

0 comments on commit 82496f2

Please sign in to comment.