[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.
|
||||
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.
|
||||
|
||||
@ -1348,7 +1344,16 @@ end
|
||||
Gem::Specification.load_defaults
|
||||
|
||||
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)
|
||||
|
@ -13,12 +13,12 @@ module Kernel
|
||||
|
||||
# Make sure we have a reference to Ruby's original Kernel#require
|
||||
unless defined?(gem_original_require)
|
||||
# :stopdoc:
|
||||
alias gem_original_require require
|
||||
private :gem_original_require
|
||||
# :startdoc:
|
||||
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
|
||||
# is capable of loading gems on demand.
|
||||
@ -33,7 +33,7 @@ module Kernel
|
||||
# The normal <tt>require</tt> functionality of returning false if
|
||||
# that file has already been loaded is preserved.
|
||||
|
||||
def require(path)
|
||||
def require(path) # :doc:
|
||||
if RUBYGEMS_ACTIVATION_MONITOR.respond_to?(:mon_owned?)
|
||||
monitor_owned = RUBYGEMS_ACTIVATION_MONITOR.mon_owned?
|
||||
end
|
||||
@ -168,7 +168,6 @@ module Kernel
|
||||
end
|
||||
end
|
||||
end
|
||||
RUBY
|
||||
|
||||
private :require
|
||||
|
||||
|
@ -1,53 +1,50 @@
|
||||
# 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
|
||||
rubygems_path = "#{__dir__}/" # Frames to be skipped start with this path.
|
||||
original_warn = instance_method(:warn)
|
||||
|
||||
original_warn = instance_method(:warn)
|
||||
remove_method :warn
|
||||
|
||||
class << self
|
||||
remove_method :warn
|
||||
end
|
||||
|
||||
class << self
|
||||
remove_method :warn
|
||||
module_function define_method(:warn) {|*messages, **kw|
|
||||
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
|
||||
|
||||
module_function define_method(:warn) {|*messages, **kw|
|
||||
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)
|
||||
# Ensure `uplevel` fits a `long`
|
||||
uplevel, = [uplevel].pack("l!").unpack("l!")
|
||||
|
||||
if uplevel >= 0
|
||||
start = 0
|
||||
while uplevel >= 0
|
||||
loc, = caller_locations(start, 1)
|
||||
unless loc
|
||||
# No more backtrace
|
||||
start += uplevel
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
# Ensure `uplevel` fits a `long`
|
||||
uplevel, = [uplevel].pack("l!").unpack("l!")
|
||||
start += 1
|
||||
|
||||
if uplevel >= 0
|
||||
start = 0
|
||||
while uplevel >= 0
|
||||
loc, = caller_locations(start, 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
|
||||
if path = loc.path
|
||||
unless path.start_with?(rubygems_path) || path.start_with?("<internal:")
|
||||
# Non-rubygems frames
|
||||
uplevel -= 1
|
||||
end
|
||||
end
|
||||
kw[:uplevel] = start
|
||||
end
|
||||
kw[:uplevel] = start
|
||||
end
|
||||
|
||||
original_warn.bind(self).call(*messages, **kw)
|
||||
}
|
||||
end
|
||||
original_warn.bind(self).call(*messages, **kw)
|
||||
}
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user