Merge pull request #6367 from reitermarkus/kernel
Move global methods into `Kernel` module.
This commit is contained in:
commit
0054dd32e1
@ -16,6 +16,65 @@ require "utils/tty"
|
||||
require "tap_constants"
|
||||
require "time"
|
||||
|
||||
module Homebrew
|
||||
module_function
|
||||
|
||||
def _system(cmd, *args, **options)
|
||||
pid = fork do
|
||||
yield if block_given?
|
||||
args.map!(&:to_s)
|
||||
begin
|
||||
exec(cmd, *args, **options)
|
||||
rescue
|
||||
nil
|
||||
end
|
||||
exit! 1 # never gets here unless exec failed
|
||||
end
|
||||
Process.wait(pid)
|
||||
$CHILD_STATUS.success?
|
||||
end
|
||||
|
||||
def system(cmd, *args, **options)
|
||||
puts "#{cmd} #{args * " "}" if ARGV.verbose?
|
||||
_system(cmd, *args, **options)
|
||||
end
|
||||
|
||||
# rubocop:disable Style/GlobalVars
|
||||
def inject_dump_stats!(the_module, pattern)
|
||||
@injected_dump_stat_modules ||= {}
|
||||
@injected_dump_stat_modules[the_module] ||= []
|
||||
injected_methods = @injected_dump_stat_modules[the_module]
|
||||
the_module.module_eval do
|
||||
instance_methods.grep(pattern).each do |name|
|
||||
next if injected_methods.include? name
|
||||
|
||||
method = instance_method(name)
|
||||
define_method(name) do |*args, &block|
|
||||
begin
|
||||
time = Time.now
|
||||
method.bind(self).call(*args, &block)
|
||||
ensure
|
||||
$times[name] ||= 0
|
||||
$times[name] += Time.now - time
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return unless $times.nil?
|
||||
|
||||
$times = {}
|
||||
at_exit do
|
||||
col_width = [$times.keys.map(&:size).max.to_i + 2, 15].max
|
||||
$times.sort_by { |_k, v| v }.each do |method, time|
|
||||
puts format("%-*s %0.4f sec", col_width, "#{method}:", time)
|
||||
end
|
||||
end
|
||||
end
|
||||
# rubocop:enable Style/GlobalVars
|
||||
end
|
||||
|
||||
module Kernel
|
||||
def require?(path)
|
||||
return false if path.nil?
|
||||
|
||||
@ -187,64 +246,6 @@ def interactive_shell(f = nil)
|
||||
raise $CHILD_STATUS.inspect
|
||||
end
|
||||
|
||||
module Homebrew
|
||||
module_function
|
||||
|
||||
def _system(cmd, *args, **options)
|
||||
pid = fork do
|
||||
yield if block_given?
|
||||
args.map!(&:to_s)
|
||||
begin
|
||||
exec(cmd, *args, **options)
|
||||
rescue
|
||||
nil
|
||||
end
|
||||
exit! 1 # never gets here unless exec failed
|
||||
end
|
||||
Process.wait(pid)
|
||||
$CHILD_STATUS.success?
|
||||
end
|
||||
|
||||
def system(cmd, *args, **options)
|
||||
puts "#{cmd} #{args * " "}" if ARGV.verbose?
|
||||
_system(cmd, *args, **options)
|
||||
end
|
||||
|
||||
# rubocop:disable Style/GlobalVars
|
||||
def inject_dump_stats!(the_module, pattern)
|
||||
@injected_dump_stat_modules ||= {}
|
||||
@injected_dump_stat_modules[the_module] ||= []
|
||||
injected_methods = @injected_dump_stat_modules[the_module]
|
||||
the_module.module_eval do
|
||||
instance_methods.grep(pattern).each do |name|
|
||||
next if injected_methods.include? name
|
||||
|
||||
method = instance_method(name)
|
||||
define_method(name) do |*args, &block|
|
||||
begin
|
||||
time = Time.now
|
||||
method.bind(self).call(*args, &block)
|
||||
ensure
|
||||
$times[name] ||= 0
|
||||
$times[name] += Time.now - time
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return unless $times.nil?
|
||||
|
||||
$times = {}
|
||||
at_exit do
|
||||
col_width = [$times.keys.map(&:size).max.to_i + 2, 15].max
|
||||
$times.sort_by { |_k, v| v }.each do |method, time|
|
||||
puts format("%-*s %0.4f sec", col_width, "#{method}:", time)
|
||||
end
|
||||
end
|
||||
end
|
||||
# rubocop:enable Style/GlobalVars
|
||||
end
|
||||
|
||||
def with_homebrew_path
|
||||
with_env(PATH: PATH.new(ENV["HOMEBREW_PATH"])) do
|
||||
yield
|
||||
@ -506,3 +507,4 @@ def redact_secrets(input, secrets)
|
||||
.reduce(input) { |str, secret| str.gsub secret, "******" }
|
||||
.freeze
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user