Merge pull request #15315 from dduugg/rm-kernel-reporting
Remove kernel/reporting activesupport extension
This commit is contained in:
commit
d0d0b7e6ee
1
.gitignore
vendored
1
.gitignore
vendored
@ -80,7 +80,6 @@
|
||||
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/string/inflections.rb
|
||||
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/string/multibyte.rb
|
||||
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/enumerable.rb
|
||||
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/kernel/reporting.rb
|
||||
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/i18n.rb
|
||||
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/inflector/transliterate.rb
|
||||
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/inflector/methods.rb
|
||||
|
||||
@ -18,7 +18,6 @@ require "active_support/core_ext/file/atomic"
|
||||
require "active_support/core_ext/hash/deep_merge"
|
||||
require "active_support/core_ext/hash/except"
|
||||
require "active_support/core_ext/hash/keys"
|
||||
require "active_support/core_ext/kernel/reporting"
|
||||
require "active_support/core_ext/object/blank"
|
||||
require "active_support/core_ext/object/try"
|
||||
require "active_support/core_ext/string/exclude"
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: true
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Utils
|
||||
@ -6,25 +6,35 @@ module Utils
|
||||
#
|
||||
# @private
|
||||
module Autoremove
|
||||
module_function
|
||||
class << self
|
||||
# An array of {Formula} without {Formula} or {Cask}
|
||||
# dependents that weren't installed on request and without
|
||||
# build dependencies for {Formula} installed from source.
|
||||
# @private
|
||||
sig { params(formulae: T::Array[Formula], casks: T::Array[Cask::Cask]).returns(T::Array[Formula]) }
|
||||
def removable_formulae(formulae, casks)
|
||||
unused_formulae = unused_formulae_with_no_formula_dependents(formulae)
|
||||
unused_formulae - formulae_with_cask_dependents(casks)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# An array of all installed {Formula} with {Cask} dependents.
|
||||
# @private
|
||||
sig { params(casks: T::Array[Cask::Cask]).returns(T::Array[Formula]) }
|
||||
def formulae_with_cask_dependents(casks)
|
||||
casks.flat_map { |cask| cask.depends_on[:formula] }
|
||||
.compact
|
||||
.map { |f| Formula[f] }
|
||||
.flat_map { |f| [f, *f.runtime_formula_dependencies].compact }
|
||||
end
|
||||
private_class_method :formulae_with_cask_dependents
|
||||
|
||||
# An array of all installed {Formula} without runtime {Formula}
|
||||
# dependents for bottles and without build {Formula} dependents
|
||||
# for those built from source.
|
||||
# @private
|
||||
sig { params(formulae: T::Array[Formula]).returns(T::Array[Formula]) }
|
||||
def formulae_with_no_formula_dependents(formulae)
|
||||
return [] if formulae.blank?
|
||||
|
||||
dependents = T.let([], T::Array[Formula])
|
||||
formulae.each do |formula|
|
||||
dependents += formula.runtime_formula_dependencies
|
||||
@ -33,36 +43,29 @@ module Utils
|
||||
next if Tab.for_keg(formula.any_installed_keg).poured_from_bottle
|
||||
|
||||
formula.deps.select(&:build?).each do |dep|
|
||||
Kernel.suppress(FormulaUnavailableError) { dependents << dep.to_formula }
|
||||
dependents << dep.to_formula
|
||||
rescue FormulaUnavailableError
|
||||
# do nothing
|
||||
end
|
||||
end
|
||||
formulae - dependents
|
||||
end
|
||||
private_class_method :formulae_with_no_formula_dependents
|
||||
|
||||
# Recursive function that returns an array of {Formula} without
|
||||
# {Formula} dependents that weren't installed on request.
|
||||
# @private
|
||||
sig { params(formulae: T::Array[Formula]).returns(T::Array[Formula]) }
|
||||
def unused_formulae_with_no_formula_dependents(formulae)
|
||||
unused_formulae = formulae_with_no_formula_dependents(formulae).reject do |f|
|
||||
Tab.for_keg(f.any_installed_keg).installed_on_request
|
||||
end
|
||||
|
||||
if unused_formulae.present?
|
||||
unless unused_formulae.empty?
|
||||
unused_formulae += unused_formulae_with_no_formula_dependents(formulae - unused_formulae)
|
||||
end
|
||||
|
||||
unused_formulae
|
||||
end
|
||||
private_class_method :unused_formulae_with_no_formula_dependents
|
||||
|
||||
# An array of {Formula} without {Formula} or {Cask}
|
||||
# dependents that weren't installed on request and without
|
||||
# build dependencies for {Formula} installed from source.
|
||||
# @private
|
||||
def removable_formulae(formulae, casks)
|
||||
unused_formulae = unused_formulae_with_no_formula_dependents(formulae)
|
||||
unused_formulae - formulae_with_cask_dependents(casks)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,45 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Kernel
|
||||
module_function
|
||||
|
||||
# Sets $VERBOSE to +nil+ for the duration of the block and back to its original
|
||||
# value afterwards.
|
||||
#
|
||||
# silence_warnings do
|
||||
# value = noisy_call # no warning voiced
|
||||
# end
|
||||
#
|
||||
# noisy_call # warning voiced
|
||||
def silence_warnings
|
||||
with_warnings(nil) { yield }
|
||||
end
|
||||
|
||||
# Sets $VERBOSE to +true+ for the duration of the block and back to its
|
||||
# original value afterwards.
|
||||
def enable_warnings
|
||||
with_warnings(true) { yield }
|
||||
end
|
||||
|
||||
# Sets $VERBOSE for the duration of the block and back to its original
|
||||
# value afterwards.
|
||||
def with_warnings(flag)
|
||||
old_verbose, $VERBOSE = $VERBOSE, flag
|
||||
yield
|
||||
ensure
|
||||
$VERBOSE = old_verbose
|
||||
end
|
||||
|
||||
# Blocks and ignores any exception passed as argument if raised within the block.
|
||||
#
|
||||
# suppress(ZeroDivisionError) do
|
||||
# 1/0
|
||||
# puts 'This code is NOT reached'
|
||||
# end
|
||||
#
|
||||
# puts 'This code gets executed and nothing related to ZeroDivisionError was seen'
|
||||
def suppress(*exception_classes)
|
||||
yield
|
||||
rescue *exception_classes
|
||||
end
|
||||
end
|
||||
Loading…
x
Reference in New Issue
Block a user