[rubygems/rubygems] Let RDoc parse the doc of Kernel#require
Since RDoc does not parse string literals as documents, `eval` the entire file instead of embedding in a here-document. On the contrary, as `gem_original_require` alias is an implementation detail but not for users, it should not be documented. https://github.com/rubygems/rubygems/commit/cad4cf16cf
This commit is contained in:
parent
fd98169e00
commit
1a1b653c9c
@ -119,10 +119,6 @@ module Gem
|
|||||||
# to avoid deprecation warnings in Ruby 2.7.
|
# to avoid deprecation warnings in Ruby 2.7.
|
||||||
UNTAINT = RUBY_VERSION < "2.7" ? :untaint.to_sym : proc {}
|
UNTAINT = RUBY_VERSION < "2.7" ? :untaint.to_sym : proc {}
|
||||||
|
|
||||||
# When https://bugs.ruby-lang.org/issues/17259 is available, there is no need to override Kernel#warn
|
|
||||||
KERNEL_WARN_IGNORES_INTERNAL_ENTRIES = RUBY_ENGINE == "truffleruby" ||
|
|
||||||
(RUBY_ENGINE == "ruby" && RUBY_VERSION >= "3.0")
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# An Array of Regexps that match windows Ruby platforms.
|
# An Array of Regexps that match windows Ruby platforms.
|
||||||
|
|
||||||
@ -1348,7 +1344,16 @@ end
|
|||||||
Gem::Specification.load_defaults
|
Gem::Specification.load_defaults
|
||||||
|
|
||||||
require_relative "rubygems/core_ext/kernel_gem"
|
require_relative "rubygems/core_ext/kernel_gem"
|
||||||
require_relative "rubygems/core_ext/kernel_require"
|
|
||||||
require_relative "rubygems/core_ext/kernel_warn"
|
path = File.join(__dir__, "rubygems/core_ext/kernel_require.rb")
|
||||||
|
# When https://bugs.ruby-lang.org/issues/17259 is available, there is no need to override Kernel#warn
|
||||||
|
if RUBY_ENGINE == "truffleruby" ||
|
||||||
|
(RUBY_ENGINE == "ruby" && RUBY_VERSION >= "3.0")
|
||||||
|
file = "<internal:#{path}>"
|
||||||
|
else
|
||||||
|
require_relative "rubygems/core_ext/kernel_warn"
|
||||||
|
file = path
|
||||||
|
end
|
||||||
|
eval File.read(path), nil, file
|
||||||
|
|
||||||
require ENV["BUNDLER_SETUP"] if ENV["BUNDLER_SETUP"] && !defined?(Bundler)
|
require ENV["BUNDLER_SETUP"] if ENV["BUNDLER_SETUP"] && !defined?(Bundler)
|
||||||
|
@ -13,12 +13,12 @@ module Kernel
|
|||||||
|
|
||||||
# Make sure we have a reference to Ruby's original Kernel#require
|
# Make sure we have a reference to Ruby's original Kernel#require
|
||||||
unless defined?(gem_original_require)
|
unless defined?(gem_original_require)
|
||||||
|
# :stopdoc:
|
||||||
alias gem_original_require require
|
alias gem_original_require require
|
||||||
private :gem_original_require
|
private :gem_original_require
|
||||||
|
# :startdoc:
|
||||||
end
|
end
|
||||||
|
|
||||||
file = Gem::KERNEL_WARN_IGNORES_INTERNAL_ENTRIES ? "<internal:#{__FILE__}>" : __FILE__
|
|
||||||
module_eval <<'RUBY', file, __LINE__ + 1 # rubocop:disable Style/EvalWithLocation
|
|
||||||
##
|
##
|
||||||
# When RubyGems is required, Kernel#require is replaced with our own which
|
# When RubyGems is required, Kernel#require is replaced with our own which
|
||||||
# is capable of loading gems on demand.
|
# is capable of loading gems on demand.
|
||||||
@ -33,7 +33,7 @@ module Kernel
|
|||||||
# The normal <tt>require</tt> functionality of returning false if
|
# The normal <tt>require</tt> functionality of returning false if
|
||||||
# that file has already been loaded is preserved.
|
# that file has already been loaded is preserved.
|
||||||
|
|
||||||
def require(path)
|
def require(path) # :doc:
|
||||||
if RUBYGEMS_ACTIVATION_MONITOR.respond_to?(:mon_owned?)
|
if RUBYGEMS_ACTIVATION_MONITOR.respond_to?(:mon_owned?)
|
||||||
monitor_owned = RUBYGEMS_ACTIVATION_MONITOR.mon_owned?
|
monitor_owned = RUBYGEMS_ACTIVATION_MONITOR.mon_owned?
|
||||||
end
|
end
|
||||||
@ -168,7 +168,6 @@ module Kernel
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
RUBY
|
|
||||||
|
|
||||||
private :require
|
private :require
|
||||||
|
|
||||||
|
@ -1,53 +1,50 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
if !Gem::KERNEL_WARN_IGNORES_INTERNAL_ENTRIES
|
module Kernel
|
||||||
|
rubygems_path = "#{__dir__}/" # Frames to be skipped start with this path.
|
||||||
|
|
||||||
module Kernel
|
original_warn = instance_method(:warn)
|
||||||
rubygems_path = "#{__dir__}/" # Frames to be skipped start with this path.
|
|
||||||
|
|
||||||
original_warn = instance_method(:warn)
|
remove_method :warn
|
||||||
|
|
||||||
|
class << self
|
||||||
remove_method :warn
|
remove_method :warn
|
||||||
|
end
|
||||||
|
|
||||||
class << self
|
module_function define_method(:warn) {|*messages, **kw|
|
||||||
remove_method :warn
|
unless uplevel = kw[:uplevel]
|
||||||
|
if Gem.java_platform? && RUBY_VERSION < "3.1"
|
||||||
|
return original_warn.bind(self).call(*messages)
|
||||||
|
else
|
||||||
|
return original_warn.bind(self).call(*messages, **kw)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module_function define_method(:warn) {|*messages, **kw|
|
# Ensure `uplevel` fits a `long`
|
||||||
unless uplevel = kw[:uplevel]
|
uplevel, = [uplevel].pack("l!").unpack("l!")
|
||||||
if Gem.java_platform? && RUBY_VERSION < "3.1"
|
|
||||||
return original_warn.bind(self).call(*messages)
|
if uplevel >= 0
|
||||||
else
|
start = 0
|
||||||
return original_warn.bind(self).call(*messages, **kw)
|
while uplevel >= 0
|
||||||
|
loc, = caller_locations(start, 1)
|
||||||
|
unless loc
|
||||||
|
# No more backtrace
|
||||||
|
start += uplevel
|
||||||
|
break
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
# Ensure `uplevel` fits a `long`
|
start += 1
|
||||||
uplevel, = [uplevel].pack("l!").unpack("l!")
|
|
||||||
|
|
||||||
if uplevel >= 0
|
if path = loc.path
|
||||||
start = 0
|
unless path.start_with?(rubygems_path) || path.start_with?("<internal:")
|
||||||
while uplevel >= 0
|
# Non-rubygems frames
|
||||||
loc, = caller_locations(start, 1)
|
uplevel -= 1
|
||||||
unless loc
|
|
||||||
# No more backtrace
|
|
||||||
start += uplevel
|
|
||||||
break
|
|
||||||
end
|
|
||||||
|
|
||||||
start += 1
|
|
||||||
|
|
||||||
if path = loc.path
|
|
||||||
unless path.start_with?(rubygems_path) || path.start_with?("<internal:")
|
|
||||||
# Non-rubygems frames
|
|
||||||
uplevel -= 1
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
kw[:uplevel] = start
|
|
||||||
end
|
end
|
||||||
|
kw[:uplevel] = start
|
||||||
|
end
|
||||||
|
|
||||||
original_warn.bind(self).call(*messages, **kw)
|
original_warn.bind(self).call(*messages, **kw)
|
||||||
}
|
}
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user