Skip to content

Commit

Permalink
Merge RubyGems 3.4.6 and Bundler 2.4.6 (#7214)
Browse files Browse the repository at this point in the history
Merge RubyGems-3.4.6 and Bundler-2.4.6
  • Loading branch information
hsbt committed Feb 1, 2023
1 parent 40e0b1e commit f4e6e78
Show file tree
Hide file tree
Showing 30 changed files with 948 additions and 717 deletions.
6 changes: 5 additions & 1 deletion lib/bundler/cli/binstubs.rb
Expand Up @@ -40,7 +40,11 @@ def run
end

if options[:standalone]
next Bundler.ui.warn("Sorry, Bundler can only be run via RubyGems.") if gem_name == "bundler"
if gem_name == "bundler"
Bundler.ui.warn("Sorry, Bundler can only be run via RubyGems.") unless options[:all]
next
end

Bundler.settings.temporary(:path => (Bundler.settings[:path] || Bundler.root)) do
installer.generate_standalone_bundler_executable_stubs(spec, installer_opts)
end
Expand Down
14 changes: 6 additions & 8 deletions lib/bundler/inline.rb
Expand Up @@ -31,16 +31,16 @@
#
def gemfile(install = false, options = {}, &gemfile)
require_relative "../bundler"
Bundler.reset!

opts = options.dup
ui = opts.delete(:ui) { Bundler::UI::Shell.new }
ui.level = "silent" if opts.delete(:quiet) || !install
Bundler.ui = ui
raise ArgumentError, "Unknown options: #{opts.keys.join(", ")}" unless opts.empty?

begin
Bundler.with_unbundled_env do
Bundler.instance_variable_set(:@bundle_path, Pathname.new(Gem.dir))
old_gemfile = ENV["BUNDLE_GEMFILE"]
Bundler::SharedHelpers.set_env "BUNDLE_GEMFILE", "Gemfile"

Bundler::Plugin.gemfile_install(&gemfile) if Bundler.feature_flag.plugins?
Expand All @@ -65,11 +65,9 @@ def definition.lock(*); end
runtime = Bundler::Runtime.new(nil, definition)
runtime.setup.require
end
ensure
if old_gemfile
ENV["BUNDLE_GEMFILE"] = old_gemfile
else
ENV["BUNDLE_GEMFILE"] = ""
end
end

if ENV["BUNDLE_GEMFILE"].nil?
ENV["BUNDLE_GEMFILE"] = ""
end
end
18 changes: 11 additions & 7 deletions lib/bundler/installer/standalone.rb
Expand Up @@ -84,13 +84,17 @@ def self.extension_api_version

def reverse_rubygems_kernel_mixin
<<~END
kernel = (class << ::Kernel; self; end)
[kernel, ::Kernel].each do |k|
if k.private_method_defined?(:gem_original_require)
private_require = k.private_method_defined?(:require)
k.send(:remove_method, :require)
k.send(:define_method, :require, k.instance_method(:gem_original_require))
k.send(:private, :require) if private_require
if Gem.respond_to?(:discover_gems_on_require=)
Gem.discover_gems_on_require = false
else
kernel = (class << ::Kernel; self; end)
[kernel, ::Kernel].each do |k|
if k.private_method_defined?(:gem_original_require)
private_require = k.private_method_defined?(:require)
k.send(:remove_method, :require)
k.send(:define_method, :require, k.instance_method(:gem_original_require))
k.send(:private, :require) if private_require
end
end
end
END
Expand Down
12 changes: 8 additions & 4 deletions lib/bundler/rubygems_integration.rb
Expand Up @@ -227,10 +227,14 @@ def security_policies

def reverse_rubygems_kernel_mixin
# Disable rubygems' gem activation system
kernel = (class << ::Kernel; self; end)
[kernel, ::Kernel].each do |k|
if k.private_method_defined?(:gem_original_require)
redefine_method(k, :require, k.instance_method(:gem_original_require))
if Gem.respond_to?(:discover_gems_on_require=)
Gem.discover_gems_on_require = false
else
kernel = (class << ::Kernel; self; end)
[kernel, ::Kernel].each do |k|
if k.private_method_defined?(:gem_original_require)
redefine_method(k, :require, k.instance_method(:gem_original_require))
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/version.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: false

module Bundler
VERSION = "2.4.5".freeze
VERSION = "2.4.6".freeze

def self.bundler_major_version
@bundler_major_version ||= VERSION.split(".").first.to_i
Expand Down
12 changes: 11 additions & 1 deletion lib/rubygems.rb
Expand Up @@ -8,7 +8,7 @@
require "rbconfig"

module Gem
VERSION = "3.4.5".freeze
VERSION = "3.4.6".freeze
end

# Must be first since it unloads the prelude from 1.9.2
Expand Down Expand Up @@ -181,6 +181,8 @@ module Gem

@default_source_date_epoch = nil

@discover_gems_on_require = true

##
# Try to activate a gem containing +path+. Returns true if
# activation succeeded or wasn't needed because it was already
Expand Down Expand Up @@ -1163,8 +1165,16 @@ class << self
# RubyGems distributors (like operating system package managers) can
# disable RubyGems update by setting this to error message printed to
# end-users on gem update --system instead of actual update.

attr_accessor :disable_system_update_message

##
# Whether RubyGems should enhance builtin `require` to automatically
# check whether the path required is present in installed gems, and
# automatically activate them and add them to `$LOAD_PATH`.

attr_accessor :discover_gems_on_require

##
# Hash of loaded Gem::Specification keyed by name

Expand Down
222 changes: 113 additions & 109 deletions lib/rubygems/core_ext/kernel_require.rb
Expand Up @@ -34,137 +34,141 @@ module Kernel
# that file has already been loaded is preserved.

def require(path) # :doc:
if RUBYGEMS_ACTIVATION_MONITOR.respond_to?(:mon_owned?)
monitor_owned = RUBYGEMS_ACTIVATION_MONITOR.mon_owned?
end
RUBYGEMS_ACTIVATION_MONITOR.enter

path = path.to_path if path.respond_to? :to_path

if spec = Gem.find_unresolved_default_spec(path)
# Ensure -I beats a default gem
resolved_path = begin
rp = nil
load_path_check_index = Gem.load_path_insert_index - Gem.activated_gem_paths
Gem.suffixes.each do |s|
$LOAD_PATH[0...load_path_check_index].each do |lp|
safe_lp = lp.dup.tap(&Gem::UNTAINT)
begin
if File.symlink? safe_lp # for backward compatibility
next
return gem_original_require(path) unless Gem.discover_gems_on_require

begin
if RUBYGEMS_ACTIVATION_MONITOR.respond_to?(:mon_owned?)
monitor_owned = RUBYGEMS_ACTIVATION_MONITOR.mon_owned?
end
RUBYGEMS_ACTIVATION_MONITOR.enter

path = path.to_path if path.respond_to? :to_path

if spec = Gem.find_unresolved_default_spec(path)
# Ensure -I beats a default gem
resolved_path = begin
rp = nil
load_path_check_index = Gem.load_path_insert_index - Gem.activated_gem_paths
Gem.suffixes.each do |s|
$LOAD_PATH[0...load_path_check_index].each do |lp|
safe_lp = lp.dup.tap(&Gem::UNTAINT)
begin
if File.symlink? safe_lp # for backward compatibility
next
end
rescue SecurityError
RUBYGEMS_ACTIVATION_MONITOR.exit
raise
end
rescue SecurityError
RUBYGEMS_ACTIVATION_MONITOR.exit
raise
end

full_path = File.expand_path(File.join(safe_lp, "#{path}#{s}"))
if File.file?(full_path)
rp = full_path
break
full_path = File.expand_path(File.join(safe_lp, "#{path}#{s}"))
if File.file?(full_path)
rp = full_path
break
end
end
break if rp
end
break if rp
rp
end
rp

begin
Kernel.send(:gem, spec.name, Gem::Requirement.default_prerelease)
rescue Exception
RUBYGEMS_ACTIVATION_MONITOR.exit
raise
end unless resolved_path
end

begin
Kernel.send(:gem, spec.name, Gem::Requirement.default_prerelease)
rescue Exception
RUBYGEMS_ACTIVATION_MONITOR.exit
raise
end unless resolved_path
end
# If there are no unresolved deps, then we can use just try
# normal require handle loading a gem from the rescue below.

# If there are no unresolved deps, then we can use just try
# normal require handle loading a gem from the rescue below.
if Gem::Specification.unresolved_deps.empty?
RUBYGEMS_ACTIVATION_MONITOR.exit
return gem_original_require(path)
end

if Gem::Specification.unresolved_deps.empty?
RUBYGEMS_ACTIVATION_MONITOR.exit
return gem_original_require(path)
end
# If +path+ is for a gem that has already been loaded, don't
# bother trying to find it in an unresolved gem, just go straight
# to normal require.
#--
# TODO request access to the C implementation of this to speed up RubyGems

# If +path+ is for a gem that has already been loaded, don't
# bother trying to find it in an unresolved gem, just go straight
# to normal require.
#--
# TODO request access to the C implementation of this to speed up RubyGems
if Gem::Specification.find_active_stub_by_path(path)
RUBYGEMS_ACTIVATION_MONITOR.exit
return gem_original_require(path)
end

if Gem::Specification.find_active_stub_by_path(path)
RUBYGEMS_ACTIVATION_MONITOR.exit
return gem_original_require(path)
end
# Attempt to find +path+ in any unresolved gems...

found_specs = Gem::Specification.find_in_unresolved path

# If there are no directly unresolved gems, then try and find +path+
# in any gems that are available via the currently unresolved gems.
# For example, given:
#
# a => b => c => d
#
# If a and b are currently active with c being unresolved and d.rb is
# requested, then find_in_unresolved_tree will find d.rb in d because
# it's a dependency of c.
#
if found_specs.empty?
found_specs = Gem::Specification.find_in_unresolved_tree path

found_specs.each do |found_spec|
found_spec.activate
end

# Attempt to find +path+ in any unresolved gems...

found_specs = Gem::Specification.find_in_unresolved path

# If there are no directly unresolved gems, then try and find +path+
# in any gems that are available via the currently unresolved gems.
# For example, given:
#
# a => b => c => d
#
# If a and b are currently active with c being unresolved and d.rb is
# requested, then find_in_unresolved_tree will find d.rb in d because
# it's a dependency of c.
#
if found_specs.empty?
found_specs = Gem::Specification.find_in_unresolved_tree path

found_specs.each do |found_spec|
found_spec.activate
end
# We found +path+ directly in an unresolved gem. Now we figure out, of
# the possible found specs, which one we should activate.
else

# We found +path+ directly in an unresolved gem. Now we figure out, of
# the possible found specs, which one we should activate.
else
# Check that all the found specs are just different
# versions of the same gem
names = found_specs.map(&:name).uniq

# Check that all the found specs are just different
# versions of the same gem
names = found_specs.map(&:name).uniq
if names.size > 1
RUBYGEMS_ACTIVATION_MONITOR.exit
raise Gem::LoadError, "#{path} found in multiple gems: #{names.join ', '}"
end

if names.size > 1
RUBYGEMS_ACTIVATION_MONITOR.exit
raise Gem::LoadError, "#{path} found in multiple gems: #{names.join ', '}"
end
# Ok, now find a gem that has no conflicts, starting
# at the highest version.
valid = found_specs.find {|s| !s.has_conflicts? }

# Ok, now find a gem that has no conflicts, starting
# at the highest version.
valid = found_specs.find {|s| !s.has_conflicts? }
unless valid
le = Gem::LoadError.new "unable to find a version of '#{names.first}' to activate"
le.name = names.first
RUBYGEMS_ACTIVATION_MONITOR.exit
raise le
end

unless valid
le = Gem::LoadError.new "unable to find a version of '#{names.first}' to activate"
le.name = names.first
RUBYGEMS_ACTIVATION_MONITOR.exit
raise le
valid.activate
end

valid.activate
end

RUBYGEMS_ACTIVATION_MONITOR.exit
return gem_original_require(path)
rescue LoadError => load_error
if load_error.path == path
RUBYGEMS_ACTIVATION_MONITOR.enter
RUBYGEMS_ACTIVATION_MONITOR.exit
return gem_original_require(path)
rescue LoadError => load_error
if load_error.path == path
RUBYGEMS_ACTIVATION_MONITOR.enter

begin
require_again = Gem.try_activate(path)
ensure
RUBYGEMS_ACTIVATION_MONITOR.exit
end

begin
require_again = Gem.try_activate(path)
ensure
RUBYGEMS_ACTIVATION_MONITOR.exit
return gem_original_require(path) if require_again
end

return gem_original_require(path) if require_again
end

raise load_error
ensure
if RUBYGEMS_ACTIVATION_MONITOR.respond_to?(:mon_owned?)
if monitor_owned != (ow = RUBYGEMS_ACTIVATION_MONITOR.mon_owned?)
STDERR.puts [$$, Thread.current, $!, $!.backtrace].inspect if $!
raise "CRITICAL: RUBYGEMS_ACTIVATION_MONITOR.owned?: before #{monitor_owned} -> after #{ow}"
raise load_error
ensure
if RUBYGEMS_ACTIVATION_MONITOR.respond_to?(:mon_owned?)
if monitor_owned != (ow = RUBYGEMS_ACTIVATION_MONITOR.mon_owned?)
STDERR.puts [$$, Thread.current, $!, $!.backtrace].inspect if $!
raise "CRITICAL: RUBYGEMS_ACTIVATION_MONITOR.owned?: before #{monitor_owned} -> after #{ow}"
end
end
end
end
Expand Down
3 changes: 1 addition & 2 deletions lib/rubygems/ext/builder.rb
Expand Up @@ -131,8 +131,7 @@ def builder_for(extension) # :nodoc:
when /CMakeLists.txt/ then
Gem::Ext::CmakeBuilder
when /Cargo.toml/ then
# We use the spec name here to ensure we invoke the correct init function later
Gem::Ext::CargoBuilder.new(@spec)
Gem::Ext::CargoBuilder.new
else
build_error("No builder for extension '#{extension}'")
end
Expand Down

0 comments on commit f4e6e78

Please sign in to comment.