Skip to content

Commit

Permalink
Merge RubyGems-3.5.21 and Bundler-2.5.21
Browse files Browse the repository at this point in the history
  • Loading branch information
hsbt authored and k0kubun committed Oct 17, 2024
1 parent af76568 commit d03e422
Show file tree
Hide file tree
Showing 40 changed files with 276 additions and 173 deletions.
50 changes: 29 additions & 21 deletions lib/bundler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -383,28 +383,12 @@ def clean_env

# @return [Hash] Environment with all bundler-related variables removed
def unbundled_env
env = original_env

if env.key?("BUNDLER_ORIG_MANPATH")
env["MANPATH"] = env["BUNDLER_ORIG_MANPATH"]
end

env.delete_if {|k, _| k[0, 7] == "BUNDLE_" }

if env.key?("RUBYOPT")
rubyopt = env["RUBYOPT"].split(" ")
rubyopt.delete("-r#{File.expand_path("bundler/setup", __dir__)}")
rubyopt.delete("-rbundler/setup")
env["RUBYOPT"] = rubyopt.join(" ")
end

if env.key?("RUBYLIB")
rubylib = env["RUBYLIB"].split(File::PATH_SEPARATOR)
rubylib.delete(__dir__)
env["RUBYLIB"] = rubylib.join(File::PATH_SEPARATOR)
end
unbundle_env(original_env)
end

env
# Remove all bundler-related variables from ENV
def unbundle_env!
ENV.replace(unbundle_env(ENV))
end

# Run block with environment present before Bundler was activated
Expand Down Expand Up @@ -633,6 +617,30 @@ def self_manager

private

def unbundle_env(env)
if env.key?("BUNDLER_ORIG_MANPATH")
env["MANPATH"] = env["BUNDLER_ORIG_MANPATH"]
end

env.delete_if {|k, _| k[0, 7] == "BUNDLE_" }
env.delete("BUNDLER_SETUP")

if env.key?("RUBYOPT")
rubyopt = env["RUBYOPT"].split(" ")
rubyopt.delete("-r#{File.expand_path("bundler/setup", __dir__)}")
rubyopt.delete("-rbundler/setup")
env["RUBYOPT"] = rubyopt.join(" ")
end

if env.key?("RUBYLIB")
rubylib = env["RUBYLIB"].split(File::PATH_SEPARATOR)
rubylib.delete(__dir__)
env["RUBYLIB"] = rubylib.join(File::PATH_SEPARATOR)
end

env
end

def load_marshal(data, marshal_proc: nil)
Marshal.load(data, marshal_proc)
rescue TypeError => e
Expand Down
16 changes: 11 additions & 5 deletions lib/bundler/inline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ def gemfile(install = false, options = {}, &gemfile)
Bundler.ui = ui
raise ArgumentError, "Unknown options: #{opts.keys.join(", ")}" unless opts.empty?

Bundler.with_unbundled_env do
old_gemfile = ENV["BUNDLE_GEMFILE"]

Bundler.unbundle_env!

begin
Bundler.instance_variable_set(:@bundle_path, Pathname.new(Gem.dir))
Bundler::SharedHelpers.set_env "BUNDLE_GEMFILE", "Gemfile"

Expand Down Expand Up @@ -80,9 +84,11 @@ def gemfile(install = false, options = {}, &gemfile)

runtime.require
end
end

if ENV["BUNDLE_GEMFILE"].nil?
ENV["BUNDLE_GEMFILE"] = ""
ensure
if old_gemfile
ENV["BUNDLE_GEMFILE"] = old_gemfile
else
ENV["BUNDLE_GEMFILE"] = ""
end
end
end
2 changes: 1 addition & 1 deletion lib/bundler/source/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def specs(*)
set_up_app_cache!(app_cache_path) if use_app_cache?

if requires_checkout? && !@copied
FileUtils.rm_rf(app_cache_path) if use_app_cache? && git_proxy.not_a_bare_repository?
FileUtils.rm_rf(app_cache_path) if use_app_cache? && git_proxy.not_a_repository?

fetch
checkout
Expand Down
6 changes: 4 additions & 2 deletions lib/bundler/source/git/git_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ def current_branch
end
end

def not_a_bare_repository?
git_local("rev-parse", "--is-bare-repository", dir: path).strip == "false"
def not_a_repository?
_, status = git_null("rev-parse", "--resolve-git-dir", path.to_s, dir: path)

!status.success?
end

def contains?(commit)
Expand Down
2 changes: 2 additions & 0 deletions lib/bundler/source/path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ def to_s
"source at `#{@path}`"
end

alias_method :to_gemfile, :path

def hash
[self.class, expanded_path, version].hash
end
Expand Down
4 changes: 2 additions & 2 deletions lib/bundler/stub_specification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def missing_extensions?
true
end

def activated
stub.activated
def activated?
stub.activated?
end

def activated=(activated)
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/version.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: false

module Bundler
VERSION = "2.5.20".freeze
VERSION = "2.5.21".freeze

def self.bundler_major_version
@bundler_major_version ||= VERSION.split(".").first.to_i
Expand Down
2 changes: 1 addition & 1 deletion lib/rubygems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
require "rbconfig"

module Gem
VERSION = "3.5.20"
VERSION = "3.5.21"
end

# Must be first since it unloads the prelude from 1.9.2
Expand Down
11 changes: 2 additions & 9 deletions lib/rubygems/command_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,18 +230,11 @@ def find_command_possibilities(cmd_name)
def load_and_instantiate(command_name)
command_name = command_name.to_s
const_name = command_name.capitalize.gsub(/_(.)/) { $1.upcase } << "Command"
load_error = nil

begin
begin
require "rubygems/commands/#{command_name}_command"
rescue LoadError => e
load_error = e
end
require "rubygems/commands/#{command_name}_command"
Gem::Commands.const_get(const_name).new
rescue StandardError => e
e = load_error if load_error

rescue StandardError, LoadError => e
alert_error clean_text("Loading command: #{command_name} (#{e.class})\n\t#{e}")
ui.backtrace e
end
Expand Down
12 changes: 1 addition & 11 deletions lib/rubygems/commands/cleanup_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ def initialize
@default_gems = []
@full = nil
@gems_to_cleanup = nil
@original_home = nil
@original_path = nil
@primary_gems = nil
end

Expand Down Expand Up @@ -95,9 +93,6 @@ def execute
end

def clean_gems
@original_home = Gem.dir
@original_path = Gem.path

get_primary_gems
get_candidate_gems
get_gems_to_cleanup
Expand All @@ -112,8 +107,6 @@ def clean_gems
deps.reverse_each do |spec|
uninstall_dep spec
end

Gem::Specification.reset
end

def get_candidate_gems
Expand All @@ -133,7 +126,7 @@ def get_gems_to_cleanup

default_gems, gems_to_cleanup = gems_to_cleanup.partition(&:default_gem?)

uninstall_from = options[:user_install] ? Gem.user_dir : @original_home
uninstall_from = options[:user_install] ? Gem.user_dir : Gem.dir

gems_to_cleanup = gems_to_cleanup.select do |spec|
spec.base_dir == uninstall_from
Expand Down Expand Up @@ -181,8 +174,5 @@ def uninstall_dep(spec)
say "Unable to uninstall #{spec.full_name}:"
say "\t#{e.class}: #{e.message}"
end
ensure
# Restore path Gem::Uninstaller may have changed
Gem.use_paths @original_home, *@original_path
end
end
3 changes: 2 additions & 1 deletion lib/rubygems/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def initialize(name, requirement, extra_message=nil)
@name = name
@requirement = requirement
@extra_message = extra_message
super(message)
end

def message # :nodoc:
Expand All @@ -53,8 +54,8 @@ class MissingSpecVersionError < MissingSpecError
attr_reader :specs

def initialize(name, requirement, specs)
super(name, requirement)
@specs = specs
super(name, requirement)
end

private
Expand Down
37 changes: 14 additions & 23 deletions lib/rubygems/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ class Gem::Installer

attr_reader :package

@path_warning = false

class << self
#
# Changes in rubygems to lazily loading `rubygems/command` (in order to
Expand All @@ -86,11 +84,6 @@ def inherited(klass)
super(klass)
end

##
# True if we've warned about PATH not including Gem.bindir

attr_accessor :path_warning

##
# Overrides the executable format.
#
Expand Down Expand Up @@ -188,15 +181,6 @@ def initialize(package, options={})
@package.dir_mode = options[:dir_mode]
@package.prog_mode = options[:prog_mode]
@package.data_mode = options[:data_mode]

if @gem_home == Gem.user_dir
# If we get here, then one of the following likely happened:
# - `--user-install` was specified
# - `Gem::PathSupport#home` fell back to `Gem.user_dir`
# - GEM_HOME was manually set to `Gem.user_dir`

check_that_user_bin_dir_is_in_path
end
end

##
Expand Down Expand Up @@ -488,11 +472,21 @@ def generate_windows_script(filename, bindir)
end

def generate_bin # :nodoc:
return if spec.executables.nil? || spec.executables.empty?
executables = spec.executables
return if executables.nil? || executables.empty?

if @gem_home == Gem.user_dir
# If we get here, then one of the following likely happened:
# - `--user-install` was specified
# - `Gem::PathSupport#home` fell back to `Gem.user_dir`
# - GEM_HOME was manually set to `Gem.user_dir`

check_that_user_bin_dir_is_in_path(executables)
end

ensure_writable_dir @bin_dir

spec.executables.each do |filename|
executables.each do |filename|
bin_path = File.join gem_dir, spec.bindir, filename
next unless File.exist? bin_path

Expand Down Expand Up @@ -694,9 +688,7 @@ def process_options # :nodoc:
end
end

def check_that_user_bin_dir_is_in_path # :nodoc:
return if self.class.path_warning

def check_that_user_bin_dir_is_in_path(executables) # :nodoc:
user_bin_dir = @bin_dir || Gem.bindir(gem_home)
user_bin_dir = user_bin_dir.tr(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR

Expand All @@ -712,8 +704,7 @@ def check_that_user_bin_dir_is_in_path # :nodoc:

unless path.include? user_bin_dir
unless !Gem.win_platform? && (path.include? user_bin_dir.sub(ENV["HOME"], "~"))
alert_warning "You don't have #{user_bin_dir} in your PATH,\n\t gem executables will not run."
self.class.path_warning = true
alert_warning "You don't have #{user_bin_dir} in your PATH,\n\t gem executables (#{executables.join(", ")}) will not run."
end
end
end
Expand Down
19 changes: 12 additions & 7 deletions lib/rubygems/resolver/api_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,21 @@ def versions(name) # :nodoc:
end

uri = @dep_uri + name
str = Gem::RemoteFetcher.fetcher.fetch_path uri

lines(str).each do |ver|
number, platform, dependencies, requirements = parse_gem(ver)
begin
str = Gem::RemoteFetcher.fetcher.fetch_path uri
rescue Gem::RemoteFetcher::FetchError
@data[name] = []
else
lines(str).each do |ver|
number, platform, dependencies, requirements = parse_gem(ver)

platform ||= "ruby"
dependencies = dependencies.map {|dep_name, reqs| [dep_name, reqs.join(", ")] }
requirements = requirements.map {|req_name, reqs| [req_name.to_sym, reqs] }.to_h
platform ||= "ruby"
dependencies = dependencies.map {|dep_name, reqs| [dep_name, reqs.join(", ")] }
requirements = requirements.map {|req_name, reqs| [req_name.to_sym, reqs] }.to_h

@data[name] << { name: name, number: number, platform: platform, dependencies: dependencies, requirements: requirements }
@data[name] << { name: name, number: number, platform: platform, dependencies: dependencies, requirements: requirements }
end
end

@data[name]
Expand Down
2 changes: 0 additions & 2 deletions lib/rubygems/resolver/best_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ def find_all(req) # :nodoc:
pick_sets if @remote && @sets.empty?

super
rescue Gem::RemoteFetcher::FetchError
[]
end

def prefetch(reqs) # :nodoc:
Expand Down
15 changes: 4 additions & 11 deletions lib/rubygems/spec_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,19 +176,12 @@ def suggest_gems_from_name(gem_name, type = :latest, num_results = 5)

matches = names.map do |n|
next unless n.match_platform?
[n.name, 0] if n.name.downcase.tr("_-", "").include?(gem_name)
distance = levenshtein_distance gem_name, n.name.downcase.tr("_-", "")
next if distance >= max
return [n.name] if distance == 0
[n.name, distance]
end.compact

if matches.length < num_results
matches += names.map do |n|
next unless n.match_platform?
distance = levenshtein_distance gem_name, n.name.downcase.tr("_-", "")
next if distance >= max
return [n.name] if distance == 0
[n.name, distance]
end.compact
end

matches = if matches.empty? && type != :prerelease
suggest_gems_from_name gem_name, :prerelease
else
Expand Down
Loading

0 comments on commit d03e422

Please sign in to comment.